forked from cerc-io/stack-orchestrator
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4356e09440 | ||
|
|
030ad25b78 | ||
|
|
c12418222a | ||
|
|
f57b8b4ba0 | ||
|
|
e29ae7ac93 | ||
|
|
edd7d549d9 | ||
|
|
4092a127ef | ||
|
|
fae8fbed5e | ||
|
|
a900945698 | ||
|
|
2937a07cd8 | ||
|
|
6ae3c252ea | ||
|
|
178de8f496 | ||
|
|
05cdd2ed01 | ||
|
|
e801c28f60 | ||
|
|
eb70f2526e | ||
|
|
199a4036a8 | ||
|
|
f0b711912a | ||
|
|
d3d3f92953 | ||
|
|
c3101bc25a | ||
|
|
6c49520e69 | ||
|
|
70d34e6751 | ||
|
|
c6de6d6067 | ||
|
|
69b6b9a873 | ||
|
|
430b884d72 | ||
|
|
5d456f5600 | ||
|
|
ca40ffb012 | ||
|
|
6a73d3adee | ||
|
|
9480b4082e | ||
|
|
467ff235ba | ||
|
|
25a755982e | ||
|
|
e3e96fa75e | ||
|
|
42696f8165 |
@@ -83,7 +83,10 @@ def command(ctx, include, exclude):
|
|||||||
container_build_env = {
|
container_build_env = {
|
||||||
"CERC_NPM_URL": "http://gitea.local:3000/api/packages/cerc-io/npm/",
|
"CERC_NPM_URL": "http://gitea.local:3000/api/packages/cerc-io/npm/",
|
||||||
"CERC_NPM_AUTH_TOKEN": config("CERC_NPM_AUTH_TOKEN", default="<token-not-supplied>"),
|
"CERC_NPM_AUTH_TOKEN": config("CERC_NPM_AUTH_TOKEN", default="<token-not-supplied>"),
|
||||||
"CERC_REPO_BASE_DIR": dev_root_path
|
"CERC_REPO_BASE_DIR": dev_root_path,
|
||||||
|
"CERC_HOST_UID": f"{os.getuid()}",
|
||||||
|
"CERC_HOST_GID": f"{os.getgid()}",
|
||||||
|
"DOCKER_BUILDKIT": "0"
|
||||||
}
|
}
|
||||||
|
|
||||||
def process_container(container):
|
def process_container(container):
|
||||||
@@ -106,7 +109,7 @@ def command(ctx, include, exclude):
|
|||||||
build_command = os.path.join(container_build_dir, "default-build.sh") + f" {container}:local {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} with environment: {container_build_env}")
|
||||||
build_result = subprocess.run(build_command, shell=True, env=container_build_env)
|
build_result = subprocess.run(build_command, shell=True, env=container_build_env)
|
||||||
if verbose:
|
if verbose:
|
||||||
print(f"Return code is: {build_result.returncode}")
|
print(f"Return code is: {build_result.returncode}")
|
||||||
|
|||||||
+5
-1
@@ -116,7 +116,11 @@ def command(ctx, include, exclude):
|
|||||||
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": npm_registry_url_token} | ({"CERC_SCRIPT_DEBUG": "true"} if debug else {})
|
# Originally we used the PEP 584 merge operator:
|
||||||
|
# envs = {"CERC_NPM_AUTH_TOKEN": npm_registry_url_token} | ({"CERC_SCRIPT_DEBUG": "true"} if debug else {})
|
||||||
|
# but that isn't available in Python 3.8 (default in Ubuntu 20) so for now we use dict.update:
|
||||||
|
envs = {"CERC_NPM_AUTH_TOKEN": npm_registry_url_token}
|
||||||
|
envs.update({"CERC_SCRIPT_DEBUG": "true"} if debug else {})
|
||||||
try:
|
try:
|
||||||
docker.run(builder_js_image_name,
|
docker.run(builder_js_image_name,
|
||||||
remove=True,
|
remove=True,
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ services:
|
|||||||
image: cerc/laconicd:local
|
image: cerc/laconicd:local
|
||||||
command: ["sh", "/docker-entrypoint-scripts.d/create-fixturenet.sh"]
|
command: ["sh", "/docker-entrypoint-scripts.d/create-fixturenet.sh"]
|
||||||
volumes:
|
volumes:
|
||||||
# TODO: look at folding this script into the container
|
# TODO: look at folding these scripts into the container
|
||||||
- ../config/fixturenet-laconicd/create-fixturenet.sh:/docker-entrypoint-scripts.d/create-fixturenet.sh
|
- ../config/fixturenet-laconicd/create-fixturenet.sh:/docker-entrypoint-scripts.d/create-fixturenet.sh
|
||||||
|
- ../config/fixturenet-laconicd/export-mykey.sh:/docker-entrypoint-scripts.d/export-mykey.sh
|
||||||
# TODO: determine which of the ports below is really needed
|
# TODO: determine which of the ports below is really needed
|
||||||
ports:
|
ports:
|
||||||
- "6060"
|
- "6060"
|
||||||
@@ -18,4 +19,7 @@ services:
|
|||||||
- "9090"
|
- "9090"
|
||||||
- "9091"
|
- "9091"
|
||||||
- "1317"
|
- "1317"
|
||||||
|
cli:
|
||||||
|
image: cerc/laconic-registry-cli:local
|
||||||
|
volumes:
|
||||||
|
- ../config/fixturenet-laconicd/registry-cli-config-template.yml:/registry-cli-config-template.yml
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# Add-on pod to include foundry tooling within a fixturenet
|
||||||
|
services:
|
||||||
|
foundry:
|
||||||
|
image: ghcr.io/foundry-rs/foundry:latest
|
||||||
|
command: ["while :; do sleep 600; done"]
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
echo y | laconicd keys export mykey --unarmored-hex --unsafe
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
cns:
|
||||||
|
restEndpoint: 'http://laconicd:1317'
|
||||||
|
gqlEndpoint: 'http://laconicd:9473/api'
|
||||||
|
userKey: REPLACE_WITH_MYKEY
|
||||||
|
bondId:
|
||||||
|
chainId: laconic_9000-1
|
||||||
@@ -1,14 +1,30 @@
|
|||||||
# Originally from: https://github.com/devcontainers/images/blob/main/src/javascript-node/.devcontainer/Dockerfile
|
# Originally from: https://github.com/devcontainers/images/blob/main/src/javascript-node/.devcontainer/Dockerfile
|
||||||
|
# Which depends on: https://github.com/nodejs/docker-node/blob/main/Dockerfile-debian.template
|
||||||
# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 18, 16, 14, 18-bullseye, 16-bullseye, 14-bullseye, 18-buster, 16-buster, 14-buster
|
# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 18, 16, 14, 18-bullseye, 16-bullseye, 14-bullseye, 18-buster, 16-buster, 14-buster
|
||||||
ARG VARIANT=16-bullseye
|
ARG VARIANT=16-bullseye
|
||||||
FROM node:${VARIANT}
|
FROM node:${VARIANT}
|
||||||
|
|
||||||
|
# Set these args to change the uid/gid for the base container's "node" user to match that of the host user (so bind mounts work as expected).
|
||||||
|
ARG CERC_HOST_UID=1000
|
||||||
|
ARG CERC_HOST_GID=1000
|
||||||
|
# Make these values available at runtime to allow a consistency check.
|
||||||
|
ENV HOST_UID=${CERC_HOST_UID}
|
||||||
|
ENV HOST_GID=${CERC_HOST_GID}
|
||||||
|
|
||||||
ARG USERNAME=node
|
ARG USERNAME=node
|
||||||
ARG NPM_GLOBAL=/usr/local/share/npm-global
|
ARG NPM_GLOBAL=/usr/local/share/npm-global
|
||||||
|
|
||||||
# Add NPM global to PATH.
|
# Add NPM global to PATH.
|
||||||
ENV PATH=${NPM_GLOBAL}/bin:${PATH}
|
ENV PATH=${NPM_GLOBAL}/bin:${PATH}
|
||||||
|
|
||||||
|
RUN \
|
||||||
|
if [ ${CERC_HOST_GID} -ne 1000 ] ; then \
|
||||||
|
groupmod -g ${CERC_HOST_GID} ${USERNAME} ; \
|
||||||
|
fi \
|
||||||
|
&& if [ ${CERC_HOST_UID} -ne 1000 ] ; then \
|
||||||
|
usermod -u ${CERC_HOST_UID} -g ${CERC_HOST_GID} ${USERNAME} && chown ${CERC_HOST_UID}:${CERC_HOST_GID} /home/${USERNAME} ; \
|
||||||
|
fi
|
||||||
|
|
||||||
RUN \
|
RUN \
|
||||||
# Configure global npm install location, use group to adapt to UID/GID changes
|
# Configure global npm install location, use group to adapt to UID/GID changes
|
||||||
if ! cat /etc/group | grep -e "^npm:" > /dev/null 2>&1; then groupadd -r npm; fi \
|
if ! cat /etc/group | grep -e "^npm:" > /dev/null 2>&1; then groupadd -r npm; fi \
|
||||||
@@ -39,6 +55,7 @@ RUN mkdir /scripts
|
|||||||
COPY build-npm-package.sh /scripts
|
COPY build-npm-package.sh /scripts
|
||||||
COPY yarn-local-registry-fixup.sh /scripts
|
COPY yarn-local-registry-fixup.sh /scripts
|
||||||
COPY build-npm-package-local-dependencies.sh /scripts
|
COPY build-npm-package-local-dependencies.sh /scripts
|
||||||
|
COPY check-uid.sh /scripts
|
||||||
ENV PATH="${PATH}:/scripts"
|
ENV PATH="${PATH}:/scripts"
|
||||||
|
|
||||||
COPY entrypoint.sh .
|
COPY entrypoint.sh .
|
||||||
|
|||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Make the container usable for uid/gid != 1000
|
||||||
|
if [[ -n "$CERC_SCRIPT_DEBUG" ]]; then
|
||||||
|
set -x
|
||||||
|
fi
|
||||||
|
current_uid=$(id -u)
|
||||||
|
current_gid=$(id -g)
|
||||||
|
# Don't check if running as root
|
||||||
|
if [[ ${current_uid} == 0 ]]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
# Check the current uid/gid vs the uid/gid used to build the container.
|
||||||
|
# We do this because both bind mounts and npm tooling require the uid/gid to match.
|
||||||
|
if [[ ${current_gid} != ${HOST_GID} ]]; then
|
||||||
|
echo "Warning: running with gid: ${current_gid} which is not the gid for which this container was built (${HOST_GID})"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
if [[ ${current_uid} != ${HOST_UID} ]]; then
|
||||||
|
echo "Warning: running with gid: ${current_uid} which is not the uid for which this container was built (${HOST_UID})"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
/scripts/check-uid.sh
|
||||||
exec "$@"
|
exec "$@"
|
||||||
|
|||||||
@@ -48,10 +48,13 @@ RUN npm config set @lirewine:registry ${CERC_NPM_URL} \
|
|||||||
# TODO: the image at this point could be made a base image for several different CLI images
|
# TODO: the image at this point could be made a base image for several different CLI images
|
||||||
# that install different Node-based CLI commands
|
# that install different Node-based CLI commands
|
||||||
|
|
||||||
# DEBUG, remove
|
|
||||||
RUN yarn info @cerc-io/laconic-registry-cli
|
|
||||||
|
|
||||||
# Globally install the cli package
|
# Globally install the cli package
|
||||||
RUN yarn global add @cerc-io/laconic-registry-cli
|
RUN yarn global add @cerc-io/laconic-registry-cli
|
||||||
|
|
||||||
ENTRYPOINT ["laconic"]
|
# Add scripts
|
||||||
|
RUN mkdir /scripts
|
||||||
|
ENV PATH="${PATH}:/scripts"
|
||||||
|
COPY ./import-key.sh /scripts
|
||||||
|
|
||||||
|
# Default command sleeps forever so docker doesn't kill it
|
||||||
|
CMD ["sh", "-c", "while :; do sleep 600; done"]
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
sed 's/REPLACE_WITH_MYKEY/'${1}'/' registry-cli-config-template.yml > config.yml
|
||||||
@@ -11,4 +11,4 @@ fi
|
|||||||
image_tag=$1
|
image_tag=$1
|
||||||
build_dir=$2
|
build_dir=$2
|
||||||
echo "Building ${image_tag} in ${build_dir}"
|
echo "Building ${image_tag} in ${build_dir}"
|
||||||
docker build -t ${image_tag} ${build_dir}
|
docker build -t ${image_tag} --build-arg CERC_HOST_UID=${CERC_HOST_UID} --build-arg CERC_HOST_GID=${CERC_HOST_GID} ${build_dir}
|
||||||
|
|||||||
@@ -19,3 +19,4 @@ eth-probe
|
|||||||
keycloak
|
keycloak
|
||||||
tx-spammer
|
tx-spammer
|
||||||
kubo
|
kubo
|
||||||
|
foundry
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
# Build Support Stack
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
|
||||||
|
JS/TS/NPM builds need an npm registry to store intermediate package artifacts.
|
||||||
|
This can be supplied by the user (e.g. using a hosted registry or even npmjs.com), or a local registry using gitea can be deployed by stack orchestrator.
|
||||||
|
To use a user-supplied registry set these environment variables:
|
||||||
|
|
||||||
|
`CERC_NPM_REGISTRY_URL` and
|
||||||
|
`CERC_NPM_AUTH_TOKEN`
|
||||||
|
|
||||||
|
Leave `CERC_NPM_REGISTRY_URL` un-set to use the local gitea registry.
|
||||||
|
|
||||||
|
### 1. Build support containers
|
||||||
|
```
|
||||||
|
$ laconic-so --stack build-support build-containers
|
||||||
|
```
|
||||||
|
Note that the scheme/gerbil builder container can take a while to build so if you aren't going to build scheme projects it can be skipped with:
|
||||||
|
```
|
||||||
|
$ laconic-so --stack build-support build-containers --exclude cerc/builder-gerbil
|
||||||
|
```
|
||||||
|
### 2. Deploy Gitea Package Registry
|
||||||
|
|
||||||
|
```
|
||||||
|
$ laconic-so --stack package-registry setup-repositories
|
||||||
|
$ laconic-so --stack package-registry deploy up
|
||||||
|
This is your gitea access token: 84fe66a73698bf11edbdccd0a338236b7d1d5c45. Keep it safe and secure, it can not be fetched again from gitea.
|
||||||
|
```
|
||||||
|
Now npm packages can be built:
|
||||||
|
### Build npm Packages
|
||||||
|
Ensure that `CERC_NPM_AUTH_TOKEN` is set with the token printed above when the package-registry stack was deployed (the actual token value will be different than shown in this example):
|
||||||
|
```
|
||||||
|
$ export CERC_NPM_AUTH_TOKEN=84fe66a73698bf11edbdccd0a338236b7d1d5c45
|
||||||
|
$ laconic-so build-npms --include laconic-sdk
|
||||||
|
```
|
||||||
|
|||||||
@@ -11,3 +11,4 @@ containers:
|
|||||||
- cerc/fixturenet-eth-lighthouse
|
- cerc/fixturenet-eth-lighthouse
|
||||||
pods:
|
pods:
|
||||||
- fixturenet-eth
|
- fixturenet-eth
|
||||||
|
- foundry
|
||||||
|
|||||||
@@ -1,18 +1,50 @@
|
|||||||
# Laconicd Fixturenet
|
# Laconicd Fixturenet
|
||||||
|
|
||||||
Instructions for deploying a local Laconic blockchain "fixturenet" for development and testing purposes using laconic-stack-orchestrator (the installation of which is covered [here](https://github.com/cerc-io/stack-orchestrator#user-mode)):
|
Instructions for deploying a local Laconic blockchain "fixturenet" for development and testing purposes using laconic-stack-orchestrator.
|
||||||
|
|
||||||
## Clone required repositories
|
## 1. Install Laconic Stack Orchestrator
|
||||||
|
Installation is covered in detail [here](https://github.com/cerc-io/stack-orchestrator#user-mode) but if you're on Linux and already have docker installed it should be as simple as:
|
||||||
```
|
```
|
||||||
$ laconic-so setup-repositories --include cerc-io/laconicd,cerc-io/laconic-sdk,cerc-io/laconic-registry-cli
|
$ mkdir my-working-dir
|
||||||
|
$ cd my-working-dir
|
||||||
|
$ curl -L -o ./laconic-so https://github.com/cerc-io/stack-orchestrator/releases/latest/download/laconic-so
|
||||||
|
$ chmod +x ./laconic-so
|
||||||
|
$ export PATH=$PATH:$(pwd) # Or move laconic-so to ~/bin or your favorite on-path directory
|
||||||
```
|
```
|
||||||
## Build the laconicd container
|
## 2. Prepare the local build environment
|
||||||
|
Note that this step needs only to be done once on a new machine.
|
||||||
|
Detailed instructions can be found [here](../build-support/README.md). For the impatient run these commands:
|
||||||
```
|
```
|
||||||
$ laconic-so build-containers --include cerc/laconicd
|
$ laconic-so --stack build-support build-containers --exclude cerc/builder-gerbil
|
||||||
|
$ laconic-so --stack package-registry setup-repositories
|
||||||
|
$ laconic-so --stack package-registry deploy-system up
|
||||||
```
|
```
|
||||||
This should create a container with tag `cerc/laconicd` in the local image registry.
|
Then add the localhost alias `gitea.local` and set `CERC_NPM_AUTH_TOKEN` to the token printed when the package-registry stack was deployed above:
|
||||||
## Deploy the stack
|
|
||||||
```
|
```
|
||||||
$ laconic-so deploy-system --include fixturenet-laconicd up
|
$ sudo vi /etc/hosts
|
||||||
|
$ export CERC_NPM_AUTH_TOKEN=<my-token>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 3. Clone required repositories
|
||||||
|
```
|
||||||
|
$ laconic-so --stack fixturenet-laconicd setup-repositories
|
||||||
|
```
|
||||||
|
## 4. Build the stack's packages and containers
|
||||||
|
```
|
||||||
|
$ laconic-so --stack fixturenet-laconicd build-npms
|
||||||
|
$ laconic-so --stack fixturenet-laconicd build-containers
|
||||||
|
```
|
||||||
|
## 5. Deploy the stack
|
||||||
|
```
|
||||||
|
$ laconic-so --stack fixturenet-laconicd deploy up
|
||||||
|
```
|
||||||
|
Correct operation should be verified by checking the laconicd container's logs with:
|
||||||
|
```
|
||||||
|
$ laconic-so --stack fixturenet-laconicd deploy logs
|
||||||
|
```
|
||||||
|
## 6. Test with the Registry CLI
|
||||||
|
```
|
||||||
|
$ laconic-so --stack fixturenet-laconicd deploy exec laconicd "sh /docker-entrypoint-scripts.d/export-mykey.sh"
|
||||||
|
$ laconic-so --stack fixturenet-laconicd deploy exec cli "sh /scripts/import-key.sh xxxxxxxxxxxxxxxxxxxxxxx"
|
||||||
|
$ laconic-so --stack fixturenet-laconicd deploy exec cli "laconic cns status"
|
||||||
```
|
```
|
||||||
Correct operation should be verified by checking the laconicd container's log.
|
|
||||||
|
|||||||
@@ -13,3 +13,6 @@ containers:
|
|||||||
- cerc/laconic-registry-cli
|
- cerc/laconic-registry-cli
|
||||||
pods:
|
pods:
|
||||||
- fixturenet-laconicd
|
- fixturenet-laconicd
|
||||||
|
config:
|
||||||
|
cli:
|
||||||
|
key: laconicd.mykey
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# Package Registry Stack
|
||||||
|
|
||||||
|
The Package Registry Stack supports a build environment that requires a package registry (initially for NPM packages only).
|
||||||
|
|
||||||
|
Setup instructions can be found [here](../build-support/README.md).
|
||||||
@@ -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.20-6c1bedc
|
v1.0.25-75376d7
|
||||||
|
|||||||
+73
-12
@@ -19,6 +19,7 @@ import hashlib
|
|||||||
import copy
|
import copy
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from dataclasses import dataclass
|
||||||
from decouple import config
|
from decouple import config
|
||||||
import subprocess
|
import subprocess
|
||||||
from python_on_whales import DockerClient
|
from python_on_whales import DockerClient
|
||||||
@@ -56,15 +57,19 @@ def command(ctx, include, exclude, cluster, command, extra_args):
|
|||||||
|
|
||||||
if not dry_run:
|
if not dry_run:
|
||||||
if command == "up":
|
if command == "up":
|
||||||
if debug:
|
container_exec_env = _make_runtime_env(ctx.obj)
|
||||||
os.environ["CERC_SCRIPT_DEBUG"] = "true"
|
for attr, value in container_exec_env.items():
|
||||||
|
os.environ[attr] = value
|
||||||
if verbose:
|
if verbose:
|
||||||
print(f"Running compose up for extra_args: {extra_args_list}")
|
print(f"Running compose up with container_exec_env: {container_exec_env}, extra_args: {extra_args_list}")
|
||||||
for pre_start_command in cluster_context.pre_start_commands:
|
for pre_start_command in cluster_context.pre_start_commands:
|
||||||
_run_command(ctx.obj, cluster_context.cluster, pre_start_command)
|
_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:
|
for post_start_command in cluster_context.post_start_commands:
|
||||||
_run_command(ctx.obj, cluster_context.cluster, post_start_command)
|
_run_command(ctx.obj, cluster_context.cluster, post_start_command)
|
||||||
|
|
||||||
|
_orchestrate_cluster_config(ctx.obj, cluster_context.config, docker, container_exec_env)
|
||||||
|
|
||||||
elif command == "down":
|
elif command == "down":
|
||||||
if verbose:
|
if verbose:
|
||||||
print("Running compose down")
|
print("Running compose down")
|
||||||
@@ -74,10 +79,8 @@ def command(ctx, include, exclude, cluster, command, extra_args):
|
|||||||
print("Usage: exec <service> <cmd>")
|
print("Usage: exec <service> <cmd>")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
service_name = extra_args_list[0]
|
service_name = extra_args_list[0]
|
||||||
command_to_exec = extra_args_list[1:]
|
command_to_exec = ["sh", "-c"] + extra_args_list[1:]
|
||||||
container_exec_env = {
|
container_exec_env = _make_runtime_env(ctx.obj)
|
||||||
"CERC_SCRIPT_DEBUG": "true"
|
|
||||||
} if debug else {}
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print(f"Running compose exec {service_name} {command_to_exec}")
|
print(f"Running compose exec {service_name} {command_to_exec}")
|
||||||
docker.compose.execute(service_name, command_to_exec, envs=container_exec_env)
|
docker.compose.execute(service_name, command_to_exec, envs=container_exec_env)
|
||||||
@@ -115,7 +118,8 @@ def command(ctx, include, exclude, cluster, command, extra_args):
|
|||||||
elif command == "logs":
|
elif command == "logs":
|
||||||
if verbose:
|
if verbose:
|
||||||
print("Running compose logs")
|
print("Running compose logs")
|
||||||
docker.compose.logs()
|
logs_output = docker.compose.logs(services=extra_args_list if extra_args_list is not None else [])
|
||||||
|
print(logs_output)
|
||||||
|
|
||||||
|
|
||||||
def get_stack_status(ctx, stack):
|
def get_stack_status(ctx, stack):
|
||||||
@@ -139,6 +143,15 @@ def get_stack_status(ctx, stack):
|
|||||||
False
|
False
|
||||||
|
|
||||||
|
|
||||||
|
def _make_runtime_env(ctx):
|
||||||
|
container_exec_env = {
|
||||||
|
"CERC_HOST_UID": f"{os.getuid()}",
|
||||||
|
"CERC_HOST_GID": f"{os.getgid()}"
|
||||||
|
}
|
||||||
|
container_exec_env.update({"CERC_SCRIPT_DEBUG": "true"} if ctx.debug else {})
|
||||||
|
return container_exec_env
|
||||||
|
|
||||||
|
|
||||||
def _make_cluster_context(ctx, include, exclude, cluster):
|
def _make_cluster_context(ctx, include, exclude, cluster):
|
||||||
|
|
||||||
if ctx.local_stack:
|
if ctx.local_stack:
|
||||||
@@ -151,10 +164,13 @@ def _make_cluster_context(ctx, include, exclude, cluster):
|
|||||||
compose_dir = Path(__file__).absolute().parent.joinpath("data", "compose")
|
compose_dir = Path(__file__).absolute().parent.joinpath("data", "compose")
|
||||||
|
|
||||||
if cluster is None:
|
if cluster is None:
|
||||||
# Create default unique, stable cluster name from confile file path
|
# Create default unique, stable cluster name from confile file path and stack name if provided
|
||||||
# TODO: change this to the config file path
|
# TODO: change this to the config file path
|
||||||
path = os.path.realpath(sys.argv[0])
|
path = os.path.realpath(sys.argv[0])
|
||||||
hash = hashlib.md5(path.encode()).hexdigest()
|
unique_cluster_descriptor = f"{path},{ctx.stack},{include},{exclude}"
|
||||||
|
if ctx.debug:
|
||||||
|
print(f"pre-hash descriptor: {unique_cluster_descriptor}")
|
||||||
|
hash = hashlib.md5(unique_cluster_descriptor.encode()).hexdigest()
|
||||||
cluster = f"laconic-{hash}"
|
cluster = f"laconic-{hash}"
|
||||||
if ctx.verbose:
|
if ctx.verbose:
|
||||||
print(f"Using cluster name: {cluster}")
|
print(f"Using cluster name: {cluster}")
|
||||||
@@ -169,8 +185,10 @@ def _make_cluster_context(ctx, include, exclude, cluster):
|
|||||||
stack_config = get_parsed_stack_config(ctx.stack)
|
stack_config = get_parsed_stack_config(ctx.stack)
|
||||||
# TODO: syntax check the input here
|
# TODO: syntax check the input here
|
||||||
pods_in_scope = stack_config['pods']
|
pods_in_scope = stack_config['pods']
|
||||||
|
cluster_config = stack_config['config'] if 'config' in stack_config else None
|
||||||
else:
|
else:
|
||||||
pods_in_scope = all_pods
|
pods_in_scope = all_pods
|
||||||
|
cluster_config = None
|
||||||
|
|
||||||
# Convert all pod definitions to v1.1 format
|
# Convert all pod definitions to v1.1 format
|
||||||
pods_in_scope = _convert_to_new_format(pods_in_scope)
|
pods_in_scope = _convert_to_new_format(pods_in_scope)
|
||||||
@@ -207,15 +225,16 @@ def _make_cluster_context(ctx, include, exclude, cluster):
|
|||||||
if ctx.verbose:
|
if ctx.verbose:
|
||||||
print(f"files: {compose_files}")
|
print(f"files: {compose_files}")
|
||||||
|
|
||||||
return cluster_context(cluster, compose_files, pre_start_commands, post_start_commands)
|
return cluster_context(cluster, compose_files, pre_start_commands, post_start_commands, cluster_config)
|
||||||
|
|
||||||
|
|
||||||
class cluster_context:
|
class cluster_context:
|
||||||
def __init__(self, cluster, compose_files, pre_start_commands, post_start_commands) -> None:
|
def __init__(self, cluster, compose_files, pre_start_commands, post_start_commands, config) -> None:
|
||||||
self.cluster = cluster
|
self.cluster = cluster
|
||||||
self.compose_files = compose_files
|
self.compose_files = compose_files
|
||||||
self.pre_start_commands = pre_start_commands
|
self.pre_start_commands = pre_start_commands
|
||||||
self.post_start_commands = post_start_commands
|
self.post_start_commands = post_start_commands
|
||||||
|
self.config = config
|
||||||
|
|
||||||
|
|
||||||
def _convert_to_new_format(old_pod_array):
|
def _convert_to_new_format(old_pod_array):
|
||||||
@@ -246,3 +265,45 @@ def _run_command(ctx, cluster_name, command):
|
|||||||
if command_result.returncode != 0:
|
if command_result.returncode != 0:
|
||||||
print(f"FATAL Error running command: {command}")
|
print(f"FATAL Error running command: {command}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def _orchestrate_cluster_config(ctx, cluster_config, docker, container_exec_env):
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class ConfigDirective:
|
||||||
|
source_container: str
|
||||||
|
source_variable: str
|
||||||
|
destination_container: str
|
||||||
|
destination_variable: str
|
||||||
|
|
||||||
|
if cluster_config is not None:
|
||||||
|
for container in cluster_config:
|
||||||
|
container_config = cluster_config[container]
|
||||||
|
if ctx.verbose:
|
||||||
|
print(f"{container} config: {container_config}")
|
||||||
|
for directive in container_config:
|
||||||
|
pd = ConfigDirective(
|
||||||
|
container_config[directive].split(".")[0],
|
||||||
|
container_config[directive].split(".")[1],
|
||||||
|
container,
|
||||||
|
directive
|
||||||
|
)
|
||||||
|
if ctx.verbose:
|
||||||
|
print(f"Setting {pd.destination_container}.{pd.destination_variable} = {pd.source_container}.{pd.source_variable}")
|
||||||
|
# TODO: fix the script paths so they're consistent between containers
|
||||||
|
source_value = docker.compose.execute(pd.source_container,
|
||||||
|
["sh", "-c",
|
||||||
|
f"sh /docker-entrypoint-scripts.d/export-{pd.source_variable}.sh"],
|
||||||
|
tty=False,
|
||||||
|
envs=container_exec_env)
|
||||||
|
# TODO: handle the case that the value is not yet available
|
||||||
|
if ctx.debug:
|
||||||
|
print(f"fetched source value: {source_value}")
|
||||||
|
destination_output = docker.compose.execute(pd.destination_container,
|
||||||
|
["sh", "-c",
|
||||||
|
f"sh /scripts/import-{pd.destination_variable}.sh {pd.source_variable}"],
|
||||||
|
tty=False,
|
||||||
|
envs=container_exec_env)
|
||||||
|
if ctx.debug:
|
||||||
|
print(f"destination output: {destination_output}")
|
||||||
|
# TODO: detect errors here
|
||||||
|
|||||||
@@ -55,5 +55,6 @@ def cli(ctx, stack, quiet, verbose, dry_run, local_stack, debug, continue_on_err
|
|||||||
cli.add_command(setup_repositories.command, "setup-repositories")
|
cli.add_command(setup_repositories.command, "setup-repositories")
|
||||||
cli.add_command(build_containers.command, "build-containers")
|
cli.add_command(build_containers.command, "build-containers")
|
||||||
cli.add_command(build_npms.command, "build-npms")
|
cli.add_command(build_npms.command, "build-npms")
|
||||||
|
cli.add_command(deploy_system.command, "deploy") # deploy is an alias for deploy-system
|
||||||
cli.add_command(deploy_system.command, "deploy-system")
|
cli.add_command(deploy_system.command, "deploy-system")
|
||||||
cli.add_command(version.command, "version")
|
cli.add_command(version.command, "version")
|
||||||
|
|||||||
@@ -24,4 +24,11 @@ $TEST_TARGET_SO --stack test deploy-system up
|
|||||||
# TODO: test that we can use the deployed container somehow
|
# TODO: test that we can use the deployed container somehow
|
||||||
# Clean up
|
# Clean up
|
||||||
$TEST_TARGET_SO --stack test deploy-system down
|
$TEST_TARGET_SO --stack test deploy-system down
|
||||||
|
# Run same test but not using the stack definition
|
||||||
|
# Test building the a stack container
|
||||||
|
$TEST_TARGET_SO build-containers --include cerc/test-container
|
||||||
|
# Deploy the test container
|
||||||
|
$TEST_TARGET_SO deploy-system --include test up
|
||||||
|
# Clean up
|
||||||
|
$TEST_TARGET_SO deploy-system --include test down
|
||||||
echo "Test passed"
|
echo "Test passed"
|
||||||
|
|||||||
Reference in New Issue
Block a user