20
20
21
21
# ----------------------------- GLOBAL VARIABLES ----------------------------- #
22
22
23
+ COMMIT_ENV_PATH=" manifests/base/commit.env"
23
24
PARAMS_ENV_PATH=" manifests/base/params.env"
24
25
25
26
# This value needs to be updated everytime we deliberately change number of the
@@ -29,13 +30,13 @@ EXPECTED_NUM_RECORDS=20
29
30
# ---------------------------- DEFINED FUNCTIONS ----------------------------- #
30
31
31
32
function check_variables_uniq() {
32
- local params_env_path =" ${1} "
33
+ local env_file_path =" ${1} "
33
34
local ret_code=0
34
35
35
- echo " Checking that all variables in the file '${params_env_path } ' are unique and expected"
36
+ echo " Checking that all variables in the file '${env_file_path } ' are unique and expected"
36
37
37
38
local content
38
- content=$( sed ' s#\(.*\)=.*#\1#' " ${params_env_path } " | sort)
39
+ content=$( sed ' s#\(.*\)=.*#\1#' " ${env_file_path } " | sort)
39
40
40
41
local num_records
41
42
num_records=$( echo " ${content} " | wc -l)
@@ -191,6 +192,30 @@ function check_image_variable_matches_name_and_commitref() {
191
192
}
192
193
}
193
194
195
+ function check_image_commit_id_matches_metadata() {
196
+ local image_variable=" ${1} "
197
+ local image_commit_id=" ${2} "
198
+
199
+ local short_image_commit_id
200
+ # We're interested only in the first 7 characters of the commit ID
201
+ short_image_commit_id=${image_commit_id: 0: 7}
202
+
203
+ local file_image_commit_id
204
+
205
+ file_image_commit_id=$( sed ' s#-commit##' " ${COMMIT_ENV_PATH} " | grep " ${image_variable} =" | cut --delimiter " =" --field 2)
206
+ test -n " ${file_image_commit_id} " || {
207
+ echo " Couldn't retrieve commit id for image variable '${image_variable} ' in '${COMMIT_ENV_PATH} '!"
208
+ return 1
209
+ }
210
+
211
+ test " ${short_image_commit_id} " = " ${file_image_commit_id} " || {
212
+ echo " Image commit IDs for image variable '${image_variable} ' don't equal!"
213
+ echo " Image commit ID gathered from image: '${short_image_commit_id} '"
214
+ echo " Image commit ID in '${COMMIT_ENV_PATH} ': '${file_image_commit_id} '"
215
+ return 1
216
+ }
217
+ }
218
+
194
219
function check_image() {
195
220
local image_variable=" ${1} "
196
221
local image_url=" ${2} "
@@ -199,6 +224,7 @@ function check_image() {
199
224
200
225
local image_metadata
201
226
local image_name
227
+ local image_commit_id
202
228
local image_commitref
203
229
204
230
image_metadata=" $( skopeo inspect --config " docker://${image_url} " ) " || {
@@ -209,6 +235,10 @@ function check_image() {
209
235
echo " Couldn't parse '.config.Labels.name' from image metadata!"
210
236
return 1
211
237
}
238
+ image_commit_id=$( echo " ${image_metadata} " | jq --raw-output ' .config.Labels."io.openshift.build.commit.id"' ) || {
239
+ echo " Couldn't parse '.config.Labels." io.openshift.build.commit.id" ' from image metadata!"
240
+ return 1
241
+ }
212
242
image_commitref=$( echo " ${image_metadata} " | jq --raw-output ' .config.Labels."io.openshift.build.commit.ref"' ) || {
213
243
echo " Couldn't parse '.config.Labels." io.openshift.build.commit.ref" ' from image metadata!"
214
244
return 1
@@ -240,18 +270,26 @@ function check_image() {
240
270
241
271
check_image_variable_matches_name_and_commitref " ${image_variable} " " ${image_name} " " ${image_commitref} " " ${openshift_build_name} " || return 1
242
272
273
+ check_image_commit_id_matches_metadata " ${image_variable} " " ${image_commit_id} " || return 1
274
+
243
275
echo " ---------------------------------------------"
244
276
}
245
277
246
278
# ------------------------------ MAIN SCRIPT --------------------------------- #
247
279
248
280
ret_code=0
249
281
250
- echo " Starting check for file: '${PARAMS_ENV_PATH} '"
282
+ echo " Starting check of image references in files: ' ${COMMIT_ENV_PATH} ' and '${PARAMS_ENV_PATH} '"
251
283
echo " ---------------------------------------------"
252
284
285
+ check_variables_uniq " ${COMMIT_ENV_PATH} " || {
286
+ echo " ERROR: Variable names in the '${COMMIT_ENV_PATH} ' file failed validation!"
287
+ echo " ----------------------------------------------------"
288
+ ret_code=1
289
+ }
290
+
253
291
check_variables_uniq " ${PARAMS_ENV_PATH} " || {
254
- echo " ERROR: Variable names in the file failed validation!"
292
+ echo " ERROR: Variable names in the ' ${PARAMS_ENV_PATH} ' file failed validation!"
255
293
echo " ----------------------------------------------------"
256
294
ret_code=1
257
295
}
0 commit comments