forked from cerc-io/stack-orchestrator
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
964edbec6f | ||
|
|
6f2a44ba2f | ||
|
|
9053d2d782 | ||
|
|
628fed4ef7 | ||
|
|
c737ec7ed6 | ||
|
|
d927c92c0a | ||
|
|
142be179f4 | ||
|
|
547ca561c0 | ||
|
|
863e19211e | ||
|
|
e20f9993d2 | ||
|
|
9dab9b815c | ||
|
|
83115bcb9d | ||
|
|
46c22f4e4f | ||
|
|
912483df58 | ||
|
|
ff69670db6 | ||
|
|
871cd90456 | ||
|
|
639ab8cbc3 | ||
|
|
bc5eff71b5 | ||
|
|
5ec774a300 |
+77
@@ -0,0 +1,77 @@
|
|||||||
|
# Copyright © 2022, 2023 Cerc
|
||||||
|
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import os
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
|
from .deploy_system import get_stack_status
|
||||||
|
|
||||||
|
|
||||||
|
def get_stack(config, stack):
|
||||||
|
if stack == "package-registry":
|
||||||
|
return package_registry_stack(config, stack)
|
||||||
|
else:
|
||||||
|
return base_stack(config, stack)
|
||||||
|
|
||||||
|
|
||||||
|
class base_stack(ABC):
|
||||||
|
|
||||||
|
def __init__(self, config, stack):
|
||||||
|
self.config = config
|
||||||
|
self.stack = stack
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def ensure_available(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def get_url(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class package_registry_stack(base_stack):
|
||||||
|
|
||||||
|
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")
|
||||||
|
if url_from_environment:
|
||||||
|
if self.config.verbose:
|
||||||
|
print(f"Using package registry url from CERC_NPM_REGISTRY_URL: {url_from_environment}")
|
||||||
|
self.url = url_from_environment
|
||||||
|
else:
|
||||||
|
# Otherwise we expect to use the local package-registry stack
|
||||||
|
# First check if the stack is up
|
||||||
|
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:
|
||||||
|
print("Found local package registry stack is up")
|
||||||
|
# TODO: get url from deploy-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
|
||||||
|
|
||||||
|
def get_url(self):
|
||||||
|
return self.url
|
||||||
|
|
||||||
|
# Temporary helper functions while we figure out a good interface to the stack deploy code
|
||||||
|
|
||||||
|
|
||||||
|
def _get_stack_mapped_port(stack, service, exposed_port):
|
||||||
|
return 3000
|
||||||
@@ -103,7 +103,7 @@ def command(ctx, include, exclude):
|
|||||||
# Check if we have a repo for this container. If not, set the context dir to the container-build subdir
|
# Check if we have a repo for this container. If not, set the context dir to the container-build subdir
|
||||||
repo_full_path = os.path.join(dev_root_path, repo_dir)
|
repo_full_path = os.path.join(dev_root_path, repo_dir)
|
||||||
repo_dir_or_build_dir = repo_dir if os.path.exists(repo_full_path) else build_dir
|
repo_dir_or_build_dir = repo_dir if os.path.exists(repo_full_path) else build_dir
|
||||||
build_command = os.path.join(container_build_dir, "default-build.sh") + f" {container} {repo_dir_or_build_dir}"
|
build_command = os.path.join(container_build_dir, "default-build.sh") + f" {container}:local {repo_dir_or_build_dir}"
|
||||||
if not dry_run:
|
if not dry_run:
|
||||||
if verbose:
|
if verbose:
|
||||||
print(f"Executing: {build_command}")
|
print(f"Executing: {build_command}")
|
||||||
|
|||||||
+32
-3
@@ -24,8 +24,11 @@ from decouple import config
|
|||||||
import click
|
import click
|
||||||
import importlib.resources
|
import importlib.resources
|
||||||
from python_on_whales import docker, DockerException
|
from python_on_whales import docker, DockerException
|
||||||
|
from .base import get_stack
|
||||||
from .util import include_exclude_check, get_parsed_stack_config
|
from .util import include_exclude_check, get_parsed_stack_config
|
||||||
|
|
||||||
|
builder_js_image_name = "cerc/builder-js:local"
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option('--include', help="only build these packages")
|
@click.option('--include', help="only build these packages")
|
||||||
@click.option('--exclude', help="don\'t build these packages")
|
@click.option('--exclude', help="don\'t build these packages")
|
||||||
@@ -41,6 +44,21 @@ def command(ctx, include, exclude):
|
|||||||
stack = ctx.obj.stack
|
stack = ctx.obj.stack
|
||||||
continue_on_error = ctx.obj.continue_on_error
|
continue_on_error = ctx.obj.continue_on_error
|
||||||
|
|
||||||
|
_ensure_prerequisites()
|
||||||
|
|
||||||
|
# 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")
|
||||||
|
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:
|
if local_stack:
|
||||||
dev_root_path = os.getcwd()[0:os.getcwd().rindex("stack-orchestrator")]
|
dev_root_path = os.getcwd()[0:os.getcwd().rindex("stack-orchestrator")]
|
||||||
print(f'Local stack dev_root_path (CERC_REPO_BASE_DIR) overridden to: {dev_root_path}')
|
print(f'Local stack dev_root_path (CERC_REPO_BASE_DIR) overridden to: {dev_root_path}')
|
||||||
@@ -75,18 +93,19 @@ def command(ctx, include, exclude):
|
|||||||
repo_dir = package
|
repo_dir = package
|
||||||
repo_full_path = os.path.join(dev_root_path, repo_dir)
|
repo_full_path = os.path.join(dev_root_path, repo_dir)
|
||||||
# TODO: make the npm registry url configurable.
|
# TODO: make the npm registry url configurable.
|
||||||
build_command = ["sh", "-c", "cd /workspace && build-npm-package-local-dependencies.sh http://gitea.local:3000/api/packages/cerc-io/npm/"]
|
build_command = ["sh", "-c", f"cd /workspace && build-npm-package-local-dependencies.sh {npm_registry_url}"]
|
||||||
if not dry_run:
|
if not dry_run:
|
||||||
if verbose:
|
if verbose:
|
||||||
print(f"Executing: {build_command}")
|
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:
|
try:
|
||||||
docker.run("cerc/builder-js",
|
docker.run(builder_js_image_name,
|
||||||
remove=True,
|
remove=True,
|
||||||
interactive=True,
|
interactive=True,
|
||||||
tty=True,
|
tty=True,
|
||||||
user=f"{os.getuid()}:{os.getgid()}",
|
user=f"{os.getuid()}:{os.getgid()}",
|
||||||
envs=envs,
|
envs=envs,
|
||||||
|
# TODO: detect this host name in npm_registry_url rather than hard-wiring it
|
||||||
add_hosts=[("gitea.local", "host-gateway")],
|
add_hosts=[("gitea.local", "host-gateway")],
|
||||||
volumes=[(repo_full_path, "/workspace")],
|
volumes=[(repo_full_path, "/workspace")],
|
||||||
command=build_command
|
command=build_command
|
||||||
@@ -111,3 +130,13 @@ def command(ctx, include, exclude):
|
|||||||
else:
|
else:
|
||||||
if verbose:
|
if verbose:
|
||||||
print(f"Excluding: {package}")
|
print(f"Excluding: {package}")
|
||||||
|
|
||||||
|
|
||||||
|
def _ensure_prerequisites():
|
||||||
|
# Check that the builder-js container is available and
|
||||||
|
# Tell the user how to build it if not
|
||||||
|
images = docker.image.list(builder_js_image_name)
|
||||||
|
if len(images) == 0:
|
||||||
|
print(f"FATAL: builder image: {builder_js_image_name} is required but was not found")
|
||||||
|
print("Please run this command to create it: laconic-so --stack build-support build-containers")
|
||||||
|
sys.exit(1)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM quay.io/keycloak/keycloak:20.0
|
FROM quay.io/keycloak/keycloak:20.0
|
||||||
WORKDIR /opt/keycloak/providers
|
WORKDIR /opt/keycloak/providers
|
||||||
RUN curl -L https://github.com/aerogear/keycloak-metrics-spi/releases/download/2.5.3/keycloak-metrics-spi-2.5.3.jar --output keycloak-metrics-spi.jar
|
RUN curl -L https://github.com/aerogear/keycloak-metrics-spi/releases/download/2.5.3/keycloak-metrics-spi-2.5.3.jar --output keycloak-metrics-spi.jar
|
||||||
RUN curl -L https://github.com/cerc-io/keycloak-api-key-demo/releases/download/v0.2/api-key-module-0.2.jar --output api-key-module.jar
|
RUN curl -L https://github.com/cerc-io/keycloak-api-key-demo/releases/download/v0.3/api-key-module-0.3.jar --output api-key-module.jar
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Usage: default-build.sh <image-tag> [<repo-relative-path>]
|
# Usage: default-build.sh <image-tag> [<repo-relative-path>]
|
||||||
# if <repo-relative-path> is not supplied, the context is the directory where the Dockerfile lives
|
# if <repo-relative-path> is not supplied, the context is the directory where the Dockerfile lives
|
||||||
|
if [[ -n "$CERC_SCRIPT_DEBUG" ]]; then
|
||||||
|
set -x
|
||||||
|
fi
|
||||||
if [[ $# -ne 2 ]]; then
|
if [[ $# -ne 2 ]]; then
|
||||||
echo "Illegal number of parameters" >&2
|
echo "Illegal number of parameters" >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
version: "1.1"
|
||||||
|
name: build-support
|
||||||
|
decription: "Build Support Components"
|
||||||
|
containers:
|
||||||
|
- cerc/builder-js
|
||||||
|
- cerc/builder-gerbil
|
||||||
@@ -7,13 +7,13 @@ Instructions to deploy a local ERC20 watcher stack (core + watcher) for demonstr
|
|||||||
Clone required repositories:
|
Clone required repositories:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic-so setup-repositories --include cerc-io/go-ethereum,cerc-io/ipld-eth-db,cerc-io/ipld-eth-server,cerc-io/watcher-ts
|
laconic-so --stack erc20 setup-repositories
|
||||||
```
|
```
|
||||||
|
|
||||||
Build the core and watcher container images:
|
Build the core and watcher container images:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic-so build-containers --include cerc/go-ethereum,cerc/go-ethereum-foundry,cerc/ipld-eth-db,cerc/ipld-eth-server,cerc/watcher-erc20
|
laconic-so --stack erc20 build-containers
|
||||||
```
|
```
|
||||||
|
|
||||||
This should create the required docker images in the local image registry.
|
This should create the required docker images in the local image registry.
|
||||||
@@ -21,7 +21,7 @@ This should create the required docker images in the local image registry.
|
|||||||
Deploy the stack:
|
Deploy the stack:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic-so deploy-system --include ipld-eth-db,go-ethereum-foundry,ipld-eth-server,watcher-erc20 up
|
laconic-so --stack erc20 deploy-system up
|
||||||
```
|
```
|
||||||
|
|
||||||
## Demo
|
## Demo
|
||||||
@@ -153,5 +153,5 @@ Transfer funds between different accounts using MetaMask and use the playground
|
|||||||
To stop all the services running in background run:
|
To stop all the services running in background run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic-so deploy-system --include ipld-eth-db,go-ethereum-foundry,ipld-eth-server,watcher-erc20 down
|
laconic-so --stack erc20 deploy-system down
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
version: "1.1"
|
||||||
|
name: package-registry
|
||||||
|
decription: "Local Package Registry"
|
||||||
|
repos:
|
||||||
|
- cerc-io/hosting
|
||||||
|
pods:
|
||||||
|
- name: gitea
|
||||||
|
repository: cerc-io/hosting
|
||||||
|
path: gitea
|
||||||
|
pre_start_command: "run-this-first.sh"
|
||||||
|
post_start_command: "initialize-gitea.sh"
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
# This file should be re-generated running: scripts/update-version-file.sh script
|
# This file should be re-generated running: scripts/update-version-file.sh script
|
||||||
v1.0.18-3bd0c74
|
v1.0.19-10f2fba
|
||||||
|
|||||||
+140
-42
@@ -16,8 +16,11 @@
|
|||||||
# Deploys the system components using docker-compose
|
# Deploys the system components using docker-compose
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import copy
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from decouple import config
|
||||||
|
import subprocess
|
||||||
from python_on_whales import DockerClient
|
from python_on_whales import DockerClient
|
||||||
import click
|
import click
|
||||||
import importlib.resources
|
import importlib.resources
|
||||||
@@ -40,53 +43,14 @@ def command(ctx, include, exclude, cluster, command, extra_args):
|
|||||||
debug = ctx.obj.debug
|
debug = ctx.obj.debug
|
||||||
quiet = ctx.obj.quiet
|
quiet = ctx.obj.quiet
|
||||||
verbose = ctx.obj.verbose
|
verbose = ctx.obj.verbose
|
||||||
|
local_stack = ctx.obj.local_stack
|
||||||
dry_run = ctx.obj.dry_run
|
dry_run = ctx.obj.dry_run
|
||||||
stack = ctx.obj.stack
|
stack = ctx.obj.stack
|
||||||
|
|
||||||
# See: https://stackoverflow.com/questions/25389095/python-get-path-of-root-project-structure
|
cluster_context = _make_cluster_context(ctx.obj, include, exclude, cluster)
|
||||||
compose_dir = Path(__file__).absolute().parent.joinpath("data", "compose")
|
|
||||||
|
|
||||||
if cluster is None:
|
|
||||||
# Create default unique, stable cluster name from confile file path
|
|
||||||
# TODO: change this to the config file path
|
|
||||||
path = os.path.realpath(sys.argv[0])
|
|
||||||
hash = hashlib.md5(path.encode()).hexdigest()
|
|
||||||
cluster = f"laconic-{hash}"
|
|
||||||
if verbose:
|
|
||||||
print(f"Using cluster name: {cluster}")
|
|
||||||
|
|
||||||
# See: https://stackoverflow.com/a/20885799/1701505
|
|
||||||
from . import data
|
|
||||||
with importlib.resources.open_text(data, "pod-list.txt") as pod_list_file:
|
|
||||||
all_pods = pod_list_file.read().splitlines()
|
|
||||||
|
|
||||||
pods_in_scope = []
|
|
||||||
if stack:
|
|
||||||
stack_config = get_parsed_stack_config(stack)
|
|
||||||
# TODO: syntax check the input here
|
|
||||||
pods_in_scope = stack_config['pods']
|
|
||||||
else:
|
|
||||||
pods_in_scope = all_pods
|
|
||||||
|
|
||||||
if verbose:
|
|
||||||
print(f"Pods: {pods_in_scope}")
|
|
||||||
|
|
||||||
# Construct a docker compose command suitable for our purpose
|
|
||||||
|
|
||||||
compose_files = []
|
|
||||||
for pod in pods_in_scope:
|
|
||||||
if include_exclude_check(pod, include, exclude):
|
|
||||||
compose_file_name = os.path.join(compose_dir, f"docker-compose-{pod}.yml")
|
|
||||||
compose_files.append(compose_file_name)
|
|
||||||
else:
|
|
||||||
if verbose:
|
|
||||||
print(f"Excluding: {pod}")
|
|
||||||
|
|
||||||
if verbose:
|
|
||||||
print(f"files: {compose_files}")
|
|
||||||
|
|
||||||
# See: https://gabrieldemarmiesse.github.io/python-on-whales/sub-commands/compose/
|
# See: https://gabrieldemarmiesse.github.io/python-on-whales/sub-commands/compose/
|
||||||
docker = DockerClient(compose_files=compose_files, compose_project_name=cluster)
|
docker = DockerClient(compose_files=cluster_context.compose_files, compose_project_name=cluster_context.cluster)
|
||||||
|
|
||||||
extra_args_list = list(extra_args) or None
|
extra_args_list = list(extra_args) or None
|
||||||
|
|
||||||
@@ -96,7 +60,11 @@ def command(ctx, include, exclude, cluster, command, extra_args):
|
|||||||
os.environ["CERC_SCRIPT_DEBUG"] = "true"
|
os.environ["CERC_SCRIPT_DEBUG"] = "true"
|
||||||
if verbose:
|
if verbose:
|
||||||
print(f"Running compose up for extra_args: {extra_args_list}")
|
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_context.cluster, pre_start_command)
|
||||||
docker.compose.up(detach=True, services=extra_args_list)
|
docker.compose.up(detach=True, services=extra_args_list)
|
||||||
|
for post_start_command in cluster_context.post_start_commands:
|
||||||
|
_run_command(ctx.obj, cluster_context.cluster, post_start_command)
|
||||||
elif command == "down":
|
elif command == "down":
|
||||||
if verbose:
|
if verbose:
|
||||||
print("Running compose down")
|
print("Running compose down")
|
||||||
@@ -148,3 +116,133 @@ def command(ctx, include, exclude, cluster, command, extra_args):
|
|||||||
if verbose:
|
if verbose:
|
||||||
print("Running compose logs")
|
print("Running compose logs")
|
||||||
docker.compose.logs()
|
docker.compose.logs()
|
||||||
|
|
||||||
|
|
||||||
|
def get_stack_status(ctx, stack):
|
||||||
|
|
||||||
|
ctx_copy = copy.copy(ctx)
|
||||||
|
ctx_copy.stack = stack
|
||||||
|
|
||||||
|
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:
|
||||||
|
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):
|
||||||
|
|
||||||
|
if ctx.local_stack:
|
||||||
|
dev_root_path = os.getcwd()[0:os.getcwd().rindex("stack-orchestrator")]
|
||||||
|
print(f'Local stack dev_root_path (CERC_REPO_BASE_DIR) overridden to: {dev_root_path}')
|
||||||
|
else:
|
||||||
|
dev_root_path = os.path.expanduser(config("CERC_REPO_BASE_DIR", default="~/cerc"))
|
||||||
|
|
||||||
|
# See: https://stackoverflow.com/questions/25389095/python-get-path-of-root-project-structure
|
||||||
|
compose_dir = Path(__file__).absolute().parent.joinpath("data", "compose")
|
||||||
|
|
||||||
|
if cluster is None:
|
||||||
|
# Create default unique, stable cluster name from confile file path
|
||||||
|
# TODO: change this to the config file path
|
||||||
|
path = os.path.realpath(sys.argv[0])
|
||||||
|
hash = hashlib.md5(path.encode()).hexdigest()
|
||||||
|
cluster = f"laconic-{hash}"
|
||||||
|
if ctx.verbose:
|
||||||
|
print(f"Using cluster name: {cluster}")
|
||||||
|
|
||||||
|
# See: https://stackoverflow.com/a/20885799/1701505
|
||||||
|
from . import data
|
||||||
|
with importlib.resources.open_text(data, "pod-list.txt") as pod_list_file:
|
||||||
|
all_pods = pod_list_file.read().splitlines()
|
||||||
|
|
||||||
|
pods_in_scope = []
|
||||||
|
if ctx.stack:
|
||||||
|
stack_config = get_parsed_stack_config(ctx.stack)
|
||||||
|
# TODO: syntax check the input here
|
||||||
|
pods_in_scope = stack_config['pods']
|
||||||
|
else:
|
||||||
|
pods_in_scope = all_pods
|
||||||
|
|
||||||
|
# Convert all pod definitions to v1.1 format
|
||||||
|
pods_in_scope = _convert_to_new_format(pods_in_scope)
|
||||||
|
|
||||||
|
if ctx.verbose:
|
||||||
|
print(f"Pods: {pods_in_scope}")
|
||||||
|
|
||||||
|
# Construct a docker compose command suitable for our purpose
|
||||||
|
|
||||||
|
compose_files = []
|
||||||
|
pre_start_commands = []
|
||||||
|
post_start_commands = []
|
||||||
|
for pod in pods_in_scope:
|
||||||
|
pod_name = pod["name"]
|
||||||
|
pod_repository = pod["repository"]
|
||||||
|
pod_path = pod["path"]
|
||||||
|
if include_exclude_check(pod_name, include, exclude):
|
||||||
|
if pod_repository is None or pod_repository == "internal":
|
||||||
|
compose_file_name = os.path.join(compose_dir, f"docker-compose-{pod_path}.yml")
|
||||||
|
else:
|
||||||
|
pod_root_dir = os.path.join(dev_root_path, pod_repository.split("/")[-1], pod["path"])
|
||||||
|
compose_file_name = os.path.join(pod_root_dir, "docker-compose.yml")
|
||||||
|
pod_pre_start_command = pod["pre_start_command"]
|
||||||
|
pod_post_start_command = pod["post_start_command"]
|
||||||
|
if pod_pre_start_command is not None:
|
||||||
|
pre_start_commands.append(os.path.join(pod_root_dir, pod_pre_start_command))
|
||||||
|
if pod_post_start_command is not None:
|
||||||
|
post_start_commands.append(os.path.join(pod_root_dir, pod_post_start_command))
|
||||||
|
compose_files.append(compose_file_name)
|
||||||
|
else:
|
||||||
|
if ctx.verbose:
|
||||||
|
print(f"Excluding: {pod_name}")
|
||||||
|
|
||||||
|
if ctx.verbose:
|
||||||
|
print(f"files: {compose_files}")
|
||||||
|
|
||||||
|
return cluster_context(cluster, compose_files, pre_start_commands, post_start_commands)
|
||||||
|
|
||||||
|
|
||||||
|
class cluster_context:
|
||||||
|
def __init__(self, cluster, compose_files, pre_start_commands, post_start_commands) -> None:
|
||||||
|
self.cluster = cluster
|
||||||
|
self.compose_files = compose_files
|
||||||
|
self.pre_start_commands = pre_start_commands
|
||||||
|
self.post_start_commands = post_start_commands
|
||||||
|
|
||||||
|
|
||||||
|
def _convert_to_new_format(old_pod_array):
|
||||||
|
new_pod_array = []
|
||||||
|
for old_pod in old_pod_array:
|
||||||
|
if isinstance(old_pod, dict):
|
||||||
|
new_pod_array.append(old_pod)
|
||||||
|
else:
|
||||||
|
new_pod = {
|
||||||
|
"name": old_pod,
|
||||||
|
"repository": "internal",
|
||||||
|
"path": old_pod
|
||||||
|
}
|
||||||
|
new_pod_array.append(new_pod)
|
||||||
|
return new_pod_array
|
||||||
|
|
||||||
|
|
||||||
|
def _run_command(ctx, cluster_name, command):
|
||||||
|
if ctx.verbose:
|
||||||
|
print(f"Running command: {command}")
|
||||||
|
command_dir = os.path.dirname(command)
|
||||||
|
command_file = os.path.join(".", os.path.basename(command))
|
||||||
|
command_env = os.environ.copy()
|
||||||
|
command_env["CERC_SO_COMPOSE_PROJECT"] = cluster_name
|
||||||
|
if ctx.debug:
|
||||||
|
command_env["CERC_SCRIPT_DEBUG"] = "true"
|
||||||
|
command_result = subprocess.run(command_file, shell=True, env=command_env, cwd=command_dir)
|
||||||
|
if command_result.returncode != 0:
|
||||||
|
print(f"FATAL Error running command: {command}")
|
||||||
|
sys.exit(1)
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
python-decouple>=3.6
|
python-decouple>=3.6
|
||||||
GitPython>=3.1.27
|
GitPython>=3.1.27
|
||||||
tqdm>=4.64.0
|
tqdm>=4.64.0
|
||||||
python-on-whales>=0.52.0
|
python-on-whales>=0.58.0
|
||||||
click>=8.1.3
|
click>=8.1.3
|
||||||
pyyaml>=6.0
|
pyyaml>=6.0
|
||||||
|
|||||||
Reference in New Issue
Block a user