82 lines
2.4 KiB
Docker
82 lines
2.4 KiB
Docker
# =============================================================================
|
|
# MOPC Platform - Production Dockerfile
|
|
# =============================================================================
|
|
# Multi-stage build for optimized production image
|
|
|
|
FROM node:22-alpine AS base
|
|
|
|
# Install dependencies only when needed
|
|
FROM base AS deps
|
|
RUN apk add --no-cache libc6-compat
|
|
WORKDIR /app
|
|
|
|
# Copy package files
|
|
COPY package.json package-lock.json* ./
|
|
RUN npm ci
|
|
|
|
# Rebuild the source code only when needed
|
|
FROM base AS builder
|
|
WORKDIR /app
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
COPY . .
|
|
|
|
# Generate Prisma client
|
|
RUN npx prisma generate
|
|
|
|
# Build Next.js
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
RUN npm run build
|
|
|
|
# Production image, copy all the files and run next
|
|
FROM base AS runner
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
# Create non-root user for security
|
|
RUN addgroup --system --gid 1001 nodejs
|
|
RUN adduser --system --uid 1001 nextjs
|
|
|
|
# Install runtime dependencies for migrations and seeding
|
|
RUN apk add --no-cache libc6-compat
|
|
|
|
# Copy built files
|
|
COPY --from=builder /app/public ./public
|
|
COPY --from=builder /app/.next/standalone ./
|
|
COPY --from=builder /app/.next/static ./.next/static
|
|
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
|
|
|
|
# Copy seed dependencies (for manual seeding via docker exec)
|
|
COPY --from=builder /app/node_modules/bcryptjs ./node_modules/bcryptjs
|
|
COPY --from=builder /app/node_modules/papaparse ./node_modules/papaparse
|
|
COPY --from=builder /app/node_modules/tsx ./node_modules/tsx
|
|
COPY --from=builder /app/node_modules/esbuild ./node_modules/esbuild
|
|
COPY --from=builder /app/node_modules/@esbuild ./node_modules/@esbuild
|
|
|
|
# Copy CSV data file for manual seeding
|
|
COPY --from=builder /app/docs/candidatures_2026.csv ./docs/candidatures_2026.csv
|
|
|
|
# Copy package.json for npx/module resolution
|
|
COPY --from=builder /app/package.json ./package.json
|
|
|
|
# Copy entrypoint script
|
|
COPY docker/docker-entrypoint.sh /app/docker-entrypoint.sh
|
|
RUN chmod +x /app/docker-entrypoint.sh
|
|
|
|
# Set correct permissions
|
|
RUN chown -R nextjs:nodejs /app
|
|
|
|
USER nextjs
|
|
|
|
EXPOSE 7600
|
|
|
|
ENV PORT=7600
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
# Run via entrypoint (migrate then start)
|
|
CMD ["/app/docker-entrypoint.sh"]
|