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 <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -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"]
|
||||
CMD ["/app/docker-entrypoint.sh"]
|
||||
21
QWEN.md
21
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 <run_id> --json status --jq '.status'
|
||||
# Harus return "completed" baru lanjut ke re-pull
|
||||
```
|
||||
|
||||
**Atau polling sampai selesai:**
|
||||
```bash
|
||||
gh run watch <publish_run_id>
|
||||
# Tunggu sampai ada checkmark ✓
|
||||
```
|
||||
|
||||
13
docker-entrypoint.sh
Normal file
13
docker-entrypoint.sh
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user