From dcfd7e3d45cbad8ed59a2f1612d5a6c3e2603b51 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Tue, 18 Jul 2023 18:19:08 -0600 Subject: [PATCH] Add deploy setup command --- .../stacks/mainnet-laconic/deploy/commands.py | 28 ++++++++++++++++++- app/deploy.py | 2 ++ app/deployment.py | 12 -------- app/deployment_create.py | 24 ++++++++++++++++ 4 files changed, 53 insertions(+), 13 deletions(-) diff --git a/app/data/stacks/mainnet-laconic/deploy/commands.py b/app/data/stacks/mainnet-laconic/deploy/commands.py index d0512655..a8a62bd7 100644 --- a/app/data/stacks/mainnet-laconic/deploy/commands.py +++ b/app/data/stacks/mainnet-laconic/deploy/commands.py @@ -13,6 +13,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +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 \ No newline at end of file + return State.CONFIGURED + + +def change_state(command_context): + pass diff --git a/app/deploy.py b/app/deploy.py index 2e665696..41af70f6 100644 --- a/app/deploy.py +++ b/app/deploy.py @@ -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) diff --git a/app/deployment.py b/app/deployment.py index 84b83bd5..1a13dbdc 100644 --- a/app/deployment.py +++ b/app/deployment.py @@ -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) diff --git a/app/deployment_create.py b/app/deployment_create.py index 4ddd04e3..0289c175 100644 --- a/app/deployment_create.py +++ b/app/deployment_create.py @@ -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)