From 13ce521d8462daa9552d72b0a47910e38b01806e Mon Sep 17 00:00:00 2001 From: David Boreham Date: Tue, 23 Apr 2024 21:47:20 +0000 Subject: [PATCH] Fix config dir processing for external stacks (#810) Reviewed-on: https://git.vdb.to/cerc-io/stack-orchestrator/pulls/810 Co-authored-by: David Boreham Co-committed-by: David Boreham --- stack_orchestrator/deploy/deployment_create.py | 6 +++--- stack_orchestrator/util.py | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/stack_orchestrator/deploy/deployment_create.py b/stack_orchestrator/deploy/deployment_create.py index 94d7f772..4e0a8e13 100644 --- a/stack_orchestrator/deploy/deployment_create.py +++ b/stack_orchestrator/deploy/deployment_create.py @@ -26,7 +26,8 @@ from stack_orchestrator import constants from stack_orchestrator.opts import opts from stack_orchestrator.util import (get_stack_file_path, get_parsed_deployment_spec, get_parsed_stack_config, global_options, get_yaml, get_pod_list, get_pod_file_path, pod_has_scripts, - get_pod_script_paths, get_plugin_code_paths, error_exit, env_var_map_from_file) + get_pod_script_paths, get_plugin_code_paths, error_exit, env_var_map_from_file, + resolve_config_dir) from stack_orchestrator.deploy.spec import Spec from stack_orchestrator.deploy.deploy_types import LaconicStackSetupCommand from stack_orchestrator.deploy.deployer_factory import getDeployerConfigGenerator @@ -480,7 +481,6 @@ def create_operation(deployment_command_context, spec_file, deployment_dir, netw os.mkdir(destination_compose_dir) destination_pods_dir = deployment_dir_path.joinpath("pods") os.mkdir(destination_pods_dir) - data_dir = Path(__file__).absolute().parent.parent.joinpath("data") yaml = get_yaml() for pod in pods: pod_file_path = get_pod_file_path(stack_name, parsed_stack, pod) @@ -497,7 +497,7 @@ def create_operation(deployment_command_context, spec_file, deployment_dir, netw config_dirs = {pod} config_dirs = config_dirs.union(extra_config_dirs) for config_dir in config_dirs: - source_config_dir = data_dir.joinpath("config", config_dir) + source_config_dir = resolve_config_dir(stack_name, config_dir) if os.path.exists(source_config_dir): destination_config_dir = deployment_dir_path.joinpath("config", config_dir) # If the same config dir appears in multiple pods, it may already have been copied diff --git a/stack_orchestrator/util.py b/stack_orchestrator/util.py index c2422f72..d4e4d32f 100644 --- a/stack_orchestrator/util.py +++ b/stack_orchestrator/util.py @@ -94,6 +94,20 @@ def get_plugin_code_paths(stack) -> List[Path]: return list(result) +# # Find a config directory, looking first in any external stack +# and if not found there, internally +def resolve_config_dir(stack, config_dir_name: str): + if stack_is_external(stack): + # First try looking in the external stack for the compose file + config_base = Path(stack).parent.parent.joinpath("config") + proposed_dir = config_base.joinpath(config_dir_name) + if proposed_dir.exists(): + return proposed_dir + # If we don't find it fall through to the internal case + config_base = get_internal_config_dir() + return config_base.joinpath(config_dir_name) + + # Find a compose file, looking first in any external stack # and if not found there, internally def resolve_compose_file(stack, pod_name: str): @@ -153,7 +167,7 @@ def get_internal_compose_file_dir(): return source_compose_dir -def get_config_file_dir(): +def get_internal_config_dir(): # TODO: refactor to use common code with deploy command data_dir = Path(__file__).absolute().parent.joinpath("data") source_config_dir = data_dir.joinpath("config")