Changes in workflow

This commit is contained in:
2025-11-06 23:36:41 +01:00
parent a84e5b34b6
commit 441b9c99d2

View File

@@ -48,13 +48,15 @@ jobs:
shell: bash shell: bash
run: | run: |
set -euo pipefail set -euo pipefail
file="$DEPLOY_FILE" file="${DEPLOY_FILE:-argocd/deployment.yaml}"
cname="$CONTAINER_NAME" cname="${CONTAINER_NAME:-web}"
expected_repo="$EXPECTED_REPO" expected_repo="${EXPECTED_REPO:-git.baumann.gr/adebaumann/vui}"
# Extract ONLY from .spec.template.spec.containers[], selecting by .name == cname # --- functions ------------------------------------------------------
# Works across multi-doc YAML (the Service doc will be ignored) have_yq() { command -v yq >/dev/null 2>&1; }
extract() {
# yq-based extractor (multi-doc aware; Deployment only; container name match)
yq_extract() {
yq -r ' yq -r '
select(.kind == "Deployment") | select(.kind == "Deployment") |
.spec.template.spec.containers // [] | .spec.template.spec.containers // [] |
@@ -63,50 +65,94 @@ jobs:
' "$1" 2>/dev/null | tail -n 1 ' "$1" 2>/dev/null | tail -n 1
} }
debug_list() { # ultra-tolerant fallback: grep around containers: block and pick name==web image
echo "== workload images in $1 ==" >&2 # (still ignores initContainers by staying within the "containers:" block)
fallback_extract() {
# print the containers block, then associate names with images
awk -v cname="$cname" '
BEGIN{ in_cont=0; name=""; image="" }
/^containers:/ {in_cont=1; next}
in_cont {
# end of containers block when dedented to less than two spaces or new top-level key
if ($0 ~ /^[[:alpha:]][[:alnum:]_:-]*:/ || $0 ~ /^ *initContainers:/) { in_cont=0 }
# capture name and image lines
if ($0 ~ /^[[:space:]]*-?[[:space:]]*name:[[:space:]]*/) {
name=$0; sub(/^.*name:[[:space:]]*/,"",name); gsub(/^[ "\047]+|[ "\047]+$/,"",name)
}
if ($0 ~ /^[[:space:]]*image:[[:space:]]*/) {
image=$0; sub(/^.*image:[[:space:]]*/,"",image); gsub(/^[ "\047]+|[ "\047]+$/,"",image)
if (name==cname) { print image; exit }
}
}
' "$1"
}
list_workload_images() {
echo "== workload containers in $1 ==" >&2
if have_yq; then
yq -r ' yq -r '
select(.kind == "Deployment") | select(.kind == "Deployment") |
.spec.template.spec.containers // [] | .spec.template.spec.containers // [] |
.[] | "\(.name): \(.image)" .[] | "\(.name): \(.image)"
' "$1" 2>/dev/null | nl -ba >&2 || true ' "$1" 2>/dev/null | nl -ba >&2 || true
else
# coarse list for visibility
awk '
/^ *containers:/, /^[^ ]/ { if ($0 ~ /name:|image:/) print }
' "$1" | nl -ba >&2 || true
fi
} }
# --------------------------------------------------------------------
# Old image (from previous commit) # Ensure yq is present; if install failed earlier, try once more
if ! have_yq; then
echo "yq missing; attempting quick install..." >&2
curl -fsSL https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -o /usr/local/bin/yq || true
chmod +x /usr/local/bin/yq || true
fi
# Prepare old file (previous commit) if exists
if git cat-file -e "${{ steps.base.outputs.base }}":"$file" 2>/dev/null; then if git cat-file -e "${{ steps.base.outputs.base }}":"$file" 2>/dev/null; then
git show "${{ steps.base.outputs.base }}:$file" > /tmp/old.yaml git show "${{ steps.base.outputs.base }}:$file" > /tmp/old.yaml
debug_list /tmp/old.yaml
old_image="$(extract /tmp/old.yaml || true)"
else else
old_image="" : > /tmp/old.yaml
fi fi
# New image (from workspace) list_workload_images /tmp/old.yaml || true
if [ -f "$file" ]; then list_workload_images "$file" || true
debug_list "$file"
new_image="$(extract "$file" || true)" if have_yq; then
old_image="$(yq_extract /tmp/old.yaml || true)"
new_image="$(yq_extract "$file" || true)"
else else
new_image="" old_image="$(fallback_extract /tmp/old.yaml || true)"
new_image="$(fallback_extract "$file" || true)"
fi fi
echo "Old workload image: $old_image" # If yq path failed to find it, try fallback once more as safety
echo "New workload image: $new_image" if [ -z "${new_image:-}" ]; then
new_image="$(fallback_extract "$file" || true)"
fi
if [ -z "${old_image:-}" ]; then
old_image="$(fallback_extract /tmp/old.yaml || true)"
fi
if [ -z "$new_image" ]; then echo "Old workload image: ${old_image:-<none>}"
echo "ERROR: Could not find containers[].name == \"$cname\" in $file" echo "New workload image: ${new_image:-<none>}"
if [ -z "${new_image:-}" ]; then
echo "ERROR: Could not find containers[].name == \"$cname\" image in $file"
exit 1 exit 1
fi fi
# Sanity-check repo prefix (avoid accidentally building the init image) # Split repo and tag
new_repo="${new_image%:*}" new_repo="${new_image%:*}"
new_tag="${new_image##*:}" new_tag="${new_image##*:}"
if [[ "$new_repo" != "$expected_repo" ]]; then if [[ "$new_repo" != "$expected_repo" ]]; then
echo "ERROR: Found container \"$cname\" image repo is \"$new_repo\" but expected \"$expected_repo\"" echo "ERROR: Found container \"$cname\" image repo is \"$new_repo\" but expected \"$expected_repo\""
exit 1 exit 1
fi fi
if [ -n "${old_image:-}" ]; then
# Old tag (if any)
if [ -n "$old_image" ]; then
old_tag="${old_image##*:}" old_tag="${old_image##*:}"
else else
old_tag="" old_tag=""