Le script docker/entrypoint.sh : - Attend PostgreSQL (netcat sur host:port extrait de DATABASE_URL) - Cree le dossier /app/data si SQLite - Applique les migrations via prisma migrate deploy - Execute le seed si RUN_SEED=true (non bloquant) - Demarre server.js (mode standalone Next) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
59 lines
2.0 KiB
Bash
Executable File
59 lines
2.0 KiB
Bash
Executable File
#!/bin/sh
|
|
# ---------------------------------------------------------------
|
|
# Entrypoint IPAM
|
|
# ---------------------------------------------------------------
|
|
# 1. Attend la base de données si PostgreSQL
|
|
# 2. Applique les migrations Prisma (prisma migrate deploy)
|
|
# 3. Optionnel : seed initial si RUN_SEED=true
|
|
# 4. Démarre le serveur Next.js (mode standalone)
|
|
# ---------------------------------------------------------------
|
|
set -eu
|
|
|
|
log() { printf '\033[36m[entrypoint]\033[0m %s\n' "$*"; }
|
|
err() { printf '\033[31m[entrypoint]\033[0m %s\n' "$*" >&2; }
|
|
|
|
# --- 1. Attente DB (PostgreSQL uniquement) ------------------------
|
|
if [ "${DATABASE_PROVIDER:-sqlite}" = "postgresql" ]; then
|
|
if [ -z "${DATABASE_URL:-}" ]; then
|
|
err "DATABASE_URL requis pour PostgreSQL"
|
|
exit 1
|
|
fi
|
|
|
|
log "Attente de PostgreSQL…"
|
|
# Extraction host:port de l'URL (format postgresql://user:pass@host:port/db?…)
|
|
HOST_PORT=$(printf '%s' "$DATABASE_URL" | sed -E 's#.*@([^/?]+).*#\1#')
|
|
HOST=$(printf '%s' "$HOST_PORT" | cut -d: -f1)
|
|
PORT=$(printf '%s' "$HOST_PORT" | cut -d: -f2)
|
|
[ "$PORT" = "$HOST" ] && PORT=5432
|
|
|
|
RETRIES=30
|
|
while ! nc -z "$HOST" "$PORT" 2>/dev/null; do
|
|
RETRIES=$((RETRIES - 1))
|
|
if [ "$RETRIES" -le 0 ]; then
|
|
err "PostgreSQL injoignable après 30 tentatives ($HOST:$PORT)"
|
|
exit 1
|
|
fi
|
|
sleep 1
|
|
done
|
|
log "PostgreSQL disponible ($HOST:$PORT)"
|
|
fi
|
|
|
|
# --- 2. Crée le dossier data pour SQLite --------------------------
|
|
if [ "${DATABASE_PROVIDER:-sqlite}" = "sqlite" ]; then
|
|
mkdir -p /app/data
|
|
fi
|
|
|
|
# --- 3. Migrations Prisma -----------------------------------------
|
|
log "Application des migrations Prisma…"
|
|
npx prisma migrate deploy
|
|
|
|
# --- 4. Seed optionnel --------------------------------------------
|
|
if [ "${RUN_SEED:-false}" = "true" ]; then
|
|
log "Exécution du seed initial…"
|
|
npx tsx prisma/seed.ts || err "Seed échoué (non bloquant)"
|
|
fi
|
|
|
|
# --- 5. Lancement du serveur --------------------------------------
|
|
log "Démarrage du serveur Next.js sur :${PORT:-3000}"
|
|
exec node server.js
|