diff --git a/deploy/utils/deploy_utils.py b/deploy/utils/deploy_utils.py index 88b9f1afd..5b0bc477a 100644 --- a/deploy/utils/deploy_utils.py +++ b/deploy/utils/deploy_utils.py @@ -4,10 +4,10 @@ import shutil import time -from deploy.utils.shell_utils import run_shell_command +from utils.shell_utils import run_shell_command from deploy.utils.constants import BASE_DIR, DEPLOYMENT_SCRIPTS -from deploy.utils.other_utils import retrieve_settings, check_kubernetes_context -from deploy.utils.servctl_utils import render, script_processor, template_processor +from deploy.utils.servctl_utils import render, script_processor, template_processor, \ + retrieve_settings, check_kubernetes_context logger = logging.getLogger() @@ -16,7 +16,7 @@ def deploy(deployment_label, component=None, output_dir=None, other_settings={}) """ Args: deployment_label (string): one of the DEPLOYMENT_LABELS (eg. "local", or "gcloud") - component (string): optionally specifies one of the components from the DEPLOYABLE_COMPONENTS lists (eg. "postgres" or "phenotips"). + component (string): optionally specifies one of the components from the DEPLOYABLE_COMPONENTS lists (eg. "elasitsearch"). If this is set to None, all DEPLOYABLE_COMPONENTS will be deployed in sequence. output_dir (string): path of directory where to put deployment logs and rendered config files other_settings (dict): a dictionary of other key-value pairs for use during deployment @@ -49,36 +49,47 @@ def deploy(deployment_label, component=None, output_dir=None, other_settings={}) logger.info("%s = %s" % (key, value)) # copy settings, templates and scripts to output directory - os.chdir("deploy") - output_base_dir = os.path.join(output_dir, 'kubernetes/settings') - for file_path in glob.glob("kubernetes/templates/*/*.*") + glob.glob("kubernetes/templates/*/*/*.*"): - file_path = file_path.replace('kubernetes/templates/', '') - input_base_dir = os.path.join(BASE_DIR, 'kubernetes/templates') + for file_path in glob.glob("deploy/kubernetes/templates/*/*.*") + glob.glob("deploy/kubernetes/templates/*/*/*.*"): + file_path = file_path.replace('deploy/kubernetes/templates/', '') + input_base_dir = os.path.join(BASE_DIR, 'deploy/kubernetes/templates') + output_base_dir = os.path.join(output_dir, 'deploy/kubernetes/configs') render(template_processor, input_base_dir, file_path, settings, output_base_dir) - for file_path in glob.glob(os.path.join("kubernetes/scripts/*.sh")): + for file_path in glob.glob(os.path.join("deploy/kubernetes/scripts/*.sh")): render(script_processor, BASE_DIR, file_path, settings, output_dir) - for file_path in glob.glob(os.path.join("kubernetes/scripts/*.py")): - shutil.copy(file_path, output_base_dir) + #for file_path in glob.glob(os.path.join("kubernetes/scripts/*.py")): + # shutil.copy(file_path, output_base_dir) - for file_path in glob.glob(os.path.join("settings/*.yaml")): - shutil.copy(file_path, output_base_dir) + for file_path in glob.glob(os.path.join("deploy/kubernetes/settings/*.yaml")): + try: + os.makedirs(os.path.join(output_dir, os.path.dirname(file_path))) + except OSError as e: + # ignore if the error is that the directory already exists + # TODO after switch to python3, use exist_ok arg + if "File exists" not in str(e): + raise + + shutil.copy(file_path, os.path.join(output_dir, file_path)) # copy docker directory to output directory - docker_src_dir = os.path.join(BASE_DIR, "docker/") - docker_dest_dir = os.path.join(output_dir, "docker") + docker_src_dir = os.path.join(BASE_DIR, "deploy/docker/") + docker_dest_dir = os.path.join(output_dir, "deploy/docker") logger.info("Copying %(docker_src_dir)s to %(docker_dest_dir)s" % locals()) shutil.copytree(docker_src_dir, docker_dest_dir) + # write out ConfigMap file so that settings key/values can be added as environment variables in each of the pods + with open(os.path.join(output_dir, "deploy/kubernetes/settings/all-settings.properties"), "w") as f: + for key, value in settings.items(): + f.write("%s=%s\n" % (key, value)) # deploy if component: deployment_scripts = [s for s in DEPLOYMENT_SCRIPTS if 'deploy_begin' in s or component in s or component.replace('-', '_') in s] else: - deployment_scripts = [s for s in DEPLOYMENT_SCRIPTS] # don't deploy these by default + deployment_scripts = DEPLOYMENT_SCRIPTS - os.chdir(output_dir) + os.chdir(os.path.join(output_dir, "deploy")) logger.info("Switched to %(output_dir)s" % locals()) for path in deployment_scripts: