From 61be5efadcea2392928ccc6757e10edc505685c7 Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Sun, 17 May 2026 04:38:50 -0700 Subject: [PATCH] feat: add actions/cache and Docker layer caching - actions/cache@v4 for node_modules across unit-tests and build jobs - Manual sha256sum key since Gitea lacks hashFiles() support - Docker BuildKit registry-based cache layers (--cache-from/--cache-to) - Both runners configured with their own cache server ports --- .gitea/workflows/pr.yml | 38 ++++++++++++++++++++++++++++++++++++ .gitea/workflows/release.yml | 8 ++++++++ 2 files changed, 46 insertions(+) diff --git a/.gitea/workflows/pr.yml b/.gitea/workflows/pr.yml index c557378..d1290fc 100644 --- a/.gitea/workflows/pr.yml +++ b/.gitea/workflows/pr.yml @@ -22,6 +22,21 @@ jobs: - name: Checkout code uses: actions/checkout@v4 + - name: Compute dependency cache key + id: npm-key + run: | + echo "hash=$(sha256sum package-lock.json | cut -d' ' -f1)" >> $GITHUB_OUTPUT + + - name: Cache node_modules + uses: actions/cache@v4 + with: + path: | + node_modules + ~/.npm + key: npm-${{ runner.os }}-${{ steps.npm-key.outputs.hash }} + restore-keys: | + npm-${{ runner.os }}- + - name: Install dependencies run: npm ci --legacy-peer-deps @@ -46,6 +61,21 @@ jobs: # Required for acceptance tests - they import prisma via @/ path alias # and @cucumber/cucumber for cucumber-e2e tests + - name: Compute dependency cache key + id: npm-key + run: | + echo "hash=$(sha256sum package-lock.json | cut -d' ' -f1)" >> $GITHUB_OUTPUT + + - name: Cache node_modules + uses: actions/cache@v4 + with: + path: | + node_modules + ~/.npm + key: npm-${{ runner.os }}-${{ steps.npm-key.outputs.hash }} + restore-keys: | + npm-${{ runner.os }}- + - name: Install dependencies run: npm ci --legacy-peer-deps @@ -60,11 +90,19 @@ jobs: echo "pr_number=$(echo $GITHUB_REF | grep -oP 'refs/pull/\K[0-9]+')" >> $GITHUB_OUTPUT echo "short_sha=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_OUTPUT + - name: Login to Registry + run: | + docker login ${{ env.REGISTRY }} -u ${{ secrets.DOCKER_LOGIN }} -p ${{ secrets.DOCKER_PASSWORD }} + - name: Build Docker image for PR + env: + DOCKER_BUILDKIT: 1 run: | IMAGE_TAG="pr-${{ steps.info.outputs.pr_number }}-${{ steps.info.outputs.short_sha }}" docker build \ --target runner \ + --cache-from type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:cache \ + --cache-to type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:cache,mode=max \ --build-arg GIT_COMMIT=$GITHUB_SHA \ -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${IMAGE_TAG} \ . diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index caa9890..b4ca687 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -109,9 +109,13 @@ jobs: - name: Build test-capable image if: steps.commit.outputs.committed == 'true' + env: + DOCKER_BUILDKIT: 1 run: | docker build \ --target test-runner \ + --cache-from type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:cache-test \ + --cache-to type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:cache-test,mode=max \ --build-arg GIT_COMMIT=${{ github.sha }} \ -t ${{ env.IMAGE_NAME }}-test:${{ steps.version.outputs.new_version }} \ . @@ -127,9 +131,13 @@ jobs: - name: Build production image if: steps.commit.outputs.committed == 'true' + env: + DOCKER_BUILDKIT: 1 run: | docker build \ --target runner \ + --cache-from type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:cache \ + --cache-to type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:cache,mode=max \ --build-arg GIT_COMMIT=${{ github.sha }} \ -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.new_version }} \ -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \