Skip to content

Commit

Permalink
Optimise the Docker build
Browse files Browse the repository at this point in the history
- Add the lockfile last, so that previous layers are cached.
- Copy files from the builder to the production app runner.
  • Loading branch information
eatyourgreens committed Nov 19, 2024
1 parent 0f24ff5 commit 377b655
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 377b655

Please sign in to comment.