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
This commit is contained in:
2026-05-17 04:38:50 -07:00
parent 954abb0939
commit 61be5efadc
2 changed files with 46 additions and 0 deletions
+38
View File
@@ -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} \
.
+8
View File
@@ -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 \