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. |