Skip to content

Commit

Permalink
Improve setting stack name by using env var
Browse files Browse the repository at this point in the history
  • Loading branch information
medihack authored Nov 18, 2024
1 parent 88b0c0b commit 8ad08d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
17 changes: 7 additions & 10 deletions adit_radis_shared/invoke_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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] = []):
Expand Down
6 changes: 4 additions & 2 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -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=

0 comments on commit 8ad08d9

Please sign in to comment.