Skip to content

Commit

Permalink
Fixed inconsistencies in prod deployment script
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogsilva committed Nov 26, 2024
1 parent c92e829 commit 2fdd543
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
26 changes: 13 additions & 13 deletions deployments/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,7 @@ class _RelaunchDeploymentScript:
name: str = "Relaunch the updated deployment script"

def handle(self) -> None:
call_args = self.original_call_args[:]
if (update_flag_index := args.index("--auto-update")) != -1:
call_args.pop(update_flag_index)
os.execv(sys.executable, call_args)
os.execv(sys.executable, self.original_call_args[:])


@dataclasses.dataclass
Expand All @@ -339,10 +336,11 @@ def handle(self) -> None:
)
compose_template = Template(compose_teplate_path.read_text())
rendered = compose_template.substitute(dataclasses.asdict(self.config))
target_path = Path(
self.config.deployment_root / "docker/compose.production.yaml"
)
target_path.write_text(rendered)
target_path = Path(self.config.deployment_root / "compose.production.yaml")
with target_path.open("w") as fh:
for line in rendered.splitlines():
if not line.startswith("#"):
fh.write(line)
compose_teplate_path.unlink(missing_ok=True)


Expand Down Expand Up @@ -381,11 +379,13 @@ class _StopCompose(_ComposeCommandExecutor):

def handle(self) -> None:
print("Stopping docker compose stack...")
run_result = self._run_compose_command("down")
if run_result.returncode == 14:
logger.info("docker compose stack was not running, no need to stop")
else:
run_result.check_returncode()
try:
self._run_compose_command("down")
except subprocess.CalledProcessError as exc:
if exc.returncode == 14:
logger.info("docker compose stack was not running, no need to stop")
else:
raise


@dataclasses.dataclass
Expand Down
22 changes: 15 additions & 7 deletions docker/compose.production.template.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# docker compose file template that can be used to create a suitable production deployment file.
# This template file is meant to be processed via Python - the processor shall replace all
# template strings, which are denoted like this: ${name} with their respective values.
# template strings with their respective values. A template string is denoted like this: <DOLLAR>{name}
# with a dollar sign instead of <DOLLAR> - we are not writing it out here to avoid the processor trying
# to perform a substitution in these comments.
#
# NOTE: BECAUSE THIS FILE IS PREPROCESSED, ALL PLACES WHERE A DOLLAR SIGN IS SIGNIFICANT, LIKE
# IN TRAEFIK ROUTING RULES, MUST USE DOUBLE DOLLAR SIGNS INSTEAD. Check:
#
# https://docs.python.org/3/library/string.html#template-strings
#
#
# - do not mount source code inside any container - keep volume binds to the
# minimum, only for relevant configuration file(s) and data collections
Expand All @@ -18,7 +26,7 @@ services:
- "traefik.http.routers.router-arpav-backend.tls=true"
- "traefik.http.routers.router-arpav-backend.tls.certificates.certFile=/run/secrets/tls-cert"
- "traefik.http.routers.router-arpav-backend.tls.certificates.keyFile=/run/secrets/tls-key"
- 'traefik.http.routers.router-arpav-backend.rule=HostRegexp(`^(.+\.)?clima\.arpa\.veneto.it$`)'
- 'traefik.http.routers.router-arpav-backend.rule=HostRegexp(`^(.+\.)?clima\.arpa\.veneto.it$$`)'
configs:
- source: traefik-conf
target: /traefik.toml
Expand Down Expand Up @@ -95,16 +103,16 @@ services:
PREFECT_SERVER_CSRF_PROTECTION_ENABLED: "${prefect_server_env_csrf_protection_enabled}"
PREFECT_UI_API_URL: "${prefect_server_env_ui_api_url}"
PREFECT_UI_URL: "${prefect_server_env_ui_url}"
PREFECT_UI_SERVE_BASE: "${prefect_server_env_serve_base}"
PREFECT_UI_SERVE_BASE: "${prefect_server_env_ui_serve_base}"
restart: unless-stopped

prefect-static-worker:
image: "${backend_image}"
environment:
ARPAV_PPCV__DEBUG: "${prefect_static_worker_env_debug}"
ARPAV_PPCV__DB_DSN: "${prefect_static_worker_env_db_dsn}"
PREFECT_API_URL: "${prefect_static_worker_env_api_url}"
PREFECT_DEBUG_MODE: "${prefect_static_worker_env_debug_mode}"
ARPAV_PPCV__DEBUG: "${prefect_static_worker_env_arpav_ppcv_debug}"
ARPAV_PPCV__DB_DSN: "${prefect_static_worker_env_arpav_ppcv_db_dsn}"
PREFECT_API_URL: "${prefect_static_worker_env_prefect_api_url}"
PREFECT_DEBUG_MODE: "${prefect_static_worker_env_prefect_debug_mode}"
restart: unless-stopped

prefect-db:
Expand Down

0 comments on commit 2fdd543

Please sign in to comment.