mirror of
https://github.com/Tony0410/nextstep.git
synced 2026-05-24 21:31:43 +08:00
69 lines
1.9 KiB
Docker
69 lines
1.9 KiB
Docker
# Stage 1: Dependencies
|
|
FROM node:20-slim AS deps
|
|
RUN apt-get update && apt-get install -y openssl build-essential python3 && rm -rf /var/lib/apt/lists/*
|
|
WORKDIR /app
|
|
|
|
COPY package.json package-lock.json* ./
|
|
COPY prisma ./prisma/
|
|
|
|
RUN npm ci
|
|
|
|
# Stage 2: Builder
|
|
FROM node:20-slim AS builder
|
|
RUN apt-get update && apt-get install -y openssl && rm -rf /var/lib/apt/lists/*
|
|
WORKDIR /app
|
|
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
COPY . .
|
|
|
|
# Generate Prisma client
|
|
RUN npx prisma generate
|
|
|
|
# Build the application
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
ENV NODE_ENV=production
|
|
|
|
# Build args for NEXT_PUBLIC_* variables (needed at build time)
|
|
ARG NEXT_PUBLIC_VAPID_PUBLIC_KEY
|
|
ENV NEXT_PUBLIC_VAPID_PUBLIC_KEY=${NEXT_PUBLIC_VAPID_PUBLIC_KEY}
|
|
|
|
RUN npm run build
|
|
|
|
# Stage 3: Runner (using slim Debian for better OpenSSL compatibility)
|
|
FROM node:20-slim AS runner
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
ENV TZ=Australia/Perth
|
|
|
|
RUN addgroup --system --gid 1001 nodejs
|
|
RUN adduser --system --uid 1001 nextjs
|
|
|
|
# Install OpenSSL and CA certificates for Prisma
|
|
RUN apt-get update && apt-get install -y openssl ca-certificates wget && rm -rf /var/lib/apt/lists/*
|
|
|
|
COPY --from=builder /app/public ./public
|
|
COPY --from=builder /app/prisma ./prisma
|
|
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
|
|
COPY --from=builder /app/node_modules/argon2 ./node_modules/argon2
|
|
COPY --from=builder /app/node_modules/node-gyp-build ./node_modules/node-gyp-build
|
|
|
|
# Set the correct permission for prerender cache
|
|
RUN mkdir .next
|
|
RUN chown nextjs:nodejs .next
|
|
|
|
# Automatically leverage output traces to reduce image size
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
|
|
USER nextjs
|
|
|
|
EXPOSE 3000
|
|
|
|
ENV PORT=3000
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
# Start the app (run migrations separately with: docker exec nextstep-app npx prisma migrate deploy)
|
|
CMD ["node", "server.js"]
|