2022-12-03 20:02:24 +00:00
|
|
|
## INIT STEP
|
|
|
|
# Install dependencies only when needed
|
|
|
|
FROM node:16-alpine AS deps
|
|
|
|
|
|
|
|
RUN apk add --no-cache libc6-compat
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
# Copy the files needed to install deps
|
|
|
|
COPY package.json yarn.lock ./
|
|
|
|
RUN yarn install --frozen-lockfile
|
|
|
|
|
|
|
|
## BUILD STEP
|
|
|
|
# Rebuild the source code only when needed
|
|
|
|
FROM node:16-alpine AS builder
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
# Copy node_modules installed by the deps step
|
|
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
|
|
|
|
|
|
COPY . .
|
|
|
|
|
|
|
|
RUN yarn build
|
|
|
|
|
|
|
|
## RUN STEP
|
|
|
|
FROM node:16-alpine AS runner
|
|
|
|
|
|
|
|
LABEL author="neshura@proton.me"
|
2023-01-14 20:11:42 +00:00
|
|
|
WORKDIR /usr/src/app
|
2022-12-03 20:02:24 +00:00
|
|
|
|
|
|
|
ENV NODE_ENV production
|
|
|
|
|
|
|
|
RUN addgroup --system --gid 1001 nodejs
|
|
|
|
RUN adduser --system --uid 1001 nextjs
|
|
|
|
|
|
|
|
COPY --from=builder /app/public ./public
|
|
|
|
COPY --from=builder /app/node_modules ./node_modules
|
|
|
|
|
|
|
|
# Automatically leverage output traces to reduce image size
|
|
|
|
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
|
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
|
|
|
|
|
|
USER nextjs
|
|
|
|
|
|
|
|
# expose port 3000
|
|
|
|
ENV PORT 3000
|
|
|
|
EXPOSE 3000
|
|
|
|
|
|
|
|
CMD [ "yarn", "start" ]
|