From 71fc972c77eb0c659aaebdeedb6e8d67cf819f1e Mon Sep 17 00:00:00 2001 From: Thomas Gloor Date: Sun, 18 Oct 2026 20:34:56 +0200 Subject: [PATCH] Add no-cache input; push step builds from local cache only - no-cache input for scheduled rebuilds that must pick up new packages - The push step no longer reads the registry cache, only the layers the scan step just built, so the pushed image is the scanned one even on no-cache runs - Put --build-arg back on its own line Co-Authored-By: Claude Opus 5.5 --- .gitea/workflows/docker-build.yml | 21 ++++++++++++++++----- README.md | 1 + 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/docker-build.yml b/.gitea/workflows/docker-build.yml index e4d2867..fd3872a 100644 --- a/.gitea/workflows/docker-build.yml +++ b/.gitea/workflows/docker-build.yml @@ -18,6 +18,10 @@ on: description: 'Path to the Dockerfile (default: /Dockerfile)' type: string default: '' + no-cache: + description: 'Build without cache, e.g. for scheduled rebuilds that must pick up new packages' + type: boolean + default: false severity: description: 'Trivy severities that fail the build' type: string @@ -84,12 +88,18 @@ jobs: FILE: ${{ inputs.file }} SEVERITY: ${{ inputs.severity }} VERSION: ${{ steps.meta.outputs.version }} + NO_CACHE: ${{ inputs.no-cache }} TRIVY_SERVER: ${{ vars.TRIVY_SERVER || 'http://localhost:4954' }} TRIVY_TOKEN: ${{ secrets.TRIVY_TOKEN }} run: | set -euo pipefail FILE="${FILE:-$CONTEXT/Dockerfile}" IFS=',' read -ra platforms <<< "$PLATFORMS" + if [ "$NO_CACHE" = "true" ]; then + cache_args=(--no-cache) + else + cache_args=(--cache-from "type=registry,ref=$IMAGE:buildcache") + fi status=0 for platform in "${platforms[@]}"; do @@ -97,8 +107,9 @@ jobs: echo "::group::Build $platform" docker buildx build --platform "$platform" --load --pull \ - --file "$FILE" --tag "$tag" --build-arg "VERSION=$VERSION" \ - --cache-from "type=registry,ref=$IMAGE:buildcache" \ + --file "$FILE" --tag "$tag" \ + --build-arg "VERSION=$VERSION" \ + "${cache_args[@]}" \ "$CONTEXT" echo "::endgroup::" @@ -119,8 +130,9 @@ jobs: exit $status - # Reuses the layers built above, so this mostly assembles and uploads. - # pull: false keeps the base images identical to the ones just scanned. + # Builds only from the builder's local cache, i.e. the layers built and + # scanned above (no cache-from), so it mostly assembles and uploads and + # the pushed image is the scanned one. pull: false keeps the base images. - name: Build and push uses: docker/build-push-action@v7 with: @@ -133,5 +145,4 @@ jobs: labels: ${{ steps.meta.outputs.labels }} build-args: | VERSION=${{ steps.meta.outputs.version }} - cache-from: type=registry,ref=${{ env.IMAGE }}:buildcache cache-to: type=registry,ref=${{ env.IMAGE }}:buildcache,mode=max diff --git a/README.md b/README.md index 496bfe2..cdedee7 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ For x64 and arm64 (Raspberry Pi), add: | `platforms` | `linux/amd64` | Comma-separated target platforms. Any `arm` platform enables QEMU emulation. | | `context` | `.` | Docker build context. | | `file` | `/Dockerfile` | Path to the Dockerfile. | +| `no-cache` | `false` | Build without cache. Use `${{ gitea.event_name == 'schedule' }}` so weekly rebuilds pick up new packages. | | `severity` | `CRITICAL,HIGH` | Severities that fail the build. Vulnerabilities without a fixed version never fail it. | | `runs-on` | `linux-amd64` | Runner label. |