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 <noreply@anthropic.com>
This commit is contained in:
1 parent
af9b97e111
commit
2c16d55a07
2 files changed
+15
-4
No files matched your search
@@ -18,6 +18,10 @@ on:
|
|||||||
description: 'Path to the Dockerfile (default: <context>/Dockerfile)'
|
description: 'Path to the Dockerfile (default: <context>/Dockerfile)'
|
||||||
type: string
|
type: string
|
||||||
default: ''
|
default: ''
|
||||||
|
build-args:
|
||||||
|
description: 'Extra build args, one NAME=value per line (VERSION is always passed)'
|
||||||
|
type: string
|
||||||
|
default: ''
|
||||||
no-cache:
|
no-cache:
|
||||||
description: 'Build without cache, e.g. for scheduled rebuilds that must pick up new packages'
|
description: 'Build without cache, e.g. for scheduled rebuilds that must pick up new packages'
|
||||||
type: boolean
|
type: boolean
|
||||||
@@ -78,9 +82,9 @@ jobs:
|
|||||||
# Each platform is built into the local Docker daemon on its own (a
|
# 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,
|
# 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
|
# 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
|
# log shows every finding at once. VERSION and the build-args input are
|
||||||
# the push step) so the scanned image matches the pushed one; Dockerfiles
|
# passed as in the push step so the scanned image matches the pushed one;
|
||||||
# that don't declare ARG VERSION ignore it.
|
# Dockerfiles that don't declare ARG VERSION ignore it.
|
||||||
- name: Build and scan with Trivy
|
- name: Build and scan with Trivy
|
||||||
id: scan
|
id: scan
|
||||||
env:
|
env:
|
||||||
@@ -89,6 +93,7 @@ jobs:
|
|||||||
FILE: ${{ inputs.file }}
|
FILE: ${{ inputs.file }}
|
||||||
SEVERITY: ${{ inputs.severity }}
|
SEVERITY: ${{ inputs.severity }}
|
||||||
VERSION: ${{ steps.meta.outputs.version }}
|
VERSION: ${{ steps.meta.outputs.version }}
|
||||||
|
BUILD_ARGS: ${{ inputs.build-args }}
|
||||||
NO_CACHE: ${{ inputs.no-cache }}
|
NO_CACHE: ${{ inputs.no-cache }}
|
||||||
TRIVY_SERVER: ${{ vars.TRIVY_SERVER || 'http://localhost:4954' }}
|
TRIVY_SERVER: ${{ vars.TRIVY_SERVER || 'http://localhost:4954' }}
|
||||||
TRIVY_TOKEN: ${{ secrets.TRIVY_TOKEN }}
|
TRIVY_TOKEN: ${{ secrets.TRIVY_TOKEN }}
|
||||||
@@ -101,6 +106,10 @@ jobs:
|
|||||||
else
|
else
|
||||||
cache_args=(--cache-from "type=registry,ref=$IMAGE:buildcache")
|
cache_args=(--cache-from "type=registry,ref=$IMAGE:buildcache")
|
||||||
fi
|
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
|
status=0
|
||||||
|
|
||||||
for platform in "${platforms[@]}"; do
|
for platform in "${platforms[@]}"; do
|
||||||
@@ -109,7 +118,7 @@ jobs:
|
|||||||
echo "::group::Build $platform"
|
echo "::group::Build $platform"
|
||||||
docker buildx build --platform "$platform" --load --pull \
|
docker buildx build --platform "$platform" --load --pull \
|
||||||
--file "$FILE" --tag "$tag" \
|
--file "$FILE" --tag "$tag" \
|
||||||
--build-arg "VERSION=$VERSION" \
|
"${build_args[@]}" \
|
||||||
"${cache_args[@]}" \
|
"${cache_args[@]}" \
|
||||||
"$CONTEXT"
|
"$CONTEXT"
|
||||||
echo "::endgroup::"
|
echo "::endgroup::"
|
||||||
@@ -146,6 +155,7 @@ jobs:
|
|||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
build-args: |
|
build-args: |
|
||||||
VERSION=${{ steps.meta.outputs.version }}
|
VERSION=${{ steps.meta.outputs.version }}
|
||||||
|
${{ inputs.build-args }}
|
||||||
cache-to: type=registry,ref=${{ env.IMAGE }}:buildcache,mode=max
|
cache-to: type=registry,ref=${{ env.IMAGE }}:buildcache,mode=max
|
||||||
|
|
||||||
# Only runs if NTFY_URL is set (e.g. https://ntfy.example.com/<topic>).
|
# Only runs if NTFY_URL is set (e.g. https://ntfy.example.com/<topic>).
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ For x64 and arm64 (Raspberry Pi), add:
|
|||||||
| `platforms` | `linux/amd64` | Comma-separated target platforms. Any `arm` platform enables QEMU emulation. |
|
| `platforms` | `linux/amd64` | Comma-separated target platforms. Any `arm` platform enables QEMU emulation. |
|
||||||
| `context` | `.` | Docker build context. |
|
| `context` | `.` | Docker build context. |
|
||||||
| `file` | `<context>/Dockerfile` | Path to the Dockerfile. |
|
| `file` | `<context>/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. |
|
| `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. |
|
| `severity` | `CRITICAL,HIGH` | Severities that fail the build. Vulnerabilities without a fixed version never fail it. |
|
||||||
| `runs-on` | `linux-amd64` | Runner label. |
|
| `runs-on` | `linux-amd64` | Runner label. |
|
||||||
|
|||||||
Reference in new issue
Block a user