All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 44s
Backup before migration (pg_dump/SQLite copy), DB connection wait with retries, idempotent prisma migrate deploy, old backup cleanup (keep 5), and server refuses to start if migration fails. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
77 lines
2.4 KiB
Docker
77 lines
2.4 KiB
Docker
# ===========================================================================
|
|
# Stage 1: Dependencies
|
|
# ===========================================================================
|
|
FROM node:22-bookworm-slim AS deps
|
|
WORKDIR /app
|
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
openssl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
COPY package.json package-lock.json* ./
|
|
COPY prisma ./prisma
|
|
|
|
RUN npm install
|
|
RUN npx prisma generate
|
|
|
|
# ===========================================================================
|
|
# Stage 2: Build
|
|
# ===========================================================================
|
|
FROM node:22-bookworm-slim AS builder
|
|
WORKDIR /app
|
|
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
COPY . .
|
|
|
|
# PrismaClient validates DATABASE_URL format at import time.
|
|
# No actual DB connection occurs during build (all pages are dynamic).
|
|
ENV DATABASE_URL="postgresql://build:build@localhost:5432/build"
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
RUN npm run build
|
|
|
|
# ===========================================================================
|
|
# Stage 3: Runner
|
|
# ===========================================================================
|
|
FROM node:22-bookworm-slim AS runner
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
openssl \
|
|
postgresql-client \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
RUN groupadd --system --gid 1001 nodejs
|
|
RUN useradd --system --uid 1001 --gid nodejs nextjs
|
|
|
|
# Static assets
|
|
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
|
|
|
# Upload directory (outside public/ — served via API route)
|
|
RUN mkdir -p ./data/uploads/notes && chown -R nextjs:nodejs ./data
|
|
|
|
# Next.js standalone output
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
|
|
# Prisma: schema + migrations + generated client + CLI
|
|
COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma
|
|
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/.prisma ./node_modules/.prisma
|
|
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/@prisma ./node_modules/@prisma
|
|
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/prisma ./node_modules/prisma
|
|
|
|
# Entrypoint
|
|
COPY --from=builder --chown=nextjs:nodejs /app/docker-entrypoint.sh ./docker-entrypoint.sh
|
|
RUN chmod +x ./docker-entrypoint.sh
|
|
|
|
USER nextjs
|
|
|
|
EXPOSE 3000
|
|
ENV PORT=3000
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
ENTRYPOINT ["./docker-entrypoint.sh"]
|