From 47de3c4f54e854a1939d5ec73187b3482a58b3b1 Mon Sep 17 00:00:00 2001 From: Valtteri Kantanen Date: Mon, 18 Nov 2024 19:18:02 +0200 Subject: [PATCH] Implement multi-stage build in Dockerfile --- Dockerfile | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4f5cf52..8accb1c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,32 @@ -FROM registry.access.redhat.com/ubi9/nodejs-18-minimal +FROM registry.access.redhat.com/ubi9/nodejs-18-minimal AS build ENV TZ="Europe/Helsinki" WORKDIR /opt/app-root/src -# Setup -COPY package* ./ +COPY package*.json ./ COPY tsconfig.json ./ -RUN npm ci -f --omit-dev --ignore-scripts + +RUN npm ci + COPY src ./src -# Build RUN npm run build + +FROM registry.access.redhat.com/ubi9/nodejs-18-minimal + +ENV TZ="Europe/Helsinki" + +ENV NODE_ENV=production + +WORKDIR /opt/app-root/src + +COPY --from=build /opt/app-root/src/package*.json ./ +COPY --from=build /opt/app-root/src/build ./build + +RUN npm ci + EXPOSE 3003 -CMD ["npm", "run", "start:prod"] +CMD ["node", "build/index.js"]