From 267e279cf2f2ffa0f359a5326abefbe26a2faedb Mon Sep 17 00:00:00 2001 From: Jennie Robinson Faber Date: Sat, 23 Aug 2025 14:28:26 +0100 Subject: [PATCH] Refactor Dockerfile for multi-stage build and update start script in package.json - Introduced a multi-stage build in the Dockerfile to separate build and runtime environments. - Added environment variables for production in the runtime stage. - Updated the start script in package.json to point to the new server entry point. --- Dockerfile | 20 +++++++++++++++----- package.json | 3 ++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 35d7f94..b946a47 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,21 @@ -FROM node:22.12-bullseye - +# --- build stage --- +FROM node:22.12-bullseye AS build WORKDIR /app - COPY package.json yarn.lock ./ RUN corepack enable && yarn install --frozen-lockfile - COPY . . RUN yarn build -CMD ["yarn", "start"] +# --- runtime stage --- +FROM node:22.12-bullseye AS runner +WORKDIR /app +ENV NODE_ENV=production \ + NITRO_HOST=0.0.0.0 \ + NITRO_PORT=3000 \ + HOST=0.0.0.0 \ + PORT=3000 +COPY --from=build /app/.output ./.output +# (Optional) copy any public/static if you need it at runtime: +# COPY --from=build /app/public ./public +EXPOSE 3000 +CMD ["node", ".output/server/index.mjs"] diff --git a/package.json b/package.json index 80c8b49..cc19e43 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "dev": "nuxt dev", "generate": "nuxt generate", "preview": "nuxt preview", - "postinstall": "nuxt prepare" + "postinstall": "nuxt prepare", + "start": "node .output/server/index.mjs" }, "dependencies": { "mongodb": "^6.18.0",