Implement create with network
This commit is contained in:
parent
61c87712ab
commit
02b5034cd6
@ -20,7 +20,7 @@ from app.deploy_util import VolumeMapping, run_container_command
|
|||||||
from app.command_types import CommandOptions
|
from app.command_types import CommandOptions
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from shutil import copyfile
|
from shutil import copyfile, copytree
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@ -145,6 +145,7 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo
|
|||||||
command_context,
|
command_context,
|
||||||
"laconicd", f"laconicd init {parameters.node_moniker} --home {laconicd_home_path_in_container}\
|
"laconicd", f"laconicd init {parameters.node_moniker} --home {laconicd_home_path_in_container}\
|
||||||
--chain-id {parameters.chain_id}", mounts)
|
--chain-id {parameters.chain_id}", mounts)
|
||||||
|
if options.debug:
|
||||||
print(f"Command output: {output}")
|
print(f"Command output: {output}")
|
||||||
|
|
||||||
elif phase == SetupPhase.JOIN:
|
elif phase == SetupPhase.JOIN:
|
||||||
@ -157,6 +158,7 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo
|
|||||||
output1, status1 = run_container_command(
|
output1, status1 = run_container_command(
|
||||||
command_context, "laconicd", f"laconicd keys add {parameters.key_name} --home {laconicd_home_path_in_container}\
|
command_context, "laconicd", f"laconicd keys add {parameters.key_name} --home {laconicd_home_path_in_container}\
|
||||||
--keyring-backend test", mounts)
|
--keyring-backend test", mounts)
|
||||||
|
if options.debug:
|
||||||
print(f"Command output: {output1}")
|
print(f"Command output: {output1}")
|
||||||
output2, status2 = run_container_command(
|
output2, status2 = run_container_command(
|
||||||
command_context,
|
command_context,
|
||||||
@ -210,17 +212,31 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo
|
|||||||
output1, status1 = run_container_command(
|
output1, status1 = run_container_command(
|
||||||
command_context, "laconicd", f"laconicd collect-gentxs --home {laconicd_home_path_in_container}", mounts)
|
command_context, "laconicd", f"laconicd collect-gentxs --home {laconicd_home_path_in_container}", mounts)
|
||||||
print(f"Command output: {output1}")
|
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
|
# In both cases we validate the genesis file now
|
||||||
output2, status1 = run_container_command(
|
output2, status1 = run_container_command(
|
||||||
command_context, "laconicd", f"laconicd validate-genesis --home {laconicd_home_path_in_container}", mounts)
|
command_context, "laconicd", f"laconicd validate-genesis --home {laconicd_home_path_in_container}", mounts)
|
||||||
print(f"Command output: {output2}")
|
print(f"Command output: {output2}")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("Illegal parameters supplied")
|
print("Illegal parameters supplied")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def create(command_context: DeployCommandContext):
|
def create(command_context: DeployCommandContext, extra_args):
|
||||||
print("Copy the network files here")
|
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):
|
def init(command_context: DeployCommandContext):
|
||||||
|
@ -134,7 +134,7 @@ def call_stack_deploy_setup(deploy_command_context, parameters: LaconicStackSetu
|
|||||||
|
|
||||||
|
|
||||||
# TODO: fold this with function above
|
# 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
|
# Link with the python file in the stack
|
||||||
# Call a function in it
|
# Call a function in it
|
||||||
# If no function found, return None
|
# 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)
|
spec = util.spec_from_file_location("commands", python_file_path)
|
||||||
imported_stack = util.module_from_spec(spec)
|
imported_stack = util.module_from_spec(spec)
|
||||||
spec.loader.exec_module(imported_stack)
|
spec.loader.exec_module(imported_stack)
|
||||||
return imported_stack.create(deployment_context)
|
return imported_stack.create(deployment_context, extra_args)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -198,8 +198,10 @@ def init(ctx, output):
|
|||||||
@click.command()
|
@click.command()
|
||||||
@click.option("--spec-file", required=True, help="Spec file to use to create this deployment")
|
@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")
|
@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
|
@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
|
# This function fails with a useful error message if the file doens't exist
|
||||||
parsed_spec = get_parsed_deployment_spec(spec_file)
|
parsed_spec = get_parsed_deployment_spec(spec_file)
|
||||||
stack_name = parsed_spec['stack']
|
stack_name = parsed_spec['stack']
|
||||||
@ -247,7 +249,7 @@ def create(ctx, spec_file, deployment_dir):
|
|||||||
deployment_command_context = ctx.obj
|
deployment_command_context = ctx.obj
|
||||||
deployment_command_context.stack = stack_name
|
deployment_command_context.stack = stack_name
|
||||||
deployment_context = DeploymentContext(Path(deployment_dir), deployment_command_context)
|
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
|
# TODO: this code should be in the stack .py files but
|
||||||
|
Loading…
Reference in New Issue
Block a user