From 88b0c0b5bf5d1e12e129ea3728f9469594805114 Mon Sep 17 00:00:00 2001 From: Manuel Debic Date: Mon, 18 Nov 2024 14:43:04 +0000 Subject: [PATCH 1/2] Add option to set prefix for compose project and container names --- adit_radis_shared/invoke_tasks.py | 11 +++++++++-- example.env | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/adit_radis_shared/invoke_tasks.py b/adit_radis_shared/invoke_tasks.py index a969b4a..74de987 100644 --- a/adit_radis_shared/invoke_tasks.py +++ b/adit_radis_shared/invoke_tasks.py @@ -49,6 +49,13 @@ def get_project_dir(): assert PROJECT_DIR is not None return PROJECT_DIR + @staticmethod + def get_compose_project_name(): + config = Utility.load_config_from_env_file() + if config.get("COMPOSE_PROJECT_NAME") is not None: + return + return Utility.get_project_name() + @staticmethod def load_config_from_env_file() -> dict[str, str | None]: env_file = Utility.get_project_dir() / ".env" @@ -87,8 +94,8 @@ def get_compose_env_file(): @staticmethod def get_stack_name(): if Utility.is_production(): - return f"{Utility.get_project_name()}_prod" - return f"{Utility.get_project_name()}_dev" + return f"{Utility.get_compose_project_name()}_prod" + return f"{Utility.get_compose_project_name()}_dev" @staticmethod def build_compose_cmd(profiles: list[str] = []): diff --git a/example.env b/example.env index c5745b8..de4defc 100644 --- a/example.env +++ b/example.env @@ -74,3 +74,6 @@ SSL_CHAIN_FILE="./chain.pem" # The timezone that the web interface uses. USER_TIME_ZONE="Europe/Berlin" + +# Optional prefix for compose project and docker container, defaults to adit +# COMPOSE_PROJECT_NAME="your_project_name" From 8ad08d9358a9c542fbc03932eceaf86d9f8ff435 Mon Sep 17 00:00:00 2001 From: Kai Schlamp Date: Mon, 18 Nov 2024 16:02:19 +0000 Subject: [PATCH 2/2] Improve setting stack name by using env var --- adit_radis_shared/invoke_tasks.py | 17 +++++++---------- example.env | 6 ++++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/adit_radis_shared/invoke_tasks.py b/adit_radis_shared/invoke_tasks.py index 74de987..6c42f92 100644 --- a/adit_radis_shared/invoke_tasks.py +++ b/adit_radis_shared/invoke_tasks.py @@ -49,13 +49,6 @@ def get_project_dir(): assert PROJECT_DIR is not None return PROJECT_DIR - @staticmethod - def get_compose_project_name(): - config = Utility.load_config_from_env_file() - if config.get("COMPOSE_PROJECT_NAME") is not None: - return - return Utility.get_project_name() - @staticmethod def load_config_from_env_file() -> dict[str, str | None]: env_file = Utility.get_project_dir() / ".env" @@ -92,10 +85,14 @@ def get_compose_env_file(): return Utility.get_project_dir() / "docker-compose.dev.yml" @staticmethod - def get_stack_name(): + def get_stack_name() -> str: + config = Utility.load_config_from_env_file() + if stack_name := config.get("STACK_NAME", ""): + return stack_name + if Utility.is_production(): - return f"{Utility.get_compose_project_name()}_prod" - return f"{Utility.get_compose_project_name()}_dev" + return f"{Utility.get_project_name()}_prod" + return f"{Utility.get_project_name()}_dev" @staticmethod def build_compose_cmd(profiles: list[str] = []): diff --git a/example.env b/example.env index de4defc..321717b 100644 --- a/example.env +++ b/example.env @@ -75,5 +75,7 @@ SSL_CHAIN_FILE="./chain.pem" # The timezone that the web interface uses. USER_TIME_ZONE="Europe/Berlin" -# Optional prefix for compose project and docker container, defaults to adit -# COMPOSE_PROJECT_NAME="your_project_name" +# An optional name of the stack (or compose project in development). +# When not set it defaults to the project name with suffix "_dev" resp. "_prod". +# For ADIT "adit_dev" and "adit_prod". For RADIS "radis_dev" and "radis_prod". +STACK_NAME=