From 2c16d55a0713fc4613b1415ad6b3857aaa1df1c5 Mon Sep 17 00:00:00 2001 From: Thomas Gloor Date: Mon, 26 Oct 2026 10:11:23 +0100 Subject: [PATCH] Add build-args input Extra NAME=value build args, passed to both the scanned and the pushed build, for repos that bake more than VERSION into the image. Co-Authored-By: Claude Opus 5.5 --- .gitea/workflows/docker-build.yml | 18 ++++++++++++++---- README.md | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/docker-build.yml b/.gitea/workflows/docker-build.yml index bf3c9b8..a10215b 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: '' + build-args: + description: 'Extra build args, one NAME=value per line (VERSION is always passed)' + type: string + default: '' no-cache: description: 'Build without cache, e.g. for scheduled rebuilds that must pick up new packages' type: boolean @@ -78,9 +82,9 @@ jobs: # Each platform is built into the local Docker daemon on its own (a # multi-platform image can't be loaded), scanned against the Trivy server, # and removed again. All platforms are scanned even if one fails, so the - # log shows every finding at once. VERSION is passed as a build arg (as in - # the push step) so the scanned image matches the pushed one; Dockerfiles - # that don't declare ARG VERSION ignore it. + # log shows every finding at once. VERSION and the build-args input are + # passed as in the push step so the scanned image matches the pushed one; + # Dockerfiles that don't declare ARG VERSION ignore it. - name: Build and scan with Trivy id: scan env: @@ -89,6 +93,7 @@ jobs: FILE: ${{ inputs.file }} SEVERITY: ${{ inputs.severity }} VERSION: ${{ steps.meta.outputs.version }} + BUILD_ARGS: ${{ inputs.build-args }} NO_CACHE: ${{ inputs.no-cache }} TRIVY_SERVER: ${{ vars.TRIVY_SERVER || 'http://localhost:4954' }} TRIVY_TOKEN: ${{ secrets.TRIVY_TOKEN }} @@ -101,6 +106,10 @@ jobs: else cache_args=(--cache-from "type=registry,ref=$IMAGE:buildcache") fi + build_args=(--build-arg "VERSION=$VERSION") + while IFS= read -r arg; do + if [ -n "$arg" ]; then build_args+=(--build-arg "$arg"); fi + done <<< "$BUILD_ARGS" status=0 for platform in "${platforms[@]}"; do @@ -109,7 +118,7 @@ jobs: echo "::group::Build $platform" docker buildx build --platform "$platform" --load --pull \ --file "$FILE" --tag "$tag" \ - --build-arg "VERSION=$VERSION" \ + "${build_args[@]}" \ "${cache_args[@]}" \ "$CONTEXT" echo "::endgroup::" @@ -146,6 +155,7 @@ jobs: labels: ${{ steps.meta.outputs.labels }} build-args: | VERSION=${{ steps.meta.outputs.version }} + ${{ inputs.build-args }} cache-to: type=registry,ref=${{ env.IMAGE }}:buildcache,mode=max # Only runs if NTFY_URL is set (e.g. https://ntfy.example.com/). diff --git a/README.md b/README.md index 8bb516e..5f3003d 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. | +| `build-args` | | Extra build args, one `NAME=value` per line, e.g. `APP_VERSION=${{ gitea.sha }}`. Used for both the scanned and the pushed build. | | `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. |