89 lines
2.1 KiB
Docker
89 lines
2.1 KiB
Docker
# Multi-stage Dockerfile for MycroZine Web App
|
|
# Based on decolonize-time-website pattern
|
|
|
|
FROM node:20-alpine AS base
|
|
RUN corepack enable && corepack prepare pnpm@latest --activate
|
|
|
|
# Dependencies stage
|
|
FROM base AS deps
|
|
WORKDIR /app
|
|
|
|
# Copy package files from web directory
|
|
COPY web/package.json web/pnpm-lock.yaml* web/package-lock.json* web/yarn.lock* ./
|
|
|
|
# Install dependencies
|
|
RUN \
|
|
if [ -f pnpm-lock.yaml ]; then pnpm install --frozen-lockfile; \
|
|
elif [ -f package-lock.json ]; then npm ci; \
|
|
elif [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
|
else npm install; \
|
|
fi
|
|
|
|
# Builder stage
|
|
FROM base AS builder
|
|
WORKDIR /app
|
|
|
|
# Copy dependencies
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
|
|
# Copy web app source
|
|
COPY web/ ./
|
|
|
|
# Copy the mycro-zine library source (needed for layout generation)
|
|
COPY src/ ../src/
|
|
|
|
# Set build-time environment variables
|
|
ARG GEMINI_API_KEY
|
|
ARG NEXT_PUBLIC_APP_URL=https://zine.jeffemmett.com
|
|
|
|
ENV GEMINI_API_KEY=$GEMINI_API_KEY
|
|
ENV NEXT_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
# Build the application
|
|
RUN npm run build
|
|
|
|
# Production runner stage
|
|
FROM base AS runner
|
|
WORKDIR /app
|
|
|
|
# Set runtime environment
|
|
ENV NODE_ENV=production
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
ENV PORT=3000
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
# Create non-root user for security
|
|
RUN addgroup --system --gid 1001 nodejs
|
|
RUN adduser --system --uid 1001 nextjs
|
|
|
|
# Copy built application
|
|
COPY --from=builder /app/public ./public
|
|
|
|
# Set permissions for prerender cache
|
|
RUN mkdir .next
|
|
RUN chown nextjs:nodejs .next
|
|
|
|
# Copy standalone build
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
|
|
# Copy the mycro-zine library for runtime
|
|
COPY --chown=nextjs:nodejs src/ ../src/
|
|
|
|
# Create data directory for zine storage
|
|
RUN mkdir -p /app/data/zines && chown -R nextjs:nodejs /app/data
|
|
|
|
# Switch to non-root user
|
|
USER nextjs
|
|
|
|
# Expose port
|
|
EXPOSE 3000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/ || exit 1
|
|
|
|
# Start the application
|
|
CMD ["node", "server.js"]
|