Skip to content

Commit 7688f53

Browse files
committed
Further improvements
1 parent f84f549 commit 7688f53

File tree

1 file changed

+39
-36
lines changed

1 file changed

+39
-36
lines changed

.github/scripts/publish-rhel.sh

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,47 @@ set -o errexit -o nounset -o pipefail ${RUNNER_DEBUG:+-x}
77

88
get_image()
99
{
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-
2610
local RESPONSE
2711
# https://catalog.redhat.com/api/containers/docs/endpoints/RESTGetImagesForCertProjectById.html
2812
RESPONSE=$( \
2913
curl --fail \
3014
--silent \
3115
--show-error \
3216
--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}")
3418

19+
echodebug "${RESPONSE}"
3520
echo "${RESPONSE}"
3621
}
3722

38-
wait_for_container_scan()
39-
{
23+
# Returns if the the image is _currently_ published
24+
is_image_published()
25+
{
4026
local IMAGE
41-
local IS_PUBLISHED
27+
IMAGE=$(get_image)
4228

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)
4537

46-
if [[ ${IS_PUBLISHED} == "1" ]]; then
38+
if [[ ${IS_PUBLISHED} == "true" ]]; then
4739
echo "Image is already published, exiting"
4840
return 0
4941
fi
5042

5143
local NOF_RETRIES=$(( TIMEOUT_IN_MINS / 2 ))
5244
# Wait until the image is scanned
5345
for i in $(seq 1 "${NOF_RETRIES}"); do
46+
local IMAGE
5447
local SCAN_STATUS
5548
local IMAGE_CERTIFIED
5649

57-
IMAGE=$(get_image not_published)
50+
IMAGE=$(get_image)
5851
SCAN_STATUS=$(echo "${IMAGE}" | jq -r '.data[0].container_grades.status')
5952
IMAGE_CERTIFIED=$(echo "${IMAGE}" | jq -r '.data[0].certified')
6053

@@ -84,9 +77,10 @@ wait_for_container_scan()
8477

8578
request_operation()
8679
{
87-
local operation=$1
80+
local OPERATION=$1
8881

89-
echo "Submitting '${operation}' request for the image ${IMAGE_ID}..."
82+
echo "Submitting '${OPERATION}' request for the image ${IMAGE_ID}..."
83+
local RESPONSE
9084
# https://catalog.redhat.com/api/containers/docs/endpoints/RESTPostImageRequestByCertProjectId.html
9185
RESPONSE=$( \
9286
curl --fail \
@@ -96,24 +90,21 @@ request_operation()
9690
--header "X-API-KEY: ${RHEL_API_KEY}" \
9791
--header 'Cache-Control: no-cache' \
9892
--header 'Content-Type: application/json' \
99-
--data "{\"image_id\":\"${IMAGE_ID}\" , \"operation\" : \"${operation}\" }" \
93+
--data "{\"image_id\":\"${IMAGE_ID}\" , \"operation\" : \"${OPERATION}\" }" \
10094
"https://catalog.redhat.com/api/containers/v1/projects/certification/id/${RHEL_PROJECT_ID}/requests/images")
10195

102-
echo "'${operation}' response: ${RESPONSE}"
96+
echo "'${OPERATION}' response: ${RESPONSE}"
10397
}
10498

10599
wait_for_container_publish()
106100
{
107101
local NOF_RETRIES=$(( TIMEOUT_IN_MINS * 2 ))
108102
# Wait until the image is published
109103
for i in $(seq 1 "${NOF_RETRIES}"); do
110-
local IMAGE
111104
local IS_PUBLISHED
105+
IS_PUBLISHED=$(is_image_published)
112106

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
117108
echo "Image is published, exiting."
118109
return 0
119110
else
@@ -123,10 +114,23 @@ wait_for_container_publish()
123114
sleep 30
124115

125116
if [[ ${i} == "${NOF_RETRIES}" ]]; then
126-
IMAGE=$(get_image not_published)
127-
128117
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+
129131
echoerr "Image Status:"
132+
local IMAGE
133+
IMAGE=$(get_image)
130134
echoerr "${IMAGE}"
131135

132136
# Add additional logging context if possible
@@ -137,7 +141,6 @@ wait_for_container_publish()
137141
TEST_RESULTS=$(curl --fail \
138142
--silent \
139143
--show-error \
140-
--request GET \
141144
--header "X-API-KEY: ${RHEL_API_KEY}" \
142145
"https://catalog.redhat.com/api/containers/${TEST_RESULTS_ENDPOINT}")
143146
echoerr "${TEST_RESULTS}"

0 commit comments

Comments
 (0)