diff --git a/.env.prod.example b/.env.prod.example index 768cab9..56e846a 100644 --- a/.env.prod.example +++ b/.env.prod.example @@ -8,7 +8,7 @@ # RELEASE VERSION # ===================================================== # Tag fra Gitea (f.eks. v1.0.0, v1.2.3) -RELEASE_VERSION=v2.0.3 +RELEASE_VERSION=v2.0.4 # ===================================================== # GITEA AUTHENTICATION diff --git a/RELEASE_NOTES_v2.0.4.md b/RELEASE_NOTES_v2.0.4.md new file mode 100644 index 0000000..8f587fb --- /dev/null +++ b/RELEASE_NOTES_v2.0.4.md @@ -0,0 +1,8 @@ +# Release Notes v2.0.4 + +## Fixes +- Reworked the migration execution endpoint to stream SQL files via stdin instead of relying on chained shell commands, which broke on Podman/Docker setups and led to pattern-matching errors for some files. +- Added a default `CONTAINER_RUNTIME` setting so the endpoint knows whether to run `docker` or `podman` when the env var is not provided. + +--- +Release Date: 28. januar 2026 \ No newline at end of file diff --git a/VERSION b/VERSION index 6acdb44..26e3379 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.3 \ No newline at end of file +2.0.4 \ No newline at end of file diff --git a/app/core/config.py b/app/core/config.py index 2f20094..e453e8a 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -147,6 +147,7 @@ class Settings(BaseSettings): POSTGRES_PASSWORD: str = "bmc_hub" POSTGRES_DB: str = "bmc_hub" POSTGRES_PORT: int = 5432 + CONTAINER_RUNTIME: str = "docker" RELEASE_VERSION: str = "latest" GITEA_URL: str = "https://g.bmcnetworks.dk" GITHUB_TOKEN: str = "" diff --git a/app/settings/backend/views.py b/app/settings/backend/views.py index 8d4458d..b14c1ca 100644 --- a/app/settings/backend/views.py +++ b/app/settings/backend/views.py @@ -8,7 +8,7 @@ from fastapi import APIRouter, Request, HTTPException from fastapi.responses import HTMLResponse from fastapi.templating import Jinja2Templates from pydantic import BaseModel -import shlex +import os import subprocess from app.core.config import settings @@ -65,15 +65,30 @@ def execute_migration(payload: MigrationExecution): raise HTTPException(status_code=404, detail="Migration file not found") # Determine the container runtime (Podman or Docker) - container_runtime = "podman" if settings.CONTAINER_RUNTIME == "podman" else "docker" + runtime = settings.CONTAINER_RUNTIME.lower() + if runtime not in {"docker", "podman"}: + runtime = "docker" - # Execute the migration file - command = ( - f"cat {shlex.quote(str(migration_file))} | " - f"{container_runtime} exec -i bmc-hub-postgres " - f"psql -U {settings.POSTGRES_USER} -d {settings.POSTGRES_DB}" + command = [ + runtime, + "exec", + "-i", + "bmc-hub-postgres", + "psql", + "-U", + settings.POSTGRES_USER, + "-d", + settings.POSTGRES_DB, + ] + + migration_sql = migration_file.read_text() + result = subprocess.run( + command, + input=migration_sql, + capture_output=True, + text=True, + env={**os.environ, "PGPASSWORD": settings.POSTGRES_PASSWORD}, ) - result = subprocess.run(command, shell=True, capture_output=True, text=True) if result.returncode != 0: raise HTTPException(status_code=500, detail=f"Migration failed: {result.stderr}")