perf(docker): optimize runner stage build time
Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 15m0s
Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 15m0s
This commit is contained in:
43
Dockerfile
43
Dockerfile
@@ -26,34 +26,37 @@ RUN npm run build
|
|||||||
# Stage 3: Runner
|
# Stage 3: Runner
|
||||||
FROM node:20-alpine AS runner
|
FROM node:20-alpine AS runner
|
||||||
RUN apk add --no-cache openssl
|
RUN apk add --no-cache openssl
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
ENV NODE_ENV production
|
ENV NODE_ENV production
|
||||||
ENV NEXT_TELEMETRY_DISABLED 1
|
ENV NEXT_TELEMETRY_DISABLED 1
|
||||||
|
|
||||||
RUN addgroup --system --gid 1001 nodejs
|
RUN addgroup --system --gid 1001 nodejs && \
|
||||||
RUN adduser --system --uid 1001 nextjs
|
adduser --system --uid 1001 nextjs
|
||||||
|
|
||||||
COPY --from=builder /app/public ./public
|
WORKDIR /app
|
||||||
COPY --from=builder /app/.next/standalone ./
|
# Fast: only chown the /app directory itself, not recursively
|
||||||
COPY --from=builder /app/.next/static ./.next/static
|
RUN chown nextjs:nodejs /app
|
||||||
COPY --from=builder /app/.env ./.env
|
|
||||||
COPY --from=builder /app/prisma ./prisma
|
|
||||||
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
|
|
||||||
COPY --from=builder /app/node_modules/prisma ./node_modules/prisma
|
|
||||||
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
|
|
||||||
COPY --from=builder /app/node_modules/.bin/prisma ./node_modules/.bin/prisma
|
|
||||||
COPY --from=builder /app/node_modules/bcryptjs ./node_modules/bcryptjs
|
|
||||||
COPY --from=builder /app/node_modules/stripe ./node_modules/stripe
|
|
||||||
COPY --from=builder /app/package.json ./package.json
|
|
||||||
RUN npm install --omit=dev --legacy-peer-deps socket.io@4.7.4 @react-pdf/renderer@4.3.2 qrcode@1.5.4 --no-save
|
|
||||||
COPY server-custom.js ./server-custom.js
|
|
||||||
COPY docker-entrypoint.sh ./docker-entrypoint.sh
|
|
||||||
|
|
||||||
RUN chown -R nextjs:nodejs /app/node_modules
|
|
||||||
|
|
||||||
USER nextjs
|
USER nextjs
|
||||||
|
|
||||||
|
# Install only the unbundled runtime deps needed by the custom server.
|
||||||
|
# Running as USER nextjs means files are already correctly owned — no slow chown -R needed afterwards.
|
||||||
|
RUN npm install --omit=dev --legacy-peer-deps socket.io@4.7.4 @react-pdf/renderer@4.3.2 qrcode@1.5.4 --no-save
|
||||||
|
|
||||||
|
COPY --chown=nextjs:nodejs --from=builder /app/public ./public
|
||||||
|
COPY --chown=nextjs:nodejs --from=builder /app/.next/standalone ./
|
||||||
|
COPY --chown=nextjs:nodejs --from=builder /app/.next/static ./.next/static
|
||||||
|
COPY --chown=nextjs:nodejs --from=builder /app/.env ./.env
|
||||||
|
COPY --chown=nextjs:nodejs --from=builder /app/prisma ./prisma
|
||||||
|
COPY --chown=nextjs:nodejs --from=builder /app/node_modules/.prisma ./node_modules/.prisma
|
||||||
|
COPY --chown=nextjs:nodejs --from=builder /app/node_modules/prisma ./node_modules/prisma
|
||||||
|
COPY --chown=nextjs:nodejs --from=builder /app/node_modules/@prisma ./node_modules/@prisma
|
||||||
|
COPY --chown=nextjs:nodejs --from=builder /app/node_modules/bcryptjs ./node_modules/bcryptjs
|
||||||
|
COPY --chown=nextjs:nodejs --from=builder /app/node_modules/stripe ./node_modules/stripe
|
||||||
|
COPY --chown=nextjs:nodejs --from=builder /app/package.json ./package.json
|
||||||
|
COPY --chown=nextjs:nodejs server-custom.js ./server-custom.js
|
||||||
|
COPY --chown=nextjs:nodejs docker-entrypoint.sh ./docker-entrypoint.sh
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
ENV PORT 3000
|
ENV PORT 3000
|
||||||
ENV HOSTNAME "0.0.0.0"
|
ENV HOSTNAME "0.0.0.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user