Refactor Dockerfile to improve Prisma Client generation and migration handling: Replace direct Prisma command with pnpm dlx for better execution, and modify entrypoint script to allow migration failures without stopping the application.
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 10s

This commit is contained in:
Julien Froidefond
2025-12-15 17:38:27 +01:00
parent 83aa54ff44
commit d9555a5d49

View File

@@ -51,10 +51,9 @@ COPY --from=builder /app/prisma.config.ts ./prisma.config.ts
ENV DATABASE_URL="file:/tmp/build.db"
# Installer seulement les dépendances de production puis générer Prisma Client
# Note: prisma doit être en dependencies (pas devDependencies) pour migrate deploy
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
pnpm install --frozen-lockfile --prod && \
pnpm prisma generate
pnpm dlx prisma generate
ENV DATABASE_URL="file:/app/data/dev.db"
@@ -64,19 +63,10 @@ RUN mkdir -p /app/data /app/public/uploads /app/public/uploads/backgrounds && \
RUN echo '#!/bin/sh' > /app/entrypoint.sh && \
echo 'set -e' >> /app/entrypoint.sh && \
echo 'echo "Starting application..."' >> /app/entrypoint.sh && \
echo 'mkdir -p /app/data' >> /app/entrypoint.sh && \
echo 'mkdir -p /app/public/uploads' >> /app/entrypoint.sh && \
echo 'mkdir -p /app/public/uploads/backgrounds' >> /app/entrypoint.sh && \
echo 'echo "Applying database migrations..."' >> /app/entrypoint.sh && \
echo 'pnpm dlx prisma migrate deploy' >> /app/entrypoint.sh && \
echo 'if [ $? -eq 0 ]; then' >> /app/entrypoint.sh && \
echo ' echo "Migrations applied successfully"' >> /app/entrypoint.sh && \
echo 'else' >> /app/entrypoint.sh && \
echo ' echo "ERROR: Failed to apply migrations"' >> /app/entrypoint.sh && \
echo ' exit 1' >> /app/entrypoint.sh && \
echo 'fi' >> /app/entrypoint.sh && \
echo 'echo "Starting Next.js server..."' >> /app/entrypoint.sh && \
echo 'pnpm dlx prisma migrate deploy || true' >> /app/entrypoint.sh && \
echo 'exec pnpm start' >> /app/entrypoint.sh && \
chmod +x /app/entrypoint.sh && \
chown nextjs:nodejs /app/entrypoint.sh