diff --git a/app/data/stacks/mainnet-laconic/deploy/commands.py b/app/data/stacks/mainnet-laconic/deploy/commands.py index 932dbc24..a6f45c35 100644 --- a/app/data/stacks/mainnet-laconic/deploy/commands.py +++ b/app/data/stacks/mainnet-laconic/deploy/commands.py @@ -21,6 +21,7 @@ from enum import Enum from pathlib import Path import os import sys +import tomli default_spec_file_content = """config: node_moniker: my-node-name @@ -38,6 +39,22 @@ class SetupPhase(Enum): ILLEGAL = 3 +def _get_chain_id_from_config(): + chain_id = None + with open("laconic-network-dir/config/client.toml", "rb") as f: + toml_dict = tomli.load(f) + chain_id = toml_dict["chain_id"] + return chain_id + + +def _get_node_moniker_from_config(): + moniker = None + with open("laconic-network-dir/config/config.toml", "rb") as f: + toml_dict = tomli.load(f) + moniker = toml_dict["moniker"] + return moniker + + def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCommand, extra_args): print(f"parameters: {parameters}") @@ -51,6 +68,10 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo if not parameters.chain_id: print("--chain-id is required") sys.exit(1) + # node_moniker must be supplied + if not parameters.node_moniker: + print("Error: --node-moniker is required") + sys.exit(1) phase = SetupPhase.INITIALIZE elif parameters.join_network: if parameters.initialize_network or parameters.create_network: @@ -69,6 +90,7 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo if os.path.exists(network_dir): print(f"Error: network directory {network_dir} already exists") sys.exit(1) + os.mkdir(network_dir) mounts = [ VolumeMapping(network_dir, "/root/.laconicd") @@ -83,6 +105,8 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo if not os.path.exists(network_dir): print(f"Error: network directory {network_dir} doesn't exist") sys.exit(1) + # Get the chain_id from the config file created in the INITIALIZE phase + chain_id = _get_chain_id_from_config() mounts = [ VolumeMapping(network_dir, "/root/.laconicd") ] @@ -98,7 +122,7 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo output3, status3 = run_container_command( command_context, "laconicd", - f"laconicd gentx {parameters.key_name} 90000000000achk --chain-id {parameters.chain_id} --keyring-backend test", + f"laconicd gentx {parameters.key_name} 90000000000achk --chain-id {chain_id} --keyring-backend test", mounts) print(f"Command output: {output3}") diff --git a/app/deploy.py b/app/deploy.py index 137935fd..f492ac5f 100644 --- a/app/deploy.py +++ b/app/deploy.py @@ -312,7 +312,7 @@ def _make_cluster_context(ctx, stack, include, exclude, cluster, env_file): if ctx.verbose: print(f"files: {compose_files}") - return ClusterContext(cluster, compose_files, pre_start_commands, post_start_commands, cluster_config, env_file) + return ClusterContext(ctx, cluster, compose_files, pre_start_commands, post_start_commands, cluster_config, env_file) def _convert_to_new_format(old_pod_array): diff --git a/app/deploy_types.py b/app/deploy_types.py index b61a82d1..794ba4f9 100644 --- a/app/deploy_types.py +++ b/app/deploy_types.py @@ -17,9 +17,11 @@ from typing import List from dataclasses import dataclass from pathlib import Path from python_on_whales import DockerClient +from app.command_types import CommandOptions @dataclass class ClusterContext: + options: CommandOptions # TODO: this should be in its own object not stuffed in here cluster: str compose_files: List[str] pre_start_commands: List[str] @@ -56,3 +58,8 @@ class LaconicStackSetupCommand: join_network: bool create_network: bool network_dir: str + + +@dataclass +class LaconicStackCreateCommand: + network_dir: str \ No newline at end of file diff --git a/app/deploy_util.py b/app/deploy_util.py index b50f8102..95ab88fa 100644 --- a/app/deploy_util.py +++ b/app/deploy_util.py @@ -15,12 +15,11 @@ import os from typing import List -from dataclasses import dataclass from app.deploy_types import DeployCommandContext, VolumeMapping from app.util import get_parsed_stack_config, get_yaml, get_compose_file_dir -def _container_image_from_service(stack:str, service: str): +def _container_image_from_service(stack :str, service: str): # Parse the compose files looking for the image name of the specified service image_name = None parsed_stack = get_parsed_stack_config(stack) @@ -51,6 +50,8 @@ def run_container_command(ctx: DeployCommandContext, service: str, command: str, docker = ctx.docker container_image = _container_image_from_service(ctx.stack, service) docker_volumes = _volumes_to_docker(mounts) + if ctx.cluster_context.options.debug: + print(f"Running this command in {service} container: {command}") docker_output = docker.run(container_image, ["-c", command], entrypoint="sh", volumes=docker_volumes) # There doesn't seem to be a way to get an exit code from docker.run() return (docker_output, 0) diff --git a/cli.py b/cli.py index e9a11d25..7ae1fd26 100644 --- a/cli.py +++ b/cli.py @@ -16,6 +16,7 @@ import click from dataclasses import dataclass +from app.command_types import CommandOptions from app import setup_repositories from app import build_containers from app import build_npms @@ -26,17 +27,6 @@ from app import deployment CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) -@dataclass -class Options: - stack: str - quiet: bool = False - verbose: bool = False - dry_run: bool = False - local_stack: bool = False - debug: bool = False - continue_on_error: bool = False - - @click.group(context_settings=CONTEXT_SETTINGS) @click.option('--stack', help="specify a stack to build/deploy") @click.option('--quiet', is_flag=True, default=False) @@ -49,7 +39,7 @@ class Options: @click.pass_context def cli(ctx, stack, quiet, verbose, dry_run, local_stack, debug, continue_on_error): """Laconic Stack Orchestrator""" - ctx.obj = Options(stack, quiet, verbose, dry_run, local_stack, debug, continue_on_error) + ctx.obj = CommandOptions(stack, quiet, verbose, dry_run, local_stack, debug, continue_on_error) cli.add_command(setup_repositories.command, "setup-repositories") diff --git a/requirements.txt b/requirements.txt index 895e677f..538121aa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ click>=8.1.6 PyYAML>=6.0.1 ruamel.yaml>=0.17.32 pydantic==1.10.9 +tomli==2.0.1