Skip to content

Commit 29b1188

Browse files
committed
Extend CI image check to also runtime images
1 parent 661caea commit 29b1188

File tree

2 files changed

+91
-1
lines changed

2 files changed

+91
-1
lines changed

.github/workflows/params-env.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
---
2-
name: Validation of params.env content (image SHAs)
2+
name: Validation of image references (image SHAs) in params.env and runtime images
33
on: # yamllint disable-line rule:truthy
44
pull_request:
55
paths:
66
- 'manifests/base/params.env'
7+
- 'ci/check-params-env.sh'
78

89
permissions:
910
contents: read
@@ -21,3 +22,8 @@ jobs:
2122
- name: Validate the 'manifests/base/params.env' file content
2223
run: |
2324
bash ./ci/check-params-env.sh
25+
26+
- name: Validate references for runtime images
27+
id: validate-runtime-images-references
28+
run: |
29+
bash ./ci/check-runtime-images.sh

ci/check-runtime-images.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
#
3+
# This script serves to check and validate the definitions for runtime images.
4+
# It does just a brief check of the metadata defined in the json file:
5+
# 1. checks that given `.metadata.image_name` is valid and can be accessed by skopeo tool
6+
# 2. checks that tag in `.metadata.tags[0]` can be found in the output from skopeo tool
7+
#
8+
# THIS FILE DOESN'T CHECK THAT THE USED LINK TO IMAGE IS THE LATEST ONE AVAILABLE!
9+
#
10+
# This script uses `skopeo` and `jq` tools installed locally for retrieving
11+
# information about the particular remote images.
12+
#
13+
# Local execution: ./ci/check-runtime-image.sh
14+
# Note: please execute from the root directory so that relative path matches
15+
#
16+
# In case of the PR on GitHub, this check is tied to GitHub actions automatically,
17+
# see `.github/workflows` directory.
18+
19+
# ---------------------------- DEFINED FUNCTIONS ----------------------------- #
20+
21+
function check_image() {
22+
local runtime_image_file="${1}"
23+
24+
echo "---------------------------------------------"
25+
echo "Checking file: '${runtime_image_file}'"
26+
27+
local img_tag
28+
local img_url
29+
local img_metadata
30+
31+
img_tag=$(jq -r '.metadata.tags[0]' "${runtime_image_file}") || {
32+
echo "ERROR: Couldn't parse image tags metadata for '${runtime_image_file}' runtime image file!"
33+
return 1
34+
}
35+
img_url=$(jq -r '.metadata.image_name' "${runtime_image_file}") || {
36+
echo "ERROR: Couldn't parse image URL metadata for '${runtime_image_file}' runtime image file!"
37+
return 1
38+
}
39+
40+
img_metadata="$(skopeo inspect --config "docker://${img_url}")" || {
41+
echo "ERROR: Couldn't download '${img_url}' image metadata with skopeo tool!"
42+
return 1
43+
}
44+
45+
local expected_string="runtime-${img_tag}-ubi"
46+
echo "Checking that '${expected_string}' is present in the image metadata"
47+
echo "${img_metadata}" | grep --quiet "${expected_string}" || {
48+
echo "ERROR: The string '${expected_string}' isn't present in the image metadata at all. Please check that the referenced image '${img_url}' is the correct one!"
49+
return 1
50+
}
51+
52+
# TODO: we shall extend this check to check also Label "io.openshift.build.commit.ref" value (e.g. '2024a') or something similar
53+
}
54+
55+
function main() {
56+
ret_code=0
57+
58+
# If name of the directory isn't good enough, maybe we can improve this to search for the: `"schema_name": "runtime-image"` string.
59+
runtime_image_files=$(find . -name "*.json" | grep "runtime-images" | sort --unique)
60+
61+
IFS=$'\n'
62+
for file in ${runtime_image_files}; do
63+
check_image "${file}" || {
64+
echo "ERROR: Check for '${file}' failed!"
65+
ret_code=1
66+
}
67+
done
68+
69+
echo "---------------------------------------------"
70+
echo ""
71+
if test "${ret_code}" -eq 0; then
72+
echo "Validation of runtime images definitions was successful! Congrats :)"
73+
else
74+
echo "ERROR: Some of the runtime image definitions aren't valid, please check above!"
75+
fi
76+
77+
return "${ret_code}"
78+
}
79+
80+
# ------------------------------ MAIN SCRIPT --------------------------------- #
81+
82+
main
83+
84+
exit "${?}"

0 commit comments

Comments
 (0)