From 377b6558f0e2d63446158430145c08700259fe21 Mon Sep 17 00:00:00 2001 From: Jim O'Donnell Date: Tue, 19 Nov 2024 09:27:46 +0000 Subject: [PATCH] Optimise the Docker build - Add the lockfile last, so that previous layers are cached. - Copy files from the builder to the production app runner. --- Dockerfile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 32f527ef1b..7290d997a5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,8 +30,6 @@ WORKDIR /usr/src/ ADD package.json /usr/src/ -ADD yarn.lock /usr/src/ - COPY .yarn /usr/src/.yarn ADD .yarnrc /usr/src/ @@ -40,6 +38,8 @@ ADD lerna.json /usr/src/ COPY ./packages /usr/src/packages +ADD yarn.lock /usr/src/ + RUN chown -R node:node . USER node @@ -64,16 +64,16 @@ RUN mkdir -p /usr/src WORKDIR /usr/src/ -ADD package.json /usr/src/ - -ADD yarn.lock /usr/src/ +COPY --from=builder /usr/src/package.json /usr/src/package.json -COPY .yarn /usr/src/.yarn +COPY --from=builder /usr/src/.yarn /usr/src/.yarn -ADD .yarnrc /usr/src/ +COPY --from=builder /usr/src/.yarnrc /usr/src/.yarnrc COPY --from=builder /usr/src/packages ./packages +COPY --from=builder /usr/src/yarn.lock /usr/src/yarn.lock + RUN --mount=type=cache,id=fem-runner-yarn,uid=1000,gid=1000,target=/home/node/.yarn YARN_CACHE_FOLDER=/home/node/.yarn yarn install --production --frozen-lockfile --ignore-scripts --prefer-offline RUN rm -rf /usr/src/packages/lib-react-components/src