Add deploy setup command

This commit is contained in:
David Boreham 2023-07-18 18:19:08 -06:00
parent 43d9861508
commit dcfd7e3d45
4 changed files with 53 additions and 13 deletions

View File

@ -13,6 +13,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
from dataclasses import dataclass
from app.util import get_yaml
from app.stack_state import State
@ -24,6 +25,27 @@ default_spec_file_content = """config:
init_help_text = """Add helpful text here on setting config variables.
"""
@dataclass
class VolumeMapping:
host_path: str
container_path: str
# In order to make this, we need the ability to run the stack
# In theory we can make this same way as we would run deploy up
def run_container_command(ctx, ontainer, command, mounts):
deploy_context = ctx.obj
pass
def setup(ctx):
node_moniker = "dbdb-node"
chain_id = "laconic_81337-1"
mounts = [
VolumeMapping("./path", "~/.laconicd")
]
output, status = run_container_command(ctx, "laconicd", f"laconicd init {node_moniker} --chain-id {chain_id}", mounts)
def init(command_context):
print(init_help_text)
@ -33,4 +55,8 @@ def init(command_context):
def get_state(command_context):
print("Here we get state")
return State.CONFIGURED
return State.CONFIGURED
def change_state(command_context):
pass

View File

@ -29,6 +29,7 @@ from pathlib import Path
from app.util import include_exclude_check, get_parsed_stack_config, global_options2
from app.deployment_create import create as deployment_create
from app.deployment_create import init as deployment_init
from app.deployment_create import setup as deployment_setup
class DeployCommandContext(object):
@ -420,3 +421,4 @@ def _orchestrate_cluster_config(ctx, cluster_config, docker, container_exec_env)
command.add_command(deployment_init)
command.add_command(deployment_create)
command.add_command(deployment_setup)

View File

@ -126,15 +126,3 @@ def logs(ctx, extra_args):
@click.pass_context
def status(ctx):
print(f"Context: {ctx.parent.obj}")
#from importlib import resources, util
# TODO: figure out how to do this dynamically
#stack = "mainnet-laconic"
#module_name = "commands"
#spec = util.spec_from_file_location(module_name, "./app/data/stacks/" + stack + "/deploy/commands.py")
#imported_stack = util.module_from_spec(spec)
#spec.loader.exec_module(imported_stack)
#command.add_command(imported_stack.init)
#command.add_command(imported_stack.create)

View File

@ -99,6 +99,18 @@ def call_stack_deploy_init(stack):
return imported_stack.init(None)
# TODO: fold this with function above
def call_stack_deploy_setup(stack):
# Link with the python file in the stack
# Call a function in it
# If no function found, return None
python_file_path = get_stack_file_path(stack).parent.joinpath("deploy", "commands.py")
spec = util.spec_from_file_location("commands", python_file_path)
imported_stack = util.module_from_spec(spec)
spec.loader.exec_module(imported_stack)
return imported_stack.setup(None)
@click.command()
@click.option("--output", required=True, help="Write yaml spec file here")
@click.pass_context
@ -158,3 +170,15 @@ def create(ctx, spec_file, deployment_dir):
source_config_dir = data_dir.joinpath("config", pod)
if os.path.exists(source_config_dir):
copytree(source_config_dir, os.path.join(deployment_dir, "config", pod))
@click.command()
@click.option("--node-moniker", help="Help goes here")
@click.option("--key-name", help="Help goes here")
@click.option("--initialize-network", is_flag=True, default=False, help="Help goes here")
@click.option("--join-network", is_flag=True, default=False, help="Help goes here")
@click.option("--create-network", is_flag=True, default=False, help="Help goes here")
@click.pass_context
def setup(ctx, node_moniker, key_name, initialize_network, join_network, create_network):
stack = global_options(ctx).stack
call_stack_deploy_setup(stack)