- Install curl in Alpine image for health checks - Add ARG and ENV declarations for NEXT_PUBLIC_* variables in builder stage - Pass build args from docker-compose.yml to Dockerfile - Update health checks to use curl instead of node -e - Update .env.example with helpful comments for Docker vs local dev 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
75 lines
1.7 KiB
Docker
75 lines
1.7 KiB
Docker
# Pastel UI - Production Docker Image
|
|
# Multi-stage build for optimized Next.js 16 application
|
|
|
|
# Stage 1: Dependencies
|
|
FROM node:20-alpine AS deps
|
|
RUN corepack enable && corepack prepare pnpm@latest --activate
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy package files
|
|
COPY package.json pnpm-lock.yaml ./
|
|
|
|
# Install dependencies
|
|
RUN pnpm install --frozen-lockfile --prod=false
|
|
|
|
# Stage 2: Builder
|
|
FROM node:20-alpine AS builder
|
|
RUN corepack enable && corepack prepare pnpm@latest --activate
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy dependencies from deps stage
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
|
|
# Copy source files
|
|
COPY . .
|
|
|
|
# Set build-time environment variables
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
ENV NODE_ENV=production
|
|
|
|
# Accept build args for environment variables
|
|
ARG NEXT_PUBLIC_API_URL
|
|
ARG NEXT_PUBLIC_APP_URL
|
|
|
|
# Set environment variables for Next.js build
|
|
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
|
|
ENV NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL}
|
|
|
|
# Build the application
|
|
RUN pnpm build
|
|
|
|
# Stage 3: Runner
|
|
FROM node:20-alpine AS runner
|
|
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
# Install curl for health checks
|
|
RUN apk add --no-cache curl
|
|
|
|
# Create non-root user
|
|
RUN addgroup --system --gid 1001 nodejs && \
|
|
adduser --system --uid 1001 nextjs
|
|
|
|
# Copy built application
|
|
COPY --from=builder /app/public ./public
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
|
|
USER nextjs
|
|
|
|
EXPOSE 3000
|
|
|
|
ENV PORT=3000
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
|
CMD curl -f http://localhost:3000/ || exit 1
|
|
|
|
CMD ["node", "server.js"]
|