From 2fc9835a6a0fe9874d9fa85bd6195f48f1165793 Mon Sep 17 00:00:00 2001 From: TheCatLady <52870424+TheCatLady@users.noreply.github.com> Date: Mon, 3 May 2021 09:13:23 -0400 Subject: [PATCH] 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 --- .github/workflows/ci.yml | 7 +------ .github/workflows/preview.yml | 16 ---------------- .github/workflows/release.yml | 5 ----- .github/workflows/snap.yaml | 5 ----- Dockerfile | 27 +++++++++++++++------------ 5 files changed, 16 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d10c4396a..7e1212b53 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,11 +16,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - - name: Use Next.js cache - uses: actions/cache@v2.1.0 - with: - path: ${{ github.workspace }}/.next/cache - key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package.json') }} - name: Install dependencies env: HUSKY_SKIP_INSTALL: 1 @@ -75,7 +70,7 @@ jobs: ghcr.io/sct/overseerr:develop ghcr.io/sct/overseerr:${{ github.sha }} cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-new + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max - # Temporary fix # https://github.com/docker/build-push-action/issues/252 # https://github.com/moby/buildkit/issues/1896 diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index a162593a2..9f05f86e8 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -19,13 +19,6 @@ jobs: uses: docker/setup-qemu-action@v1 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - - name: Cache Docker layers - uses: actions/cache@v2.1.5 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - name: Log in to Docker Hub uses: docker/login-action@v1 with: @@ -49,12 +42,3 @@ jobs: tags: | sctx/overseerr:${{ steps.get_version.outputs.VERSION }} ghcr.io/sct/overseerr:${{ steps.get_version.outputs.VERSION }} - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-new - - # Temporary fix - # https://github.com/docker/build-push-action/issues/252 - # https://github.com/moby/buildkit/issues/1896 - name: Move cache - run: | - rm -rf /tmp/.buildx-cache - mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 92461862f..8ff0fbb77 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,11 +13,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - - name: Use Next.js cache - uses: actions/cache@v2.1.0 - with: - path: ${{ github.workspace }}/.next/cache - key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package.json') }} - name: Install dependencies env: HUSKY_SKIP_INSTALL: 1 diff --git a/.github/workflows/snap.yaml b/.github/workflows/snap.yaml index f1620cd8d..b0b5a3992 100644 --- a/.github/workflows/snap.yaml +++ b/.github/workflows/snap.yaml @@ -24,11 +24,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - - name: Cache Next.js build - uses: actions/cache@v2.1.0 - with: - path: ${{ github.workspace }}/.next/cache - key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package.json') }} - name: Install dependencies env: HUSKY_SKIP_INSTALL: 1 diff --git a/Dockerfile b/Dockerfile index 9a5af8ca7..eda37b312 100644 --- a/Dockerfile +++ b/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" ]