From 6fa73ec21496d6edee1189366f2365cc4cd1e1ec Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Wed, 11 Jan 2023 18:55:28 +0000 Subject: [PATCH] Install npm deps in separate docker layer --- Dockerfile | 11 ++++++++--- Dockerfile-dev | 7 ++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index f9e32313..b0ec5128 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,14 @@ FROM docker.io/node:alpine as builder RUN apk add --no-cache git python3 build-base -COPY . /app + WORKDIR /app -RUN yarn install \ - && yarn build + +# Copy package.json and yarn.lock and install dependencies first to speed up subsequent builds +COPY package.json yarn.lock /app/ +RUN yarn install + +COPY . /app +RUN yarn build FROM docker.io/nginx:alpine COPY --from=builder /app/target /usr/share/nginx/html diff --git a/Dockerfile-dev b/Dockerfile-dev index 08dd9abd..7212a4ae 100644 --- a/Dockerfile-dev +++ b/Dockerfile-dev @@ -1,7 +1,12 @@ FROM docker.io/node:alpine RUN apk add --no-cache git python3 build-base -COPY . /code + WORKDIR /code + +# Copy package.json and yarn.lock and install dependencies first to speed up subsequent builds +COPY package.json yarn.lock /code/ RUN yarn install + +COPY . /code EXPOSE 3000 ENTRYPOINT ["yarn", "start"]