Update Docker configuration for Prisma migrations: Comment out migrations volume in docker-compose.yml for production use, and add checks in Dockerfile to verify the presence of migrations during build and entrypoint execution.
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 14s

This commit is contained in:
Julien Froidefond
2025-12-19 08:40:18 +01:00
parent 0b56d625ec
commit d6a1e21e9f
2 changed files with 13 additions and 6 deletions

View File

@@ -19,6 +19,9 @@ RUN corepack enable && corepack prepare pnpm@latest --activate
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Vérifier que les migrations sont bien présentes
RUN ls -la /app/prisma/migrations || echo "WARNING: Migrations directory not found"
ENV DATABASE_URL="postgresql://user:pass@localhost:5432/db"
RUN pnpm prisma generate
@@ -45,10 +48,10 @@ COPY --from=builder --chown=nextjs:nodejs /app/public ./public
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/pnpm-lock.yaml ./pnpm-lock.yaml
COPY --from=builder /app/next.config.js ./next.config.js
RUN mkdir -p /app/prisma/migrations
COPY --from=builder --chown=nextjs:nodejs /app/prisma/schema.prisma ./prisma/schema.prisma
COPY --from=builder --chown=nextjs:nodejs /app/prisma/migrations ./prisma/migrations
COPY --from=builder /app/prisma.config.ts ./prisma.config.ts
# Copier le répertoire prisma complet (schema + migrations + config)
COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma
# Vérifier que les migrations ont bien été copiées
RUN ls -la /app/prisma/migrations || (echo "ERROR: Migrations not found after COPY" && exit 1)
ENV DATABASE_URL="postgresql://user:pass@localhost:5432/db"
@@ -65,7 +68,9 @@ RUN echo '#!/bin/sh' > /app/entrypoint.sh && \
echo 'set -e' >> /app/entrypoint.sh && \
echo 'mkdir -p /app/public/uploads' >> /app/entrypoint.sh && \
echo 'mkdir -p /app/public/uploads/backgrounds' >> /app/entrypoint.sh && \
echo 'pnpm dlx prisma migrate deploy || true' >> /app/entrypoint.sh && \
echo 'echo "Checking migrations..."' >> /app/entrypoint.sh && \
echo 'ls -la /app/prisma/migrations || echo "Migrations directory not found"' >> /app/entrypoint.sh && \
echo 'pnpm dlx prisma migrate deploy' >> /app/entrypoint.sh && \
echo 'exec pnpm start' >> /app/entrypoint.sh && \
chmod +x /app/entrypoint.sh && \
chown nextjs:nodejs /app/entrypoint.sh

View File

@@ -44,7 +44,9 @@ services:
volumes:
# Persist uploaded images (avatars and backgrounds)
- ${UPLOADS_PATH:-./public/uploads}:/app/public/uploads
- ./prisma/migrations:/app/prisma/migrations
# Migrations: décommenter uniquement en développement local pour modifier les migrations sans rebuild
# En production, les migrations sont incluses dans l'image Docker
# - ./prisma/migrations:/app/prisma/migrations
depends_on:
got-postgres:
condition: service_healthy