diff --git a/.gitea/workflows/docker-build.yml b/.gitea/workflows/docker-build.yml index 8ec933c..e4d2867 100644 --- a/.gitea/workflows/docker-build.yml +++ b/.gitea/workflows/docker-build.yml @@ -36,7 +36,7 @@ jobs: runs-on: ${{ inputs.runs-on }} steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v7 # Docker image names must be lowercase; Gitea owner/repo names may not be. - name: Set image name @@ -44,13 +44,17 @@ jobs: - name: Set up QEMU if: contains(inputs.platforms, 'arm') - uses: docker/setup-qemu-action@v3 + uses: docker/setup-qemu-action@v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + uses: docker/setup-buildx-action@v4 + with: + buildkitd-config-inline: | + [worker.oci] + max-parallelism = 8 - name: Log in to Gitea container registry - uses: docker/login-action@v3 + uses: docker/login-action@v4 with: registry: git.hin-fort.ch username: ${{ gitea.actor }} @@ -58,7 +62,7 @@ jobs: - name: Extract metadata id: meta - uses: docker/metadata-action@v5 + uses: docker/metadata-action@v6 with: images: ${{ env.IMAGE }} tags: | @@ -70,13 +74,16 @@ 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. + # 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. - name: Build and scan with Trivy env: PLATFORMS: ${{ inputs.platforms }} CONTEXT: ${{ inputs.context }} FILE: ${{ inputs.file }} SEVERITY: ${{ inputs.severity }} + VERSION: ${{ steps.meta.outputs.version }} TRIVY_SERVER: ${{ vars.TRIVY_SERVER || 'http://localhost:4954' }} TRIVY_TOKEN: ${{ secrets.TRIVY_TOKEN }} run: | @@ -90,7 +97,7 @@ jobs: echo "::group::Build $platform" docker buildx build --platform "$platform" --load --pull \ - --file "$FILE" --tag "$tag" \ + --file "$FILE" --tag "$tag" --build-arg "VERSION=$VERSION" \ --cache-from "type=registry,ref=$IMAGE:buildcache" \ "$CONTEXT" echo "::endgroup::" @@ -115,7 +122,7 @@ jobs: # Reuses the layers built above, so this mostly assembles and uploads. # pull: false keeps the base images identical to the ones just scanned. - name: Build and push - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v7 with: context: ${{ inputs.context }} file: ${{ inputs.file }} @@ -124,5 +131,7 @@ jobs: pull: false tags: ${{ steps.meta.outputs.tags }} 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 93e8968..496bfe2 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,9 @@ For x64 and arm64 (Raspberry Pi), add: | `severity` | `CRITICAL,HIGH` | Severities that fail the build. Vulnerabilities without a fixed version never fail it. | | `runs-on` | `linux-amd64` | Runner label. | +The image version from the tag/branch (e.g. `1.4.0`, `main`) is passed as +build arg `VERSION`; declare `ARG VERSION` in the Dockerfile to use it. + ### Required secrets Set these on the repo's organisation (or on the repo):