Implement create with network

This commit is contained in:
David Boreham 2023-08-22 17:43:03 -06:00
parent 61c87712ab
commit 02b5034cd6
2 changed files with 29 additions and 11 deletions

View File

@ -20,7 +20,7 @@ from app.deploy_util import VolumeMapping, run_container_command
from app.command_types import CommandOptions
from enum import Enum
from pathlib import Path
from shutil import copyfile
from shutil import copyfile, copytree
import json
import os
import sys
@ -145,7 +145,8 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo
command_context,
"laconicd", f"laconicd init {parameters.node_moniker} --home {laconicd_home_path_in_container}\
--chain-id {parameters.chain_id}", mounts)
print(f"Command output: {output}")
if options.debug:
print(f"Command output: {output}")
elif phase == SetupPhase.JOIN:
if not os.path.exists(network_dir):
@ -157,7 +158,8 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo
output1, status1 = run_container_command(
command_context, "laconicd", f"laconicd keys add {parameters.key_name} --home {laconicd_home_path_in_container}\
--keyring-backend test", mounts)
print(f"Command output: {output1}")
if options.debug:
print(f"Command output: {output1}")
output2, status2 = run_container_command(
command_context,
"laconicd",
@ -210,17 +212,31 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo
output1, status1 = run_container_command(
command_context, "laconicd", f"laconicd collect-gentxs --home {laconicd_home_path_in_container}", mounts)
print(f"Command output: {output1}")
print(f"Generated genesis file, please copy to other nodes as required: \
{os.path.join(network_dir, 'config', 'genesis.json')}")
# In both cases we validate the genesis file now
output2, status1 = run_container_command(
command_context, "laconicd", f"laconicd validate-genesis --home {laconicd_home_path_in_container}", mounts)
print(f"Command output: {output2}")
else:
print("Illegal parameters supplied")
sys.exit(1)
def create(command_context: DeployCommandContext):
print("Copy the network files here")
def create(command_context: DeployCommandContext, extra_args):
network_dir = extra_args
if network_dir is None:
print("Error: --network-dir must be supplied")
sys.exit(1)
network_dir_path = Path(network_dir)
if not (network_dir_path.exists() and network_dir_path.is_dir()):
print(f"Error: supplied network directory does not exist: {network_dir}")
sys.exit(1)
# Copy the network directory contents into our deployment
# TODO: change this to work with non local paths
deployment_config_dir = command_context.deployment_dir.joinpath("data", "laconicd-config")
copytree(network_dir_path, deployment_config_dir, dirs_exist_ok=True)
def init(command_context: DeployCommandContext):

View File

@ -134,7 +134,7 @@ def call_stack_deploy_setup(deploy_command_context, parameters: LaconicStackSetu
# TODO: fold this with function above
def call_stack_deploy_create(deployment_context):
def call_stack_deploy_create(deployment_context, extra_args):
# Link with the python file in the stack
# Call a function in it
# If no function found, return None
@ -143,7 +143,7 @@ def call_stack_deploy_create(deployment_context):
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.create(deployment_context)
return imported_stack.create(deployment_context, extra_args)
else:
return None
@ -198,8 +198,10 @@ def init(ctx, output):
@click.command()
@click.option("--spec-file", required=True, help="Spec file to use to create this deployment")
@click.option("--deployment-dir", help="Create deployment files in this directory")
# TODO: Hack
@click.option("--network-dir", help="Network configuration supplied in this directory")
@click.pass_context
def create(ctx, spec_file, deployment_dir):
def create(ctx, spec_file, deployment_dir, network_dir):
# This function fails with a useful error message if the file doens't exist
parsed_spec = get_parsed_deployment_spec(spec_file)
stack_name = parsed_spec['stack']
@ -247,7 +249,7 @@ def create(ctx, spec_file, deployment_dir):
deployment_command_context = ctx.obj
deployment_command_context.stack = stack_name
deployment_context = DeploymentContext(Path(deployment_dir), deployment_command_context)
call_stack_deploy_create(deployment_context)
call_stack_deploy_create(deployment_context, network_dir)
# TODO: this code should be in the stack .py files but