Files
euchre_camp/Dockerfile
T

69 lines
2.0 KiB
Docker

# Multi-stage build for EuchreCamp Next.js application
# Stage 1: Builder
FROM node:20-alpine AS builder
# Install dependencies
RUN apk add --no-cache python3 make g++
# Set working directory
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies (including dev dependencies for building)
RUN npm ci
# Copy source code
COPY . .
# Generate Prisma client (with dummy PostgreSQL DATABASE_URL for build-time generation)
# Note: A dummy URL is used since the real database is not available during build
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" npx prisma generate
# Build the application (with dummy DATABASE_URL for static page generation and git commit)
ARG GIT_COMMIT=unknown
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" NEXT_PUBLIC_GIT_COMMIT=$GIT_COMMIT npm run build
# Stage 2: Runner
FROM node:20-alpine AS runner
# Install dumb-init for proper signal handling
RUN apk add --no-cache dumb-init
# Create non-root user
RUN addgroup --system --gid 1001 euchre && \
adduser --system --uid 1001 --ingroup euchre euchre
# Set working directory
WORKDIR /app
# Copy built application from builder
COPY --from=builder --chown=euchre:euchre /app/.next ./.next
COPY --from=builder --chown=euchre:euchre /app/public ./public
COPY --from=builder --chown=euchre:euchre /app/package.json ./package.json
COPY --from=builder --chown=euchre:euchre /app/package-lock.json ./package-lock.json
COPY --from=builder --chown=euchre:euchre /app/prisma ./prisma
# Install only production dependencies
RUN npm ci --omit=dev
# Generate Prisma client
# Note: We need to set DATABASE_URL even for generation because prisma.config.ts requires it
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" npx prisma generate
# Switch to non-root user
USER euchre
# Expose port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1
# Start command
ENTRYPOINT ["dumb-init", "--"]
CMD ["npm", "start"]