From 44af6b6ba0b1fef87cbd1c2ae7709b3b0e9fe04b Mon Sep 17 00:00:00 2001 From: Niall Thomson Date: Thu, 10 Oct 2024 14:09:40 -0600 Subject: [PATCH 1/2] chore: multi-stage build for checkout --- src/checkout/Dockerfile | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/checkout/Dockerfile b/src/checkout/Dockerfile index f74f79ee5..2370a1538 100644 --- a/src/checkout/Dockerfile +++ b/src/checkout/Dockerfile @@ -1,3 +1,12 @@ +FROM node:20-alpine AS build +WORKDIR /usr/src/app +COPY --chown=node:node package*.json ./ +COPY --chown=node:node . . +RUN npm run build +RUN npm ci -f && npm cache clean --force +USER node + + FROM public.ecr.aws/amazonlinux/amazonlinux:2023 # We tell DNF not to install Recommends and Suggests packages, which are @@ -26,12 +35,7 @@ RUN useradd \ WORKDIR /app USER appuser -COPY --chown=appuser:appuser package.json . -COPY --chown=appuser:appuser package-lock.json . - -RUN npm ci - -ADD . /app -RUN npm run build +COPY --chown=node:node --from=build /usr/src/app/node_modules ./node_modules +COPY --chown=node:node --from=build /usr/src/app/dist ./dist -ENTRYPOINT [ "node", "dist/main.js" ] +ENTRYPOINT [ "node", "dist/main.js" ] \ No newline at end of file From 7b68618660a37462f2b738d23bff243309437c26 Mon Sep 17 00:00:00 2001 From: Niall Thomson Date: Thu, 10 Oct 2024 14:19:52 -0600 Subject: [PATCH 2/2] Fix npm command order --- src/checkout/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/checkout/Dockerfile b/src/checkout/Dockerfile index 2370a1538..f8629bbcd 100644 --- a/src/checkout/Dockerfile +++ b/src/checkout/Dockerfile @@ -2,8 +2,8 @@ FROM node:20-alpine AS build WORKDIR /usr/src/app COPY --chown=node:node package*.json ./ COPY --chown=node:node . . +RUN npm ci -f RUN npm run build -RUN npm ci -f && npm cache clean --force USER node @@ -14,7 +14,6 @@ FROM public.ecr.aws/amazonlinux/amazonlinux:2023 # packages as minimal as possible. RUN dnf --setopt=install_weak_deps=False install -q -y \ nodejs20 \ - npm \ shadow-utils \ && \ dnf clean all