@@ -7,54 +7,47 @@ set -o errexit -o nounset -o pipefail ${RUNNER_DEBUG:+-x}
7
7
8
8
get_image ()
9
9
{
10
- local PUBLISHED=$1
11
-
12
- case " ${PUBLISHED} " in
13
- " published" )
14
- local PUBLISHED_FILTER=" repositories.published==true"
15
- ;;
16
- " not_published" )
17
- local PUBLISHED_FILTER=" repositories.published!=true"
18
- ;;
19
- * )
20
- echoerr " Need first parameter as 'published' or 'not_published', not '${PUBLISHED} '." ; return 1
21
- ;;
22
- esac
23
-
24
- local FILTER=" filter=deleted==false;${PUBLISHED_FILTER} ;_id==${IMAGE_ID} "
25
-
26
10
local RESPONSE
27
11
# https://catalog.redhat.com/api/containers/docs/endpoints/RESTGetImagesForCertProjectById.html
28
12
RESPONSE=$( \
29
13
curl --fail \
30
14
--silent \
31
15
--show-error \
32
16
--header " X-API-KEY: ${RHEL_API_KEY} " \
33
- " https://catalog.redhat.com/api/containers/v1/projects/certification/id/${RHEL_PROJECT_ID} /images?${FILTER }" )
17
+ " https://catalog.redhat.com/api/containers/v1/projects/certification/id/${RHEL_PROJECT_ID} /images?filter=_id== ${IMAGE_ID }" )
34
18
19
+ echodebug " ${RESPONSE} "
35
20
echo " ${RESPONSE} "
36
21
}
37
22
38
- wait_for_container_scan ()
39
- {
23
+ # Returns if the the image is _currently_ published
24
+ is_image_published ()
25
+ {
40
26
local IMAGE
41
- local IS_PUBLISHED
27
+ IMAGE= $( get_image )
42
28
43
- IMAGE=$( get_image published)
44
- IS_PUBLISHED=$( echo " ${IMAGE} " | jq -r ' .total' )
29
+ # Return the published status of the most recent repository entry
30
+ jq -r ' .data[].repositories[-1].published' <<< " ${IMAGE}"
31
+ }
32
+
33
+ wait_for_container_scan ()
34
+ {
35
+ local IS_PUBLISHED
36
+ IS_PUBLISHED=$( is_image_published)
45
37
46
- if [[ ${IS_PUBLISHED} == " 1 " ]]; then
38
+ if [[ ${IS_PUBLISHED} == " true " ]]; then
47
39
echo " Image is already published, exiting"
48
40
return 0
49
41
fi
50
42
51
43
local NOF_RETRIES=$(( TIMEOUT_IN_MINS / 2 ))
52
44
# Wait until the image is scanned
53
45
for i in $( seq 1 " ${NOF_RETRIES} " ) ; do
46
+ local IMAGE
54
47
local SCAN_STATUS
55
48
local IMAGE_CERTIFIED
56
49
57
- IMAGE=$( get_image not_published )
50
+ IMAGE=$( get_image)
58
51
SCAN_STATUS=$( echo " ${IMAGE} " | jq -r ' .data[0].container_grades.status' )
59
52
IMAGE_CERTIFIED=$( echo " ${IMAGE} " | jq -r ' .data[0].certified' )
60
53
@@ -84,9 +77,10 @@ wait_for_container_scan()
84
77
85
78
request_operation ()
86
79
{
87
- local operation =$1
80
+ local OPERATION =$1
88
81
89
- echo " Submitting '${operation} ' request for the image ${IMAGE_ID} ..."
82
+ echo " Submitting '${OPERATION} ' request for the image ${IMAGE_ID} ..."
83
+ local RESPONSE
90
84
# https://catalog.redhat.com/api/containers/docs/endpoints/RESTPostImageRequestByCertProjectId.html
91
85
RESPONSE=$( \
92
86
curl --fail \
@@ -96,24 +90,21 @@ request_operation()
96
90
--header " X-API-KEY: ${RHEL_API_KEY} " \
97
91
--header ' Cache-Control: no-cache' \
98
92
--header ' Content-Type: application/json' \
99
- --data " {\" image_id\" :\" ${IMAGE_ID} \" , \" operation\" : \" ${operation } \" }" \
93
+ --data " {\" image_id\" :\" ${IMAGE_ID} \" , \" operation\" : \" ${OPERATION } \" }" \
100
94
" https://catalog.redhat.com/api/containers/v1/projects/certification/id/${RHEL_PROJECT_ID} /requests/images" )
101
95
102
- echo " '${operation } ' response: ${RESPONSE} "
96
+ echo " '${OPERATION } ' response: ${RESPONSE} "
103
97
}
104
98
105
99
wait_for_container_publish ()
106
100
{
107
101
local NOF_RETRIES=$(( TIMEOUT_IN_MINS * 2 ))
108
102
# Wait until the image is published
109
103
for i in $( seq 1 " ${NOF_RETRIES} " ) ; do
110
- local IMAGE
111
104
local IS_PUBLISHED
105
+ IS_PUBLISHED=$( is_image_published)
112
106
113
- IMAGE=$( get_image published)
114
- IS_PUBLISHED=$( echo " ${IMAGE} " | jq -r ' .total' )
115
-
116
- if [[ ${IS_PUBLISHED} == " 1" ]]; then
107
+ if [[ ${IS_PUBLISHED} == " true" ]]; then
117
108
echo " Image is published, exiting."
118
109
return 0
119
110
else
@@ -123,10 +114,23 @@ wait_for_container_publish()
123
114
sleep 30
124
115
125
116
if [[ ${i} == " ${NOF_RETRIES} " ]]; then
126
- IMAGE=$( get_image not_published)
127
-
128
117
echoerr " Timeout! Publish could not be finished"
118
+
119
+ echoerr " Request Status:"
120
+ local IMAGE_REQUESTS
121
+ # https://catalog.redhat.com/api/containers/docs/endpoints/RESTGetImageRequestsByImageId.html
122
+ IMAGE_REQUESTS=$( \
123
+ curl --fail \
124
+ --silent \
125
+ --show-error \
126
+ --header " X-API-KEY: ${RHEL_API_KEY} " \
127
+ " https://catalog.redhat.com/api/containers/v1/images/id/${IMAGE_ID} /requests" )
128
+
129
+ echoerr " ${IMAGE_REQUESTS} "
130
+
129
131
echoerr " Image Status:"
132
+ local IMAGE
133
+ IMAGE=$( get_image)
130
134
echoerr " ${IMAGE} "
131
135
132
136
# Add additional logging context if possible
@@ -137,7 +141,6 @@ wait_for_container_publish()
137
141
TEST_RESULTS=$( curl --fail \
138
142
--silent \
139
143
--show-error \
140
- --request GET \
141
144
--header " X-API-KEY: ${RHEL_API_KEY} " \
142
145
" https://catalog.redhat.com/api/containers/${TEST_RESULTS_ENDPOINT} " )
143
146
echoerr " ${TEST_RESULTS} "
0 commit comments