diff --git a/Dockerfile b/Dockerfile index 64bbaa3..0b4b9e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,11 +13,6 @@ WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . -# Next.js collects completely anonymous telemetry data about general usage. -# Learn more here: https://nextjs.org/telemetry -# Uncomment the following line in case you want to disable telemetry during the build. -# ENV NEXT_TELEMETRY_DISABLED 1 - RUN npx prisma generate RUN npm run build @@ -26,46 +21,47 @@ FROM node:20-alpine AS runner WORKDIR /app ENV NODE_ENV production -# Uncomment the following line in case you want to disable telemetry during runtime. -# ENV NEXT_TELEMETRY_DISABLED 1 RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs +# Copy public folder COPY --from=builder /app/public ./public # Set the correct permission for prerender cache RUN mkdir .next RUN chown nextjs:nodejs .next -# Automatically leverage output traces to reduce image size -# https://nextjs.org/docs/advanced-features/output-file-tracing +# Copy standalone build COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static -# Copy Prisma files for migrations +# Copy Prisma files for migrations (as root before switching user) COPY --from=builder /app/prisma ./prisma COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma +COPY --from=builder /app/node_modules/prisma ./node_modules/prisma -# Install prisma CLI for migrations -RUN npm install -g prisma +# Fix permissions for prisma folder +RUN chown -R nextjs:nodejs ./prisma ./node_modules/.prisma ./node_modules/@prisma ./node_modules/prisma # Create entrypoint script -RUN echo '#!/bin/sh' > /app/entrypoint.sh && \ - echo 'echo "Running database migrations..."' >> /app/entrypoint.sh && \ - echo 'npx prisma migrate deploy' >> /app/entrypoint.sh && \ - echo 'echo "Starting application..."' >> /app/entrypoint.sh && \ - echo 'exec node server.js' >> /app/entrypoint.sh && \ - chmod +x /app/entrypoint.sh +COPY <