From c737ec7ed6af4b37f235b18d232da2154fa9eb54 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Mon, 20 Feb 2023 06:43:06 -0700 Subject: [PATCH] Wire up to build-npms Former-commit-id: 7e6268c39d3d2b0b895500d695f28f946fec426e --- app/base.py | 6 ++++-- app/build_npms.py | 15 +++++++++++---- app/deploy_system.py | 6 +++--- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/base.py b/app/base.py index b5ca26d..3c6dbe6 100644 --- a/app/base.py +++ b/app/base.py @@ -42,7 +42,7 @@ class base_stack(ABC): class package_registry_stack(base_stack): - def ensure_available(self, ctx): + def ensure_available(self): self.url = "" # Check if we were given an external registry URL url_from_environment = os.environ.get("CERC_NPM_REGISTRY_URL") @@ -53,7 +53,7 @@ class package_registry_stack(base_stack): else: # Otherwise we expect to use the local package-registry stack # First check if the stack is up - registry_running = get_stack_status("package-registry") + registry_running = get_stack_status(self.config, "package-registry") if registry_running: # If it is available, get its mapped port and construct its URL if self.config.debug: @@ -61,6 +61,8 @@ class package_registry_stack(base_stack): self.url = "http://gitea.local:3000/api/packages/cerc-io/npm/" else: # If not, print a message about how to start it and return fail to the caller + print("ERROR: The package-registry stack is not running, and no external registry specified with CERC_NPM_REGISTRY_URL") + print("ERROR: Start the local package registry with: laconic-so --stack package-registry deploy-system up") return False return True diff --git a/app/build_npms.py b/app/build_npms.py index d794d02..101fde3 100644 --- a/app/build_npms.py +++ b/app/build_npms.py @@ -44,9 +44,16 @@ def command(ctx, include, exclude): # build-npms depends on having access to a writable package registry # so we check here that it is available - package_registry_stack = get_stack(ctx.obj, 'package-registry') - package_registry_stack.ensure_available() - npm_registry_url = package_registry_stack.get_url('package-registry') + package_registry_stack = get_stack(ctx.obj, "package-registry") + registry_available = package_registry_stack.ensure_available() + if not registry_available: + print("FATAL: no npm registry available for build-npms command") + sys.exit(1) + npm_registry_url = package_registry_stack.get_url() + npm_registry_url_token = config("CERC_NPM_AUTH_TOKEN", default=None) + if not npm_registry_url_token: + print("FATAL: CERC_NPM_AUTH_TOKEN is not defined") + sys.exit(1) if local_stack: dev_root_path = os.getcwd()[0:os.getcwd().rindex("stack-orchestrator")] @@ -86,7 +93,7 @@ def command(ctx, include, exclude): if not dry_run: if verbose: print(f"Executing: {build_command}") - envs = {"CERC_NPM_AUTH_TOKEN": os.environ["CERC_NPM_AUTH_TOKEN"]} | ({"CERC_SCRIPT_DEBUG": "true"} if debug else {}) + envs = {"CERC_NPM_AUTH_TOKEN": npm_registry_url_token} | ({"CERC_SCRIPT_DEBUG": "true"} if debug else {}) try: docker.run("cerc/builder-js", remove=True, diff --git a/app/deploy_system.py b/app/deploy_system.py index 4012690..bff573b 100644 --- a/app/deploy_system.py +++ b/app/deploy_system.py @@ -61,10 +61,10 @@ def command(ctx, include, exclude, cluster, command, extra_args): if verbose: print(f"Running compose up for extra_args: {extra_args_list}") for pre_start_command in cluster_context.pre_start_commands: - _run_command(ctx.obj, cluster, pre_start_command) + _run_command(ctx.obj, cluster_context.cluster, pre_start_command) docker.compose.up(detach=True, services=extra_args_list) for post_start_command in cluster_context.post_start_commands: - _run_command(ctx.obj, cluster, post_start_command) + _run_command(ctx.obj, cluster_context.cluster, post_start_command) elif command == "down": if verbose: print("Running compose down") @@ -123,7 +123,7 @@ def get_stack_status(ctx, stack): ctx_copy = copy.copy(ctx) ctx_copy.stack = stack - cluster_context = _make_cluster_context(ctx_copy, [], [], None) + cluster_context = _make_cluster_context(ctx_copy, None, None, None) docker = DockerClient(compose_files=cluster_context.compose_files, compose_project_name=cluster_context.cluster) # TODO: refactor to avoid duplicating this code above if ctx.verbose: