Initial deployment config implementation

This commit is contained in:
David Boreham 2023-10-03 11:52:47 -06:00
parent b485a3b8d8
commit fe2e92889d
6 changed files with 50 additions and 14 deletions

View File

@ -4,6 +4,7 @@ services:
restart: always restart: always
environment: environment:
CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
CERC_TEST_PARAM_1: ${CERC_TEST_PARAM_1:-FAILED}
volumes: volumes:
- test-data:/data - test-data:/data
ports: ports:

View File

@ -14,6 +14,8 @@ else
echo "Filesystem is fresh" echo "Filesystem is fresh"
echo `date` > $EXISTSFILENAME echo `date` > $EXISTSFILENAME
fi fi
if [ -n "$CERC_TEST_PARAM_1" ]; then
echo "Test-param-1: ${CERC_TEST_PARAM_1}"
fi
# Run nginx which will block here forever # Run nginx which will block here forever
/usr/sbin/nginx -g "daemon off;" /usr/sbin/nginx -g "daemon off;"

View File

@ -27,10 +27,7 @@ import sys
import tomli import tomli
import re import re
default_spec_file_content = """config: default_spec_file_content = ""
node_moniker: my-node-name
chain_id: my-chain-id
"""
class SetupPhase(Enum): class SetupPhase(Enum):

View File

@ -20,7 +20,7 @@ from app.deploy_util import VolumeMapping, run_container_command
from pathlib import Path from pathlib import Path
default_spec_file_content = """config: default_spec_file_content = """config:
config_variable: test-value test-variable-1: test-value-1
""" """

View File

@ -25,6 +25,16 @@ from app.deploy import exec_operation, logs_operation, create_deploy_context
class DeploymentContext: class DeploymentContext:
dir: Path dir: Path
def get_stack_file(self):
return self.dir.joinpath("stack.yml")
def get_env_file(self):
return self.dir.joinpath("config.env")
# TODO: implement me
def get_cluster_name(self):
return None
@click.group() @click.group()
@click.option("--dir", required=True, help="path to deployment directory") @click.option("--dir", required=True, help="path to deployment directory")
@ -49,10 +59,10 @@ def command(ctx, dir):
def make_deploy_context(ctx): def make_deploy_context(ctx):
# Get the stack config file name stack_file_path = ctx.obj.get_stack_file()
stack_file_path = ctx.obj.dir.joinpath("stack.yml") env_file = ctx.obj.get_env_file()
# TODO: add cluster name and env file here cluster_name = ctx.obj.get_cluster_name()
return create_deploy_context(ctx.parent.parent.obj, stack_file_path, None, None, None, None) return create_deploy_context(ctx.parent.parent.obj, stack_file_path, None, None, cluster_name, env_file)
@command.command() @command.command()

View File

@ -204,22 +204,48 @@ def _get_mapped_ports(stack: str, map_recipe: str):
return ports return ports
def _parse_config_variables(variable_values: str):
result = None
if variable_values:
value_pairs = variable_values.split(",")
if len(value_pairs):
result_values = {}
for value_pair in value_pairs:
variable_value_pair = value_pair.split("=")
if len(variable_value_pair) != 2:
print(f"ERROR: config argument is not valid: {variable_values}")
sys.exit(1)
variable_name = variable_value_pair[0]
variable_value = variable_value_pair[1]
result_values[variable_name] = variable_value
result = {"config": result_values}
return result
@click.command() @click.command()
@click.option("--config", help="Provide config variables for the deployment")
@click.option("--output", required=True, help="Write yaml spec file here") @click.option("--output", required=True, help="Write yaml spec file here")
@click.option("--map-ports-to-host", required=False, @click.option("--map-ports-to-host", required=False,
help="Map ports to the host as one of: any-variable-random (default), " help="Map ports to the host as one of: any-variable-random (default), "
"localhost-same, any-same, localhost-fixed-random, any-fixed-random") "localhost-same, any-same, localhost-fixed-random, any-fixed-random")
@click.pass_context @click.pass_context
def init(ctx, output, map_ports_to_host): def init(ctx, config, output, map_ports_to_host):
yaml = get_yaml() yaml = get_yaml()
stack = global_options(ctx).stack stack = global_options(ctx).stack
verbose = global_options(ctx).verbose debug = global_options(ctx).debug
default_spec_file_content = call_stack_deploy_init(ctx.obj) default_spec_file_content = call_stack_deploy_init(ctx.obj)
spec_file_content = {"stack": stack} spec_file_content = {"stack": stack}
if default_spec_file_content: if default_spec_file_content:
spec_file_content.update(default_spec_file_content) spec_file_content.update(default_spec_file_content)
if verbose: config_variables = _parse_config_variables(config)
print(f"Creating spec file for stack: {stack}") if config_variables:
# Implement merge, since update() overwrites
orig_config = spec_file_content["config"]
new_config = config_variables["config"]
merged_config = {**new_config, **orig_config}
spec_file_content.update({"config": merged_config})
if debug:
print(f"Creating spec file for stack: {stack} with content: {spec_file_content}")
ports = _get_mapped_ports(stack, map_ports_to_host) ports = _get_mapped_ports(stack, map_ports_to_host)
spec_file_content["ports"] = ports spec_file_content["ports"] = ports