Call from base stack class

Former-commit-id: f1cbce1d00
This commit is contained in:
David Boreham 2023-02-20 06:23:21 -07:00
parent 142be179f4
commit d927c92c0a
2 changed files with 32 additions and 11 deletions

View File

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

View File

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