feat(get-images-from-files): add support for helm values #29

Merged
t.behrendt merged 4 commits from feat-get-images-from-files-add-helm-values-support into main 2026-02-05 17:29:01 +01:00
4 changed files with 6 additions and 17 deletions
Showing only changes of commit 19cf9c7dd6 - Show all commits
+1 -4
View File
@@ -69,9 +69,6 @@ jobs:
check "Helmfile image (repository+tag)" "example.com/helmfile/app:v4" check "Helmfile image (repository+tag)" "example.com/helmfile/app:v4"
check "Helmfile images.worker (repository+tag)" "example.com/helmfile/worker:v5" 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 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 # Shared ref (in both files) — must appear exactly once
check "Shared ref present (distroless/static:nonroot)" "example.com/distroless/static:nonroot" check "Shared ref present (distroless/static:nonroot)" "example.com/distroless/static:nonroot"
@@ -80,7 +77,7 @@ jobs:
[ "$count" -eq 1 ] && echo "OK (count=$count)" || { echo "FAIL (count=$count, expected 1)"; exit 1; } [ "$count" -eq 1 ] && echo "OK (count=$count)" || { echo "FAIL (count=$count, expected 1)"; exit 1; }
total=$(echo "$images" | tr ',' '\n' | grep -c . || true) total=$(echo "$images" | tr ',' '\n' | grep -c . || true)
echo -n " Total unique refs: " echo -n " Total unique refs: "
[ "$total" -eq 11 ] && echo "OK ($total)" || { echo "FAIL (got $total, expected 11)"; exit 1; } [ "$total" -eq 10 ] && echo "OK ($total)" || { echo "FAIL (got $total, expected 10)"; exit 1; }
echo "" echo ""
echo "All checks passed." echo "All checks passed."
+1 -1
View File
@@ -11,7 +11,7 @@ A reusable Gitea Action that extracts Docker image references from selected file
| **Dockerfile** | `FROM` lines; the image ref is the last token (handles `FROM --platform=... <image>`). | | **Dockerfile** | `FROM` lines; the image ref is the last token (handles `FROM --platform=... <image>`). |
| **Kubernetes manifests** | Lines with `image:` (e.g. under `containers` / `initContainers`); the value is taken as the image ref. | | **Kubernetes manifests** | Lines with `image:` (e.g. under `containers` / `initContainers`); the value is taken as the image ref. |
| **Docker Compose / Compose** | Same as Kubernetes: `image:` key under services. | | **Docker Compose / Compose** | Same as Kubernetes: `image:` key under services. |
| **Helmfile values** | Pairs of `repository` and optional `tag` at the same indent; ref is `repository` or `repository:tag`. A lone `tag` without `repository` is skipped. | | **Helmfile values** | Pairs of `repository` and `tag` (both required) at the same indent; ref is `repository:tag`. A lone `tag` without `repository` is skipped. |
Other files are supported if they use one of these patterns (e.g. `image:` or `FROM`). Other files are supported if they use one of these patterns (e.g. `image:` or `FROM`).
+4 -6
View File
@@ -32,17 +32,15 @@ runs:
awk '/^[[:space:]]*FROM[[:space:]]/ { print $NF }' "$f" 2>/dev/null || true awk '/^[[:space:]]*FROM[[:space:]]/ { print $NF }' "$f" 2>/dev/null || true
# Kubernetes / Docker Compose: image: <ref> # Kubernetes / Docker Compose: image: <ref>
grep -E '[[:space:]]image:[[:space:]]' "$f" 2>/dev/null | sed 's/.*image:[[:space:]]*//' | awk '{ print $1 }' || true 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 # Helmfile values: repository + tag (both required, by indent); tag without repo is skipped
awk ' awk '
match($0, /^[[:space:]]*/) { indent = RLENGTH } match($0, /^[[:space:]]*/) { indent = RLENGTH }
/^[[:space:]]*repository:[[:space:]]/ { /^[[:space:]]*repository:[[:space:]]/ {
v = $0; sub(/^[^:]*:[[:space:]]*"?/, "", v); sub(/"?[[:space:]]*$/, "", v); repo[indent] = v; v = $0; sub(/^[^:]*:[[:space:]]*"?/, "", v); sub(/"?[[:space:]]*$/, "", v); repo[indent] = v; next
if (tag[indent] != "") { print repo[indent] ":" tag[indent] } else { print repo[indent] };
delete repo[indent]; delete tag[indent]; next
} }
/^[[:space:]]*tag:[[:space:]]/ { /^[[:space:]]*tag:[[:space:]]/ {
v = $0; sub(/^[^:]*:[[:space:]]*"?/, "", v); sub(/"?[[:space:]]*$/, "", v); tag[indent] = v; v = $0; sub(/^[^:]*:[[:space:]]*"?/, "", v); sub(/"?[[:space:]]*$/, "", v);
if (repo[indent] != "") { print repo[indent] ":" tag[indent]; delete repo[indent]; delete tag[indent] } else { delete tag[indent] }; next if (repo[indent] != "") { print repo[indent] ":" v; delete repo[indent] }; next
} }
' "$f" 2>/dev/null || true ' "$f" 2>/dev/null || true
done | grep -E '/' | sort -u | paste -sd, done | grep -E '/' | sort -u | paste -sd,
@@ -12,9 +12,3 @@ images:
helper: helper:
repository: example.com/myproject/helper repository: example.com/myproject/helper
tag: "2.0@sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" 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"