2022-10-31 21:28:27 +00:00
|
|
|
# Thanks @yordis on Github! https://github.com/vercel/next.js/discussions/16995#discussioncomment-132339
|
|
|
|
|
|
|
|
# Install dependencies only when needed
|
|
|
|
FROM node:lts-alpine AS deps
|
|
|
|
|
|
|
|
WORKDIR /opt/app
|
2023-01-28 16:38:28 +00:00
|
|
|
COPY package.json pnpm-lock.yaml ./
|
2023-03-20 02:46:32 +00:00
|
|
|
RUN npm install -g pnpm
|
2023-01-28 16:38:28 +00:00
|
|
|
RUN pnpm install --frozen-lockfile
|
2022-10-31 21:28:27 +00:00
|
|
|
|
|
|
|
# Rebuild the source code only when needed
|
|
|
|
# This is where because may be the case that you would try
|
|
|
|
# to build the app based on some `X_TAG` in my case (Git commit hash)
|
|
|
|
# but the code hasn't changed.
|
|
|
|
FROM node:lts-alpine AS builder
|
|
|
|
|
|
|
|
ENV NODE_ENV=production
|
|
|
|
WORKDIR /opt/app
|
2023-03-20 02:46:32 +00:00
|
|
|
RUN npm install -g pnpm
|
2022-10-31 21:28:27 +00:00
|
|
|
COPY . .
|
|
|
|
COPY --from=deps /opt/app/node_modules ./node_modules
|
2023-01-28 16:38:28 +00:00
|
|
|
RUN pnpm build
|
2022-10-31 21:28:27 +00:00
|
|
|
|
|
|
|
# Production image, copy all the files and run next
|
2023-03-20 02:46:32 +00:00
|
|
|
FROM gcr.io/distroless/nodejs18-debian11 AS runner
|
2022-10-31 21:28:27 +00:00
|
|
|
ARG X_TAG
|
|
|
|
WORKDIR /opt/app
|
|
|
|
ENV NODE_ENV=production
|
|
|
|
COPY --from=builder /opt/app/next.config.mjs ./
|
|
|
|
COPY --from=builder /opt/app/public ./public
|
|
|
|
COPY --from=builder /opt/app/.next ./.next
|
|
|
|
COPY --from=builder /opt/app/node_modules ./node_modules
|
|
|
|
ENV HOST=0.0.0.0
|
|
|
|
ENV PORT=3000
|
2023-03-20 02:46:32 +00:00
|
|
|
CMD ["./node_modules/next/dist/bin/next", "start"]
|