2022-05-24 12:13:49 +02:00
|
|
|
# Install dependencies only when needed
|
2023-03-12 20:45:46 +01:00
|
|
|
FROM --platform=linux/amd64 node:18-alpine AS deps
|
2022-05-24 12:13:49 +02:00
|
|
|
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
|
|
|
RUN apk add --no-cache libc6-compat
|
|
|
|
WORKDIR /app
|
|
|
|
COPY package.json yarn.lock ./
|
2023-03-12 19:53:49 +01:00
|
|
|
# Add yarn timeout to handle slow CPU when Github Actions
|
2023-03-12 18:35:36 +01:00
|
|
|
RUN yarn config set network-timeout 300000
|
2022-05-24 12:13:49 +02:00
|
|
|
RUN yarn install --frozen-lockfile
|
2022-02-19 05:00:21 +01:00
|
|
|
|
2022-05-24 12:13:49 +02:00
|
|
|
# Rebuild the source code only when needed
|
2023-03-12 19:53:49 +01:00
|
|
|
FROM --platform=linux/amd64 node:18-alpine AS builder
|
2022-05-24 12:13:49 +02:00
|
|
|
WORKDIR /app
|
|
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
|
|
COPY . .
|
2022-02-21 08:27:50 +01:00
|
|
|
|
2022-06-14 20:32:21 +02:00
|
|
|
ARG DATABASE_TYPE
|
2022-06-22 20:02:40 +02:00
|
|
|
ARG BASE_PATH
|
|
|
|
|
2022-06-14 20:32:21 +02:00
|
|
|
ENV DATABASE_TYPE $DATABASE_TYPE
|
2022-06-22 20:02:40 +02:00
|
|
|
ENV BASE_PATH $BASE_PATH
|
|
|
|
|
2022-05-24 12:13:49 +02:00
|
|
|
ENV NEXT_TELEMETRY_DISABLED 1
|
2020-09-22 14:30:37 +02:00
|
|
|
|
2022-08-23 19:49:45 +02:00
|
|
|
RUN yarn build-docker
|
2020-08-19 06:23:04 +02:00
|
|
|
|
2022-05-24 12:13:49 +02:00
|
|
|
# Production image, copy all the files and run next
|
2023-03-12 20:45:46 +01:00
|
|
|
FROM --platform=linux/amd64 node:18-alpine AS runner
|
2020-09-22 14:30:37 +02:00
|
|
|
WORKDIR /app
|
|
|
|
|
2022-05-24 12:13:49 +02:00
|
|
|
ENV NODE_ENV production
|
|
|
|
ENV NEXT_TELEMETRY_DISABLED 1
|
|
|
|
|
|
|
|
RUN addgroup --system --gid 1001 nodejs
|
|
|
|
RUN adduser --system --uid 1001 nextjs
|
2020-09-22 14:30:37 +02:00
|
|
|
|
2022-08-09 22:09:41 +02:00
|
|
|
RUN yarn add npm-run-all dotenv prisma
|
2022-06-12 08:38:58 +02:00
|
|
|
|
2022-05-24 12:13:49 +02:00
|
|
|
# You only need to copy next.config.js if you are NOT using the default configuration
|
2022-06-27 19:34:03 +02:00
|
|
|
COPY --from=builder /app/next.config.js .
|
2022-08-09 22:36:24 +02:00
|
|
|
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
2022-05-24 12:13:49 +02:00
|
|
|
COPY --from=builder /app/package.json ./package.json
|
2022-06-27 19:34:03 +02:00
|
|
|
COPY --from=builder /app/prisma ./prisma
|
|
|
|
COPY --from=builder /app/scripts ./scripts
|
2020-09-22 14:30:37 +02:00
|
|
|
|
2022-06-11 11:27:42 +02:00
|
|
|
# Automatically leverage output traces to reduce image size
|
2022-05-24 12:13:49 +02:00
|
|
|
# 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
|
2020-09-22 14:30:37 +02:00
|
|
|
|
2022-05-24 12:13:49 +02:00
|
|
|
USER nextjs
|
2020-09-22 14:30:37 +02:00
|
|
|
|
|
|
|
EXPOSE 3000
|
2022-05-24 12:13:49 +02:00
|
|
|
|
|
|
|
ENV PORT 3000
|
|
|
|
|
2022-06-22 10:50:33 +02:00
|
|
|
CMD ["yarn", "start-docker"]
|