From 2edf5e9b11ad05a18bf1662a06fabc56f8cd464c Mon Sep 17 00:00:00 2001 From: nico Date: Mon, 13 Apr 2026 17:00:53 +0800 Subject: [PATCH] fix(deployment): add auto database migration on container startup - Create docker-entrypoint.sh to run prisma migrate deploy before app start - Update Dockerfile to use entrypoint script - Ensures database schema is always up-to-date after deployment - Fixes: CRUD kependudukan error 500 di staging karena tabel belum dibuat Co-authored-by: Qwen-Coder --- Dockerfile | 3 ++- QWEN.md | 21 +++++++++++++++++++++ docker-entrypoint.sh | 13 +++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index bba5a399..d7dbc7e4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -59,9 +59,10 @@ COPY --from=builder --chown=nextjs:nodejs /app/public ./public COPY --from=builder --chown=nextjs:nodejs /app/package.json ./package.json COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma COPY --from=builder --chown=nextjs:nodejs /app/next.config.* ./ +COPY --chmod=755 docker-entrypoint.sh ./docker-entrypoint.sh USER nextjs EXPOSE 3000 -CMD ["bun", "start"] \ No newline at end of file +CMD ["/app/docker-entrypoint.sh"] \ No newline at end of file diff --git a/QWEN.md b/QWEN.md index 3e0d9347..c1070959 100644 --- a/QWEN.md +++ b/QWEN.md @@ -250,3 +250,24 @@ Setelah commit ke branch deployment (dev/stg/prod), otomatis trigger workflow pu Branch deployment: `stg` (staging) atau `prod` (production) Version format di package.json: `"version": "major.minor.patch"` +- **Deployment Workflow HARUS Sequential (Berurutan)**: + +Saat deploy ke stg atau prod, workflow TIDAK BOLEH dijalankan bersamaan. Harus menunggu yang pertama SELESAI total baru trigger yang kedua. + +**Urutan yang BENAR:** +1. ✅ **publish.yml** - Tunggu sampai SELESAI (status: ✓ success) +2. ✅ **Setelah publish selesai**, baru trigger **re-pull.yml** + +**JANGAN trigger keduanya bersamaan!** Ini akan menyebabkan race condition karena re-pull akan menarik image yang belum selesai di-build. + +**Cara cek workflow selesai:** +```bash +gh run view --json status --jq '.status' +# Harus return "completed" baru lanjut ke re-pull +``` + +**Atau polling sampai selesai:** +```bash +gh run watch +# Tunggu sampai ada checkmark ✓ +``` diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 00000000..e0b6e6bc --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -e + +echo "🔄 Running database migrations..." +cd /app +bunx prisma migrate deploy || { + echo "❌ Migration failed!" + exit 1 +} +echo "✅ Migrations completed successfully" + +echo "🚀 Starting application..." +exec bun start