# Build stage FROM node:20-alpine AS builder WORKDIR /app # Sharp needs these for native compilation RUN apk add --no-cache python3 make g++ # Copy package files first for layer caching COPY package*.json ./ # Install dependencies RUN npm ci || npm install # Copy source files COPY src ./src COPY public ./public COPY next.config.ts tsconfig.json postcss.config.mjs components.json ./ COPY eslint.config.mjs ./ # Build the application RUN npm run build # Production stage FROM node:20-alpine AS runner WORKDIR /app ENV NODE_ENV=production # Sharp runtime dependencies RUN apk add --no-cache vips-dev # Create non-root user RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs # Copy necessary files from builder COPY --from=builder /app/public ./public COPY --from=builder /app/.next/standalone ./ COPY --from=builder /app/.next/static ./.next/static # Create data directory for zine storage RUN mkdir -p /app/data/zines && chown -R nextjs:nodejs /app/data # Set ownership RUN chown -R nextjs:nodejs /app USER nextjs EXPOSE 3000 ENV PORT=3000 ENV HOSTNAME="0.0.0.0" ENV DATA_DIR=/app/data CMD ["node", "server.js"]