Skip to content

Commit

Permalink
feat: use separate rebuild stage
Browse files Browse the repository at this point in the history
  • Loading branch information
oplik0 committed Sep 23, 2023
1 parent 65fdc56 commit 6c0d1b4
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@ USER node

RUN npm install --omit=dev


FROM node:lts-slim
FROM node:lts as rebuild

ARG BUILDPLATFORM
ARG TARGETPLATFORM

RUN mkdir -p /usr/src/build && \
chown -R node:node /usr/src/build

COPY --from=npm /usr/src/build /usr/src/build

RUN if [ $BUILDPLATFORM != $TARGETPLATFORM ]; then \
npm rebuild && \
npm cache clean --force; fi

FROM node:lts-slim as run

ARG NODE_ENV
ENV NODE_ENV=$NODE_ENV \
Expand All @@ -28,15 +37,11 @@ ENV NODE_ENV=$NODE_ENV \
RUN mkdir -p /usr/src/app && \
chown -R node:node /usr/src/app

COPY --chown=node:node --from=npm /usr/src/build /usr/src/app
COPY --chown=node:node --from=rebuild /usr/src/build /usr/src/app


WORKDIR /usr/src/app

RUN if [ $BUILDPLATFORM != $TARGETPLATFORM ]; then \
npm rebuild && \
npm cache clean --force; fi

USER node

COPY --chown=node:node . /usr/src/app
Expand Down

0 comments on commit 6c0d1b4

Please sign in to comment.