feat(get-images-from-files): add support for helm values
This commit is contained in:
@@ -45,6 +45,7 @@ jobs:
|
||||
- get-images-from-files/test.Dockerfile
|
||||
- get-images-from-files/test-deployment.yaml
|
||||
- get-images-from-files/test-compose.yaml
|
||||
- get-images-from-files/test-values-helmfile.yaml
|
||||
- name: Check image formats extracted
|
||||
run: |
|
||||
images="${{ steps.giff.outputs.images }}"
|
||||
@@ -64,6 +65,14 @@ jobs:
|
||||
check "Compose registry+tag (web:v3)" "example.com/compose/web:v3"
|
||||
check "Compose registry+tag (worker:v3)" "example.com/compose/worker:v3"
|
||||
|
||||
# Helmfile values (repository + tag, optional registry)
|
||||
check "Helmfile image (repository+tag)" "example.com/helmfile/app:v4"
|
||||
check "Helmfile images.worker (repository+tag)" "example.com/helmfile/worker:v5"
|
||||
check "Helmfile images.helper (repository+tag with digest)" "example.com/myproject/helper:2.0@sha256:cccc"
|
||||
check "Helmfile repository only (no tag)" "example.com/helmfile/repo-only"
|
||||
echo -n " Helmfile tag only (skipped, no output): "
|
||||
echo "$images" | grep -q ':v99' && { echo "FAIL (orphan tag should be skipped)"; exit 1; } || echo "OK"
|
||||
|
||||
# Shared ref (in both files) — must appear exactly once
|
||||
check "Shared ref present (distroless/static:nonroot)" "example.com/distroless/static:nonroot"
|
||||
count=$(echo "$images" | tr ',' '\n' | grep -c 'example.com/distroless/static:nonroot' || true)
|
||||
@@ -71,7 +80,7 @@ jobs:
|
||||
[ "$count" -eq 1 ] && echo "OK (count=$count)" || { echo "FAIL (count=$count, expected 1)"; exit 1; }
|
||||
total=$(echo "$images" | tr ',' '\n' | grep -c . || true)
|
||||
echo -n " Total unique refs: "
|
||||
[ "$total" -eq 7 ] && echo "OK ($total)" || { echo "FAIL (got $total, expected 7)"; exit 1; }
|
||||
[ "$total" -eq 11 ] && echo "OK ($total)" || { echo "FAIL (got $total, expected 11)"; exit 1; }
|
||||
|
||||
echo ""
|
||||
echo "All checks passed."
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
A reusable Gitea Action, that extracts docker images from selected files in a repository.
|
||||
|
||||
The action supports Dockerfiles, Kubernetes manifests, and Docker Compose/compose files. Other files are supported if they have a recognizable image reference. Duplicate image references are deduplicated.
|
||||
The action supports Dockerfiles, Kubernetes manifests, Docker Compose/compose files, and Helmfile value files (convention: `repository` required, `tag` optional; a lone `tag` without `repository` is skipped). Other files are supported if they have a recognizable image reference. Duplicate image references are deduplicated.
|
||||
|
||||
**Note:** Only fully-qualified refs (with registry, e.g. `docker.io/library/alpine:latest`, `gcr.io/distroless/static:nonroot@sha256:...`) are included; short refs like `alpine:latest` are omitted as their use is discouraged.
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: "Get Images From Files"
|
||||
description: "Extract docker images from selected files (Dockerfiles, Kubernetes manifests, Docker Compose/compose files, and files with recognizable image references)"
|
||||
description: "Extract docker images from selected files (Dockerfiles, Kubernetes manifests, Docker Compose/compose files, Helmfile values, and files with recognizable image references)"
|
||||
author: "Timo Behrendt <t.behrendt@t00n.de>"
|
||||
branding:
|
||||
icon: "package"
|
||||
@@ -32,6 +32,19 @@ runs:
|
||||
awk '/^[[:space:]]*FROM[[:space:]]/ { print $NF }' "$f" 2>/dev/null || true
|
||||
# Kubernetes / Docker Compose: image: <ref>
|
||||
grep -E '[[:space:]]image:[[:space:]]' "$f" 2>/dev/null | sed 's/.*image:[[:space:]]*//' | awk '{ print $1 }' || true
|
||||
# Helmfile values: repository (required), tag optional (by indent); tag without repo is skipped
|
||||
awk '
|
||||
match($0, /^[[:space:]]*/) { indent = RLENGTH }
|
||||
/^[[:space:]]*repository:[[:space:]]/ {
|
||||
v = $0; sub(/^[^:]*:[[:space:]]*"?/, "", v); sub(/"?[[:space:]]*$/, "", v); repo[indent] = v;
|
||||
if (tag[indent] != "") { print repo[indent] ":" tag[indent] } else { print repo[indent] };
|
||||
delete repo[indent]; delete tag[indent]; next
|
||||
}
|
||||
/^[[:space:]]*tag:[[:space:]]/ {
|
||||
v = $0; sub(/^[^:]*:[[:space:]]*"?/, "", v); sub(/"?[[:space:]]*$/, "", v); tag[indent] = v;
|
||||
if (repo[indent] != "") { print repo[indent] ":" tag[indent]; delete repo[indent]; delete tag[indent] } else { delete tag[indent] }; next
|
||||
}
|
||||
' "$f" 2>/dev/null || true
|
||||
done | grep -E '/' | sort -u | paste -sd,
|
||||
)
|
||||
echo "images=${images:-}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
# Used by CI to test get-images-from-files action (Helmfile values, fully-qualified refs only)
|
||||
# Simple convention: image.repository + image.tag
|
||||
image:
|
||||
repository: example.com/helmfile/app
|
||||
tag: "v4"
|
||||
|
||||
# Nested under images (repository + tag)
|
||||
images:
|
||||
worker:
|
||||
repository: example.com/helmfile/worker
|
||||
tag: "v5"
|
||||
helper:
|
||||
repository: example.com/myproject/helper
|
||||
tag: "2.0@sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
|
||||
# Repository only (no tag) — should be extracted
|
||||
repo_only:
|
||||
repository: example.com/helmfile/repo-only
|
||||
# Tag only (no repository) — should be skipped
|
||||
tag_only:
|
||||
tag: "v99"
|
||||
Reference in New Issue
Block a user