build(docker): refactor Dockerfile to enable caching of node_modules (#1550)
* ci: revert actions/cache version change and install GNU tar * ci: do not potentially destroy Docker cache while building preview images * build(docker): refactor Dockerfile to cache node_modules * ci: remove Next.js caching * build(docker): don't break arm builds
This commit is contained in:
27
Dockerfile
27
Dockerfile
@@ -1,28 +1,30 @@
|
||||
FROM node:14.16-alpine AS BUILD_IMAGE
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ARG TARGETPLATFORM
|
||||
ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64}
|
||||
|
||||
ARG COMMIT_TAG
|
||||
ENV COMMIT_TAG=${COMMIT_TAG}
|
||||
|
||||
COPY . /app
|
||||
WORKDIR /app
|
||||
|
||||
RUN \
|
||||
case "${TARGETPLATFORM}" in \
|
||||
'linux/arm64') apk add --no-cache python make g++ ;; \
|
||||
'linux/arm/v7') apk add --no-cache python make g++ ;; \
|
||||
esac
|
||||
|
||||
RUN yarn --frozen-lockfile --network-timeout 1000000 && \
|
||||
yarn build
|
||||
COPY package.json yarn.lock ./
|
||||
RUN yarn install --frozen-lockfile --network-timeout 1000000
|
||||
|
||||
COPY . ./
|
||||
|
||||
ARG COMMIT_TAG
|
||||
ENV COMMIT_TAG=${COMMIT_TAG}
|
||||
|
||||
RUN yarn build
|
||||
|
||||
# remove development dependencies
|
||||
RUN yarn install --production --ignore-scripts --prefer-offline
|
||||
|
||||
RUN rm -rf src && \
|
||||
rm -rf server
|
||||
RUN rm -rf src server
|
||||
|
||||
RUN touch config/DOCKER
|
||||
|
||||
@@ -31,11 +33,12 @@ RUN echo "{\"commitTag\": \"${COMMIT_TAG}\"}" > committag.json
|
||||
|
||||
FROM node:14.16-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN apk add --no-cache tzdata tini
|
||||
|
||||
# copy from build image
|
||||
COPY --from=BUILD_IMAGE /app /app
|
||||
WORKDIR /app
|
||||
COPY --from=BUILD_IMAGE /app ./
|
||||
|
||||
ENTRYPOINT [ "/sbin/tini", "--" ]
|
||||
CMD [ "yarn", "start" ]
|
||||
|
||||
Reference in New Issue
Block a user