Bernt Christian Egeland 1 месяц назад
Родитель
Сommit
8916278dfa
2 измененных файлов с 28 добавлено и 7 удалено
  1. 20 6
      .github/workflows/deploy-demo.yml
  2. 8 1
      init-db.sh

+ 20 - 6
.github/workflows/deploy-demo.yml

@@ -144,17 +144,31 @@ jobs:
 
       - name: Health check
         run: |
-          echo "Waiting for demo container to be ready..."
-          for i in $(seq 1 12); do
+          # Docker reports "running" as soon as the entrypoint starts, which is
+          # before init-db.sh has applied migrations. The seed step below writes
+          # to tables those migrations touch, so waiting on status alone let it
+          # race ahead and fail on a column that did not exist yet. The health
+          # route only answers once node server.js is up, i.e. after migrating.
+          echo "Waiting for demo app to serve..."
+          for i in $(seq 1 60); do
             STATUS=$(docker inspect --format='{{.State.Status}}' torqvoice-app-demo 2>/dev/null || echo "not found")
-            if [ "$STATUS" = "running" ]; then
-              echo "Container is running!"
+            case "$STATUS" in
+              running|created|restarting) ;;
+              *)
+                echo "::error::Container is not running (status: $STATUS)"
+                docker logs torqvoice-app-demo --tail 50
+                exit 1
+                ;;
+            esac
+            if docker exec torqvoice-app-demo \
+              wget -q -O /dev/null http://127.0.0.1:3000/api/v1/health 2>/dev/null; then
+              echo "Demo app is healthy!"
               exit 0
             fi
-            echo "Status: $STATUS, retrying in 5s..."
+            echo "Not serving yet, retrying in 5s..."
             sleep 5
           done
-          echo "::error::Container failed to start"
+          echo "::error::Demo app did not become healthy in time"
           docker logs torqvoice-app-demo --tail 50
           exit 1
 

+ 8 - 1
init-db.sh

@@ -18,7 +18,13 @@ done
 echo "PostgreSQL is ready!"
 
 echo "Applying database migrations..."
-if ! npx prisma migrate deploy 2>/dev/null; then
+# Keep stderr rather than discarding it: when the retry below also fails, the
+# first error is the one that says why, and swallowing it left the container
+# dying with no reason recorded.
+migrate_err=$(mktemp)
+if ! npx prisma migrate deploy 2>"$migrate_err"; then
+  echo "First migrate attempt failed:"
+  sed 's/^/  /' "$migrate_err" >&2
   # P3005: existing DB without migration history (from db push).
   # Create empty migration table so migrate deploy can run.
   # 0_init is fully idempotent — safe on any DB state.
@@ -26,6 +32,7 @@ if ! npx prisma migrate deploy 2>/dev/null; then
   npx prisma db execute --stdin <<< 'CREATE TABLE IF NOT EXISTS "_prisma_migrations" ("id" VARCHAR(36) PRIMARY KEY NOT NULL, "checksum" VARCHAR(64) NOT NULL, "finished_at" TIMESTAMPTZ, "migration_name" VARCHAR(255) NOT NULL, "logs" TEXT, "rolled_back_at" TIMESTAMPTZ, "started_at" TIMESTAMPTZ NOT NULL DEFAULT now(), "applied_steps_count" INTEGER NOT NULL DEFAULT 0)'
   npx prisma migrate deploy
 fi
+rm -f "$migrate_err"
 echo "Migrations applied successfully!"
 
 # Photo embedding is the one thing here that depends on a native module, and