Wire up to build-npms

Former-commit-id: 7e6268c39d
This commit is contained in:
David Boreham 2023-02-20 06:43:06 -07:00
parent d927c92c0a
commit c737ec7ed6
3 changed files with 18 additions and 9 deletions

View File

@ -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 = "<no registry url set>"
# 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

View File

@ -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,

View File

@ -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: