From 7713eb2fa7c0830f9ef3826ac472ffb343003cad Mon Sep 17 00:00:00 2001 From: Nils-Johan Gynther Date: Sun, 24 May 2026 20:30:28 +0200 Subject: [PATCH] ci(deploy): standardize docker compose env file usage across scripts - Added --env-file .env to all docker compose commands for consistent environment variable loading - Added MISTRAL_API_KEY validation in deploy.sh with fatal error if missing - Added --force-recreate flag to recipe-api restarts in disable/enable receipt trace scripts - Added .env file existence check in rebuild_flutter.sh - Added API service recreation logic in deploy.sh when backend/importer services are updated --- deploy.sh | 10 +++++++++- scripts/disable_receipt_trace.sh | 2 +- scripts/enable_receipt_trace.sh | 4 ++-- scripts/rebuild_flutter.sh | 4 +++- scripts/reset_recipe_stack.sh | 2 +- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/deploy.sh b/deploy.sh index 966bb662..854a89ac 100755 --- a/deploy.sh +++ b/deploy.sh @@ -143,7 +143,10 @@ if [ "$BUILD_BACKEND" = true ] || [ "$RUN_SEED" = true ] || [ "$RUN_CLEAN_DATABA fi export SKIP_MIGRATION -COMPOSE_CMD=(docker compose -f compose.yml -f compose.flutter.yml) +COMPOSE_CMD=(docker compose --env-file .env -f compose.yml -f compose.flutter.yml) + +MISTRAL_API_KEY="$(read_env_value MISTRAL_API_KEY)" +[ -n "$MISTRAL_API_KEY" ] || fatal "MISTRAL_API_KEY saknas i .env" # ── Git pull ────────────────────────────────────────────────────────────────── info "Hämtar senaste kod (recipe-app)..." @@ -178,6 +181,11 @@ fi info "Startar tjänster..." "${COMPOSE_CMD[@]}" up -d +if [ "$BUILD_BACKEND" = true ] || [ "$BUILD_IMPORTER" = true ]; then + info "Återskapar API-tjänster för att säkra uppdaterade env-variabler..." + "${COMPOSE_CMD[@]}" up -d --force-recreate recipe-api importer-api +fi + # ── Databasrensning (opt-in) ────────────────────────────────────────────────── if [ "$RUN_CLEAN_DATABASE" = true ]; then CLEAN_SQL_FILE="backend/prisma/maintenance/clean-database.sql" diff --git a/scripts/disable_receipt_trace.sh b/scripts/disable_receipt_trace.sh index f0470f4b..f4a1dffb 100755 --- a/scripts/disable_receipt_trace.sh +++ b/scripts/disable_receipt_trace.sh @@ -19,6 +19,6 @@ fi echo "RECEIPT_TRACE_DECISIONS=0 satt i .env" echo "Startar om recipe-api utan full trace..." -docker compose -f compose.yml -f compose.flutter.yml up -d recipe-api +docker compose --env-file .env -f compose.yml -f compose.flutter.yml up -d --force-recreate recipe-api echo "Klart." diff --git a/scripts/enable_receipt_trace.sh b/scripts/enable_receipt_trace.sh index 9ae44aaa..0c282257 100755 --- a/scripts/enable_receipt_trace.sh +++ b/scripts/enable_receipt_trace.sh @@ -19,11 +19,11 @@ fi echo "RECEIPT_TRACE_DECISIONS=1 satt i .env" echo "Bygger och startar om recipe-api..." -docker compose -f compose.yml -f compose.flutter.yml up -d --build recipe-api +docker compose --env-file .env -f compose.yml -f compose.flutter.yml up -d --build --force-recreate recipe-api mkdir -p logs LOG_FILE="logs/receipt_decisions_$(date +%Y%m%d_%H%M%S).log" echo "Startar loggning till $LOG_FILE" echo "Tryck Ctrl+C för att avsluta loggströmmen." -docker compose -f compose.yml -f compose.flutter.yml logs -f recipe-api | tee "$LOG_FILE" +docker compose --env-file .env -f compose.yml -f compose.flutter.yml logs -f recipe-api | tee "$LOG_FILE" diff --git a/scripts/rebuild_flutter.sh b/scripts/rebuild_flutter.sh index 1f997974..9d4a91b0 100644 --- a/scripts/rebuild_flutter.sh +++ b/scripts/rebuild_flutter.sh @@ -2,7 +2,7 @@ set -Eeuo pipefail APP_DIR="${1:-/opt/containers/recipe-app}" -COMPOSE_FILES=(-f compose.yml -f compose.flutter.yml) +COMPOSE_FILES=(--env-file .env -f compose.yml -f compose.flutter.yml) SERVICE="recipe-flutter" log() { echo "[flutter-rebuild] $*"; } @@ -18,6 +18,8 @@ if [ ! -f "compose.yml" ] || [ ! -f "compose.flutter.yml" ]; then fail "compose.yml eller compose.flutter.yml saknas i $APP_DIR" fi +[ -f ".env" ] || fail ".env saknas i $APP_DIR" + log "Bygger om $SERVICE" docker compose "${COMPOSE_FILES[@]}" build "$SERVICE" diff --git a/scripts/reset_recipe_stack.sh b/scripts/reset_recipe_stack.sh index 55aa22c1..85b4c18b 100644 --- a/scripts/reset_recipe_stack.sh +++ b/scripts/reset_recipe_stack.sh @@ -7,7 +7,7 @@ trap 'echo "[reset][ERROR] Rad ${LINENO}: kommando misslyckades: ${BASH_COMMAND} # Config # ---------------------------------------- APP_DIR="${1:-/opt/containers/recipe-app}" -COMPOSE_FILES=(-f compose.yml -f compose.flutter.yml) +COMPOSE_FILES=(--env-file .env -f compose.yml -f compose.flutter.yml) DB_CONTAINER="recipe-db" IMPORTER_DIR="../microservice-importer" SEED_FILE="db/seeds/seed_all.sql"