Implement deployment config #554

Merged
telackey merged 4 commits from dboreham/deployment-config into main 2023-10-03 18:49:16 +00:00
6 changed files with 50 additions and 14 deletions
Showing only changes of commit fe2e92889d - Show all commits

View File

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

View File

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

View File

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

View File

@ -20,7 +20,7 @@ from app.deploy_util import VolumeMapping, run_container_command
from pathlib import Path
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:
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.option("--dir", required=True, help="path to deployment directory")
@ -49,10 +59,10 @@ def command(ctx, dir):
def make_deploy_context(ctx):
# Get the stack config file name
stack_file_path = ctx.obj.dir.joinpath("stack.yml")
# TODO: add cluster name and env file here
return create_deploy_context(ctx.parent.parent.obj, stack_file_path, None, None, None, None)
stack_file_path = ctx.obj.get_stack_file()
env_file = ctx.obj.get_env_file()
cluster_name = ctx.obj.get_cluster_name()
return create_deploy_context(ctx.parent.parent.obj, stack_file_path, None, None, cluster_name, env_file)
@command.command()

View File

@ -204,22 +204,48 @@ def _get_mapped_ports(stack: str, map_recipe: str):
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.option("--config", help="Provide config variables for the deployment")
@click.option("--output", required=True, help="Write yaml spec file here")
@click.option("--map-ports-to-host", required=False,
help="Map ports to the host as one of: any-variable-random (default), "
"localhost-same, any-same, localhost-fixed-random, any-fixed-random")
@click.pass_context
def init(ctx, output, map_ports_to_host):
def init(ctx, config, output, map_ports_to_host):
yaml = get_yaml()
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)
spec_file_content = {"stack": stack}
if default_spec_file_content:
spec_file_content.update(default_spec_file_content)
if verbose:
print(f"Creating spec file for stack: {stack}")
config_variables = _parse_config_variables(config)
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)
spec_file_content["ports"] = ports