From d927c92c0af286d199ca2f2b9d3f938c89a94371 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Mon, 20 Feb 2023 06:23:21 -0700 Subject: [PATCH] Call from base stack class Former-commit-id: f1cbce1d00db85009fc4c1bc424458cba76b9bfc --- app/base.py | 21 ++++++++++++--------- app/deploy_system.py | 22 ++++++++++++++++++++-- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/app/base.py b/app/base.py index 52528a6d..b5ca26dc 100644 --- a/app/base.py +++ b/app/base.py @@ -15,6 +15,8 @@ import os from abc import ABC, abstractmethod +from .deploy_system import get_stack_status + def get_stack(config, stack): if stack == "package-registry": @@ -40,7 +42,7 @@ class base_stack(ABC): class package_registry_stack(base_stack): - def ensure_available(self): + def ensure_available(self, ctx): self.url = "" # Check if we were given an external registry URL url_from_environment = os.environ.get("CERC_NPM_REGISTRY_URL") @@ -51,10 +53,15 @@ class package_registry_stack(base_stack): else: # Otherwise we expect to use the local package-registry stack # First check if the stack is up - # If not, print a message about how to start it and return fail to the caller - return False - # If it is available, get its mapped port and construct its URL - self.url = "http://gitea.local:3000/api/packages/cerc-io/npm/" + registry_running = get_stack_status("package-registry") + if registry_running: + # If it is available, get its mapped port and construct its URL + if self.config.debug: + print("Found local package registry stack is up") + 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 + return False return True def get_url(self): @@ -63,9 +70,5 @@ class package_registry_stack(base_stack): # Temporary helper functions while we figure out a good interface to the stack deploy code -def _is_stack_running(stack): - return True - - def _get_stack_mapped_port(stack, service, exposed_port): return 3000 diff --git a/app/deploy_system.py b/app/deploy_system.py index 3fd42f58..4012690a 100644 --- a/app/deploy_system.py +++ b/app/deploy_system.py @@ -16,6 +16,7 @@ # Deploys the system components using docker-compose import hashlib +import copy import os import sys from decouple import config @@ -117,8 +118,25 @@ def command(ctx, include, exclude, cluster, command, extra_args): docker.compose.logs() -def get_stack_status(stack): - pass +def get_stack_status(ctx, stack): + + ctx_copy = copy.copy(ctx) + ctx_copy.stack = stack + + cluster_context = _make_cluster_context(ctx_copy, [], [], 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: + print("Running compose ps") + container_list = docker.compose.ps() + if len(container_list) > 0: + if ctx.debug: + print(f"Container list from compose ps: {container_list}") + return True + else: + if ctx.debug: + print("No containers found from compose ps") + False def _make_cluster_context(ctx, include, exclude, cluster):