File size: 1,791 Bytes
1067b6f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | # ---------- Base image ----------
FROM node:20-alpine AS base
# Needed for some native deps
RUN apk add --no-cache libc6-compat python3 make g++
WORKDIR /app
# ---------- Dependencies (prod) ----------
FROM base AS deps
WORKDIR /app
# Copy only package manifests
COPY package.json package-lock.json ./
# Install prod deps (no dev) – use npm install, not npm ci
RUN npm install --omit=dev --legacy-peer-deps --no-audit --no-fund
# ---------- Build (dev + tooling) ----------
FROM base AS builder
WORKDIR /app
# Copy manifests and install full deps (including dev)
COPY package.json package-lock.json ./
RUN npm install --legacy-peer-deps --no-audit --no-fund
# Copy the rest of the source
COPY . .
# Ensure migrations-folder exists so COPY in the next stage never fails
# Try to generate Drizzle migrations; if it fails, don't break the build
RUN mkdir -p migrations-folder && \
npx drizzle-kit generate || echo "Skipping drizzle-kit generate step"
# Build the Next.js app
RUN npm run build
# ---------- Runtime ----------
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
# Copy runtime deps from deps stage
COPY --from=deps /app/node_modules ./node_modules
# Copy built app + configs
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/styles ./styles
COPY --from=builder /app/next.config.js ./next.config.js
COPY --from=builder /app/tailwind.config.js ./tailwind.config.js
COPY --from=builder /app/postcss.config.js ./postcss.config.js
COPY --from=builder /app/drizzle.config.json ./drizzle.config.json
COPY --from=builder /app/migrations-folder ./migrations-folder
# ⭐ REQUIRED ⭐
COPY --from=builder /app/db ./db
EXPOSE 3000
CMD ["npm", "start"]
|