From 3a379824b87f838915eb5f36704ca23bb1e36bcd Mon Sep 17 00:00:00 2001 From: Joshua Lanese Date: Mon, 14 Oct 2024 21:23:34 -0700 Subject: [PATCH] Dashboard Dockerfile --- dashboard/Dockerfile | 43 +++++++++++++++++++++++++++++++++------- dashboard/next.config.js | 1 + 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/dashboard/Dockerfile b/dashboard/Dockerfile index cc6172e2..f4305a43 100644 --- a/dashboard/Dockerfile +++ b/dashboard/Dockerfile @@ -1,17 +1,46 @@ -FROM node:21 as build +# Derived from +# https://github.com/vercel/next.js/blob/4b9ef1eb23f9d247321c9368d08c2398b6ec8169/examples/with-docker/Dockerfile +FROM node:21-alpine AS base +FROM base AS deps WORKDIR /app -ENV NODE_ENV production - COPY package*.json /app/ RUN npm ci --legacy-peer-deps -COPY . ./ +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . + RUN npm run build -FROM nginx +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV production + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public + +# Set the correct permission for prerender cache +RUN mkdir .next +RUN chown nextjs:nodejs .next + +# 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 3001 -WORKDIR /usr/share/nginx/html +ENV PORT=3001 -COPY --from=build /app/out/ ./ +# server.js is created by next build from the standalone output +# https://nextjs.org/docs/pages/api-reference/next-config-js/output +ENV HOSTNAME="0.0.0.0" +CMD ["node", "server.js"] diff --git a/dashboard/next.config.js b/dashboard/next.config.js index 326ec400..ff60f8c0 100644 --- a/dashboard/next.config.js +++ b/dashboard/next.config.js @@ -22,4 +22,5 @@ module.exports = { }, ]; }, + output: 'standalone' };