From 643e41d91e95d728ffa051ebb73021d9bc210cb7 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Tue, 6 Feb 2024 13:48:38 -0700 Subject: [PATCH] Test database stack --- .../compose/docker-compose-test-database.yml | 16 ++++++++++++++++ .../cerc-test-database-container/Dockerfile | 3 +++ .../cerc-test-database-container/build.sh | 5 +++++ .../data/stacks/test-database/README.md | 3 +++ .../data/stacks/test-database/stack.yml | 8 ++++++++ stack_orchestrator/repos/setup_repositories.py | 6 +++--- stack_orchestrator/util.py | 5 +++++ 7 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 stack_orchestrator/data/compose/docker-compose-test-database.yml create mode 100644 stack_orchestrator/data/container-build/cerc-test-database-container/Dockerfile create mode 100755 stack_orchestrator/data/container-build/cerc-test-database-container/build.sh create mode 100644 stack_orchestrator/data/stacks/test-database/README.md create mode 100644 stack_orchestrator/data/stacks/test-database/stack.yml diff --git a/stack_orchestrator/data/compose/docker-compose-test-database.yml b/stack_orchestrator/data/compose/docker-compose-test-database.yml new file mode 100644 index 00000000..7de4712b --- /dev/null +++ b/stack_orchestrator/data/compose/docker-compose-test-database.yml @@ -0,0 +1,16 @@ +services: + database: + image: cerc/test-database-container:local + restart: always + volumes: + - db-data:/var/lib/postgresql/data + environment: + POSTGRES_USER: "test-user" + POSTGRES_DB: "test-db" + POSTGRES_PASSWORD: "password" + POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C" + ports: + - "5432" + +volumes: + db-data: diff --git a/stack_orchestrator/data/container-build/cerc-test-database-container/Dockerfile b/stack_orchestrator/data/container-build/cerc-test-database-container/Dockerfile new file mode 100644 index 00000000..aae60175 --- /dev/null +++ b/stack_orchestrator/data/container-build/cerc-test-database-container/Dockerfile @@ -0,0 +1,3 @@ +FROM postgres:16-bullseye + +EXPOSE 5432 diff --git a/stack_orchestrator/data/container-build/cerc-test-database-container/build.sh b/stack_orchestrator/data/container-build/cerc-test-database-container/build.sh new file mode 100755 index 00000000..a4515229 --- /dev/null +++ b/stack_orchestrator/data/container-build/cerc-test-database-container/build.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +# Build cerc/test-container +source ${CERC_CONTAINER_BASE_DIR}/build-base.sh +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +docker build -t cerc/test-database-container:local -f ${SCRIPT_DIR}/Dockerfile ${build_command_args} $SCRIPT_DIR diff --git a/stack_orchestrator/data/stacks/test-database/README.md b/stack_orchestrator/data/stacks/test-database/README.md new file mode 100644 index 00000000..1dcdcc7b --- /dev/null +++ b/stack_orchestrator/data/stacks/test-database/README.md @@ -0,0 +1,3 @@ +# Test Database Stack + +A stack with a database for test/demo purposes. \ No newline at end of file diff --git a/stack_orchestrator/data/stacks/test-database/stack.yml b/stack_orchestrator/data/stacks/test-database/stack.yml new file mode 100644 index 00000000..6fac54e0 --- /dev/null +++ b/stack_orchestrator/data/stacks/test-database/stack.yml @@ -0,0 +1,8 @@ +version: "1.0" +name: test +description: "A test database stack" +repos: +containers: + - cerc/test-database-container +pods: + - test-database diff --git a/stack_orchestrator/repos/setup_repositories.py b/stack_orchestrator/repos/setup_repositories.py index 3612aed0..a137d645 100644 --- a/stack_orchestrator/repos/setup_repositories.py +++ b/stack_orchestrator/repos/setup_repositories.py @@ -26,7 +26,7 @@ import importlib.resources from pathlib import Path import yaml from stack_orchestrator.constants import stack_file_name -from stack_orchestrator.util import include_exclude_check, stack_is_external, error_exit +from stack_orchestrator.util import include_exclude_check, stack_is_external, error_exit, warn_exit class GitProgress(git.RemoteProgress): @@ -249,8 +249,8 @@ def command(ctx, include, exclude, git_ssh, check_only, pull, branches, branches error_exit(f"stack {stack} does not exist") with stack_file_path: stack_config = yaml.safe_load(open(stack_file_path, "r")) - if "repos" not in stack_config: - error_exit(f"stack {stack} does not define any repositories") + if "repos" not in stack_config or stack_config["repos"] is None: + warn_exit(f"stack {stack} does not define any repositories") else: repos_in_scope = stack_config["repos"] else: diff --git a/stack_orchestrator/util.py b/stack_orchestrator/util.py index 36c6bfd0..257e1deb 100644 --- a/stack_orchestrator/util.py +++ b/stack_orchestrator/util.py @@ -189,5 +189,10 @@ def error_exit(s): sys.exit(1) +def warn_exit(s): + print(f"WARN: {s}") + sys.exit(0) + + def env_var_map_from_file(file: Path) -> Mapping[str, str]: return dotenv_values(file)