Refactor Dockerfile and schema.prisma for improved migration handling: Remove migration checks during build, enhance entrypoint script to validate DATABASE_URL and schema.prisma presence, and update schema.prisma to use environment variable for database URL.
Some checks failed
Deploy with Docker Compose / deploy (push) Failing after 14s
Some checks failed
Deploy with Docker Compose / deploy (push) Failing after 14s
This commit is contained in:
14
Dockerfile
14
Dockerfile
@@ -19,9 +19,6 @@ 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
|
||||
|
||||
@@ -50,8 +47,6 @@ COPY --from=builder /app/pnpm-lock.yaml ./pnpm-lock.yaml
|
||||
COPY --from=builder /app/next.config.js ./next.config.js
|
||||
# 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"
|
||||
|
||||
@@ -70,7 +65,14 @@ RUN echo '#!/bin/sh' > /app/entrypoint.sh && \
|
||||
echo 'mkdir -p /app/public/uploads/backgrounds' >> /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 'if [ -z "$DATABASE_URL" ]; then' >> /app/entrypoint.sh && \
|
||||
echo ' echo "ERROR: DATABASE_URL is not set"' >> /app/entrypoint.sh && \
|
||||
echo ' exit 1' >> /app/entrypoint.sh && \
|
||||
echo 'fi' >> /app/entrypoint.sh && \
|
||||
echo 'echo "DATABASE_URL is set (checking schema.prisma)..."' >> /app/entrypoint.sh && \
|
||||
echo 'ls -la /app/prisma/schema.prisma || echo "ERROR: schema.prisma not found"' >> /app/entrypoint.sh && \
|
||||
echo 'export DATABASE_URL' >> /app/entrypoint.sh && \
|
||||
echo 'cd /app && pnpm dlx prisma migrate deploy --schema=./prisma/schema.prisma' >> /app/entrypoint.sh && \
|
||||
echo 'exec pnpm start' >> /app/entrypoint.sh && \
|
||||
chmod +x /app/entrypoint.sh && \
|
||||
chown nextjs:nodejs /app/entrypoint.sh
|
||||
|
||||
Reference in New Issue
Block a user