Skip to content

Commit 4d09237

Browse files
CORE-11514: Added CI test to check images availability
1 parent 9d1953d commit 4d09237

File tree

6 files changed

+121
-0
lines changed

6 files changed

+121
-0
lines changed

.semaphore/semaphore.yml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.semaphore/semaphore.yml.d/02-global_job_config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
global_job_config:
22
secrets:
33
- name: docker-hub
4+
- name: oss-release-secrets
45
prologue:
56
commands:
67
- checkout
@@ -10,6 +11,8 @@ global_job_config:
1011
# unshallow it for GIT_VERSION:=$(shell git describe --tags --dirty --always)
1112
- retry git fetch --unshallow
1213
- echo $DOCKERHUB_PASSWORD | docker login --username "$DOCKERHUB_USERNAME" --password-stdin
14+
- export GOOGLE_APPLICATION_CREDENTIALS=$HOME/secrets/gcr-credentials.json
15+
- gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS}
1316
epilogue:
1417
commands:
1518
- cd "$REPO_DIR"

.semaphore/semaphore.yml.d/blocks/10-prerequisites.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@
55
- name: Pre-flight checks
66
commands:
77
- make ci-preflight-checks
8+
secrets:
9+
- name: oss-release-secrets
10+
prologue:
11+
commands:
12+
- export GOOGLE_APPLICATION_CREDENTIALS=$HOME/secrets/gcr-credentials.json
13+
- echo "🔐 Authenticating to GCR using GOOGLE_APPLICATION_CREDENTIALS"
14+
- gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS}

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ clean:
5050

5151
ci-preflight-checks:
5252
$(MAKE) check-go-mod
53+
$(MAKE) check-images-availability
5354
$(MAKE) verify-go-mods
5455
$(MAKE) check-dockerfiles
5556
$(MAKE) check-language
@@ -71,6 +72,11 @@ go-vet:
7172
check-dockerfiles:
7273
./hack/check-dockerfiles.sh
7374

75+
check-images-availability: bin/yq bin/crane
76+
cd ./hack && \
77+
OPERATOR_VERSION=$(OPERATOR_VERSION) \
78+
./check-images-availability.sh
79+
7480
check-language:
7581
./hack/check-language.sh
7682

hack/check-images-availability.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Resolve script directory
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
7+
# Use provided CRANE or fallback to ../bin/crane (relative to hack/)
8+
CRANE="${CRANE:-../bin/crane}"
9+
10+
if [ ! -x "$CRANE" ]; then
11+
echo "❌ Error: crane not found or not executable at: $CRANE" >&2
12+
echo "Resolved path: $(realpath "$CRANE" 2>/dev/null || echo '<unresolvable>')" >&2
13+
exit 1
14+
fi
15+
16+
#########################################
17+
# Step 1: Extract from manifests
18+
#########################################
19+
manifest_dir="${SCRIPT_DIR}/../manifests"
20+
manifest_images=$(
21+
grep -rhoE 'image:\s*["'\''"]?[a-z0-9.-]+\.[a-z0-9.-]+/[a-z0-9._/-]+:[a-zA-Z0-9._-]+' "$manifest_dir" \
22+
| sed -E 's/image:\s*["'\''"]?//' \
23+
| grep -v -- '-fips' \
24+
| sort -u
25+
)
26+
27+
count=$(echo "$manifest_images" | wc -l)
28+
echo "📦 Total unique images from manifests (excluding -fips): ${count}"
29+
30+
#########################################
31+
# Step 2: Check availability with retries
32+
#########################################
33+
FAILED=0
34+
FAILED_IMAGES=()
35+
36+
while IFS= read -r image; do
37+
success=0
38+
for attempt in 1 2 3; do
39+
if "$CRANE" digest "$image" >/dev/null 2>&1; then
40+
echo "✅ Available: $image"
41+
success=1
42+
break
43+
else
44+
echo "⚠️ Attempt $attempt failed for: $image"
45+
if [ "$attempt" -eq 3 ]; then
46+
echo "🔍 Used crane at: $(realpath "$CRANE" 2>/dev/null || echo '<unresolvable>')"
47+
fi
48+
sleep 3
49+
fi
50+
done
51+
52+
if [ "$success" -ne 1 ]; then
53+
echo "❌ NOT FOUND after 3 attempts: $image"
54+
FAILED=1
55+
FAILED_IMAGES+=("$image")
56+
fi
57+
done <<< "$manifest_images"
58+
59+
#########################################
60+
# Step 3: Final result
61+
#########################################
62+
if [ "$FAILED" -eq 1 ]; then
63+
echo ""
64+
echo "❗ Some images are missing or invalid:"
65+
for img in "${FAILED_IMAGES[@]}"; do
66+
echo "$img"
67+
done
68+
exit 1
69+
else
70+
echo "✅ All images from manifests are available!"
71+
fi

lib.Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,26 @@ bin/yq:
12491249
tar -zxvf $(TMP)/yq4.tar.gz -C $(TMP)
12501250
mv $(TMP)/yq_linux_$(BUILDARCH) bin/yq
12511251

1252+
# This setup is used to download and install the 'crane' binary into the local bin/ directory.
1253+
# The binary will be placed at: ./bin/crane
1254+
# Normalize architecture for go-containerregistry filenames
1255+
CRANE_BUILDARCH := $(shell uname -m | sed 's/amd64/x86_64/;s/x86_64/x86_64/;s/aarch64/arm64/')
1256+
ifeq ($(CRANE_BUILDARCH),)
1257+
$(error Unsupported or unknown architecture: $(shell uname -m))
1258+
endif
1259+
CRANE_VERSION := v0.20.6
1260+
CRANE_FILENAME := go-containerregistry_Linux_$(CRANE_BUILDARCH).tar.gz
1261+
CRANE_URL := https://github.com/google/go-containerregistry/releases/download/$(CRANE_VERSION)/$(CRANE_FILENAME)
1262+
1263+
# Install crane binary into bin/
1264+
bin/crane:
1265+
mkdir -p bin
1266+
$(eval TMP := $(shell mktemp -d))
1267+
curl -sSfL --retry 5 -o $(TMP)/crane.tar.gz $(CRANE_URL)
1268+
tar -xzf $(TMP)/crane.tar.gz -C $(TMP) crane
1269+
mv $(TMP)/crane bin/crane
1270+
chmod +x bin/crane
1271+
12521272
###############################################################################
12531273
# Common functions for launching a local Kubernetes control plane.
12541274
###############################################################################

0 commit comments

Comments
 (0)