From 803fd927c981eb02a866033623bd0d0076b4e419 Mon Sep 17 00:00:00 2001 From: Rasmus Rosengren Date: Sun, 4 Jun 2023 10:03:48 +0200 Subject: [PATCH] dockerfile --- frontend/Dockerfile | 56 +++++++++++++++++++++++++++++++++++------ frontend/next.config.js | 1 + 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 6f08299..74f79ef 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,12 +1,54 @@ -FROM node:latest as build +# https://github.com/vercel/next.js/blob/v13.4.3/examples/with-docker/Dockerfile +FROM node:18-alpine AS base +# Install dependencies only when needed +FROM base AS deps +# 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 + +# Install dependencies based on the preferred package manager +COPY package.json package-lock.json ./ +RUN npm ci + +# Rebuild the source code only when needed +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules COPY . . -ENV NODE_ENV=development -RUN npm install -ENV NODE_ENV=production + +# Next.js collects completely anonymous telemetry data about general usage. +# Learn more here: https://nextjs.org/telemetry +# Uncomment the following line in case you want to disable telemetry during the build. +# ENV NEXT_TELEMETRY_DISABLED 1 + +# RUN yarn build + +# If using npm comment out above and use below instead RUN npm run build -RUN rm -rf node_modules -RUN npm install + +# Production image, copy all the files and run next +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV production +# Uncomment the following line in case you want to disable telemetry during runtime. +# ENV NEXT_TELEMETRY_DISABLED 1 + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public + +# 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 3000 -CMD npm run start + +ENV PORT 3000 + +CMD ["node", "server.js"] \ No newline at end of file diff --git a/frontend/next.config.js b/frontend/next.config.js index 91ef62f..793352b 100644 --- a/frontend/next.config.js +++ b/frontend/next.config.js @@ -1,6 +1,7 @@ /** @type {import('next').NextConfig} */ const nextConfig = { reactStrictMode: true, + output: "standalone", }; module.exports = nextConfig;