diff --git a/.github/workflows/build-push-ghcr.yml b/.github/workflows/build-push-ghcr.yml index 5d496c5..d8b6155 100644 --- a/.github/workflows/build-push-ghcr.yml +++ b/.github/workflows/build-push-ghcr.yml @@ -26,31 +26,42 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 # Setup QEMU: https://github.com/docker/setup-qemu-action - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 with: platforms: 'arm64' # Workaround: https://github.com/docker/build-push-action/issues/461 - name: Setup Docker buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v6 with: install: true - name: Cache Docker layers - uses: actions/cache@v2 + uses: actions/cache@v4 with: - path: /tmp/.buildx-cache + path: | + /tmp/.buildx-cache + pnpm-store # Key is named differently to avoid collision - key: ${{ runner.os }}-multi-buildx-${{ github.sha }} + key: ${{ runner.os }}-multi-buildx-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('Dockerfile') }} restore-keys: | ${{ runner.os }}-multi-buildx + + - name: inject cache into docker + uses: reproducible-containers/buildkit-cache-dance@v3.1.0 + with: + cache-map: | + { + "pnpm-store": "/pnpm/store" + } + skip-extraction: ${{ steps.cache.outputs.cache-hit }} - name: Log in to the Container registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} @@ -58,7 +69,7 @@ jobs: - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | @@ -68,7 +79,7 @@ jobs: type=sha - name: Build and push Docker image - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v6 with: context: . push: true @@ -80,9 +91,4 @@ jobs: # More: https://github.com/moby/buildkit#--export-cache-options # And: https://github.com/docker/buildx#--cache-tonametypetypekeyvalue cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new - - # prevents running out of space - - name: Move cache - run: | - rm -rf /tmp/.buildx-cache - mv /tmp/.buildx-cache-new /tmp/.buildx-cache \ No newline at end of file + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 3ea191f..3742435 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,18 @@ FROM node:lts-slim AS base - ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" RUN corepack enable - -FROM base AS prod - -COPY pnpm-lock.yaml /app +COPY . /app WORKDIR /app -RUN pnpm fetch --prod -COPY . /app +FROM base AS prod-deps +RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile + +FROM base AS build +RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile RUN pnpm run build FROM base -COPY --from=prod /app/node_modules /app/node_modules -COPY --from=prod /app/dist /app/dist +COPY --from=prod-deps /app/node_modules /app/node_modules +COPY --from=build /app/dist /app/dist CMD [ "pnpm", "start" ] \ No newline at end of file