Skip to content

Commit 22c50a7

Browse files
fix: add script for checking unicorn multiarch images (defenseunicorns#2047)
## Description Dynamically grab all unicorn images, based on `quay.io/rfcurated`, create a list of those images, then iterate over those images and do a crane manifest against each image. Keep track of each image that doesn't have both an `arm64` and `amd64` published architecture. If any images don't have both architectures, `exit 1` at the end of the script. Script automatically cleans up tmp files with the `trap` functionality. <img width="980" height="1245" alt="Screenshot from 2025-10-20 10-16-45" src="https://github.com/user-attachments/assets/fe52ddf2-d8d1-4373-a4ce-9603a0558ca0" /> ## Related Issue Fixes # <!-- or --> Relates to # ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Other (security config, docs update, etc) ## Steps to Validate - If this PR introduces new functionality to UDS Core or addresses a bug, please document the steps to test the changes. ## Checklist before merging - [ ] Test, docs, adr added or updated as needed - [ ] [Contributor Guide](https://github.com/defenseunicorns/uds-template-capability/blob/main/CONTRIBUTING.md) followed
1 parent 65747cb commit 22c50a7

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

scripts/check-multiarch.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
# Copyright 2025 Defense Unicorns
3+
# SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Defense-Unicorns-Commercial
4+
5+
set -e
6+
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
SRC_DIR="${1:-$SCRIPT_DIR/../src}"
9+
10+
# Create temporary files and ensure cleanup no matter script outcome
11+
TEMP_IMAGES=$(mktemp)
12+
TEMP_MISSING=$(mktemp)
13+
trap "rm -f $TEMP_IMAGES $TEMP_MISSING" EXIT
14+
15+
echo "Scanning $SRC_DIR for unicorn and registry1 images..."
16+
17+
# Extract all quay.io/rfcurated/ (unicorn) and registry1.dso.mil/ironbank/ (registry1) images
18+
find "$SRC_DIR" -name "zarf.yaml" -type f -exec grep -hE "quay.io/rfcurated/|registry1.dso.mil/ironbank/" {} \; | \
19+
sed 's/^[[:space:]]*-[[:space:]]*//' | \
20+
sed 's/"//g' | \
21+
sort -u > "$TEMP_IMAGES"
22+
23+
TOTAL=$(wc -l < "$TEMP_IMAGES")
24+
echo "Found $TOTAL images"
25+
echo ""
26+
27+
# Check each image
28+
COUNT=0
29+
> "$TEMP_MISSING"
30+
31+
cat "$TEMP_IMAGES" | while read -r IMAGE; do
32+
COUNT=$((COUNT + 1))
33+
echo "[$COUNT/$TOTAL] $IMAGE"
34+
35+
MANIFEST=$(crane manifest "$IMAGE" 2>/dev/null || echo "")
36+
37+
if [ -z "$MANIFEST" ]; then
38+
echo " ERROR: Failed to fetch"
39+
echo "$IMAGE" >> "$TEMP_MISSING"
40+
continue
41+
fi
42+
43+
AMD64=$(echo "$MANIFEST" | jq -r '.manifests[]?.platform.architecture' 2>/dev/null | grep -c "amd64" || echo "0" | tr -d '\n')
44+
ARM64=$(echo "$MANIFEST" | jq -r '.manifests[]?.platform.architecture' 2>/dev/null | grep -c "arm64" || echo "0" | tr -d '\n')
45+
46+
# Ensure we have clean integers
47+
AMD64=${AMD64//[^0-9]/}
48+
ARM64=${ARM64//[^0-9]/}
49+
AMD64=${AMD64:-0}
50+
ARM64=${ARM64:-0}
51+
52+
if [ "$AMD64" -eq 0 ] || [ "$ARM64" -eq 0 ]; then
53+
ARCHS=$(echo "$MANIFEST" | jq -r '.manifests[]?.platform.architecture // .architecture // "unknown"' 2>/dev/null | paste -sd "," -)
54+
echo " ✗ MISSING [$ARCHS]"
55+
echo "$IMAGE" >> "$TEMP_MISSING"
56+
else
57+
echo " ✓ OK"
58+
fi
59+
done
60+
61+
echo ""
62+
echo "=========================================="
63+
MISSING_COUNT=$(wc -l < "$TEMP_MISSING")
64+
echo "Images missing amd64/arm64: $MISSING_COUNT"
65+
66+
if [ "$MISSING_COUNT" -gt 0 ]; then
67+
echo ""
68+
echo "Missing multi-arch support:"
69+
cat "$TEMP_MISSING"
70+
exit 1
71+
fi

tasks/utils.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,9 @@ tasks:
116116
BASE_NAME=$(echo "${FLAVORED_PACKAGE}" | sed "s/-${FLAVOR}\.tar\.zst/.tar.zst/")
117117
mv -v "${FLAVORED_PACKAGE}" "${BASE_NAME}"
118118
done
119+
120+
- name: check-multiarch-images
121+
description: "Script to check if/what Unicorn and Registry1 images are missing from registry."
122+
actions:
123+
- description: Check Unicorn and Registry1 Multi-Arch images
124+
cmd: ./scripts/check-multiarch.sh

0 commit comments

Comments
 (0)