Add production Docker deployment configuration
- Add multi-stage Dockerfile for Next.js standalone build - Add docker-compose.deploy.yml for production deployment - Add entrypoint.sh for database migration and startup - Add .dockerignore for efficient Docker builds - Add docker/.env.production with all required env vars - Add Caddyfile.prod with security headers and optimizations - Update next.config.ts with output: standalone for Docker - Add DOCKER_DEPLOYMENT.md with comprehensive deployment guide
This commit is contained in:
+57
@@ -0,0 +1,57 @@
|
||||
# Multi-stage build for Next.js monorepo
|
||||
FROM node:22-alpine AS base
|
||||
RUN corepack enable pnpm
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies stage
|
||||
FROM base AS deps
|
||||
RUN apk add --no-cache libc6-compat
|
||||
COPY pnpm-lock.yaml pnpm-workspace.yaml package.json ./
|
||||
RUN pnpm install --frozen-lockfile --prod
|
||||
|
||||
# Build stage
|
||||
FROM base AS builder
|
||||
RUN apk add --no-cache libc6-compat postgresql-client
|
||||
COPY pnpm-lock.yaml pnpm-workspace.yaml package.json ./
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Build the app
|
||||
RUN pnpm build
|
||||
|
||||
# Production runtime
|
||||
FROM base AS runtime
|
||||
RUN apk add --no-cache libc6-compat postgresql-client
|
||||
ENV NODE_ENV production
|
||||
|
||||
# Copy production node_modules
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
|
||||
# Copy built Next.js app
|
||||
COPY --from=builder /app/apps/web/.next/standalone ./
|
||||
|
||||
# Copy public assets
|
||||
COPY --from=builder /app/apps/web/public ./public
|
||||
|
||||
# Copy workspace packages (needed for migrations)
|
||||
COPY --from=builder /app/packages ./packages
|
||||
|
||||
# Copy root package.json for pnpm monorepo
|
||||
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml ./
|
||||
|
||||
# Create non-root user
|
||||
RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001
|
||||
|
||||
# Copy entrypoint script
|
||||
COPY docker/entrypoint.sh /app/entrypoint.sh
|
||||
RUN chmod +x /app/entrypoint.sh
|
||||
|
||||
USER nextjs
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
ENV PORT 3000
|
||||
|
||||
CMD ["/app/entrypoint.sh"]
|
||||
Reference in New Issue
Block a user