Skip to content

Refactor RHEL publish #981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 47 additions & 58 deletions .github/scripts/publish-rhel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ set -o errexit -o nounset -o pipefail ${RUNNER_DEBUG:+-x}
get_image()
{
local PUBLISHED=$1
local RHEL_PROJECT_ID=$2
local IMAGE_ID=$3
local RHEL_API_KEY=$4

case "${PUBLISHED}" in
"published")
Expand Down Expand Up @@ -39,16 +36,11 @@ get_image()
}

wait_for_container_scan()
{
local RHEL_PROJECT_ID=$1
local IMAGE_ID=$2
local RHEL_API_KEY=$3
local TIMEOUT_IN_MINS=$4

{
local IMAGE
local IS_PUBLISHED

IMAGE=$(get_image published "${RHEL_PROJECT_ID}" "${IMAGE_ID}" "${RHEL_API_KEY}")
IMAGE=$(get_image published)
IS_PUBLISHED=$(echo "${IMAGE}" | jq -r '.total')

if [[ ${IS_PUBLISHED} == "1" ]]; then
Expand All @@ -63,7 +55,7 @@ wait_for_container_scan()
local SCAN_STATUS
local IMAGE_CERTIFIED

IMAGE=$(get_image not_published "${RHEL_PROJECT_ID}" "${IMAGE_ID}" "${RHEL_API_KEY}")
IMAGE=$(get_image not_published)
SCAN_STATUS=$(echo "${IMAGE}" | jq -r '.data[0].container_grades.status')
IMAGE_CERTIFIED=$(echo "${IMAGE}" | jq -r '.data[0].certified')

Expand Down Expand Up @@ -93,16 +85,12 @@ wait_for_container_scan()

publish_the_image()
{
local RHEL_PROJECT_ID=$1
local IMAGE_ID=$2
local RHEL_API_KEY=$3

echo "Starting publishing the image for ${IMAGE_ID}"

local IMAGE
local IMAGE_EXISTS

IMAGE=$(get_image not_published "${RHEL_PROJECT_ID}" "${IMAGE_ID}" "${RHEL_API_KEY}")
IMAGE=$(get_image not_published)
IMAGE_EXISTS=$(echo "${IMAGE}" | jq -r '.total')

if [[ ${IMAGE_EXISTS} == "1" ]]; then
Expand Down Expand Up @@ -138,55 +126,15 @@ publish_the_image()
echo "Created a publish request, please check if the image is published."
}

sync_tags()
{
local RHEL_PROJECT_ID=$1
local IMAGE_ID=$2
local RHEL_API_KEY=$3

echo "Starting sync tags for ${IMAGE_ID}"

local IMAGE
local IMAGE_EXISTS

IMAGE=$(get_image published "${RHEL_PROJECT_ID}" "${IMAGE_ID}" "${RHEL_API_KEY}")
IMAGE_EXISTS=$(echo "${IMAGE}" | jq -r '.total')

if [[ ${IMAGE_EXISTS} == "0" ]]; then
echo "Image you are trying to sync does not exist."
return 1
fi

echo "Syncing tags of the image ${IMAGE_ID}..."
# https://catalog.redhat.com/api/containers/docs/endpoints/RESTPostImageRequestByCertProjectId.html
RESPONSE=$( \
curl --silent \
--retry 5 --retry-all-errors \
--request POST \
--header "X-API-KEY: ${RHEL_API_KEY}" \
--header 'Cache-Control: no-cache' \
--header 'Content-Type: application/json' \
--data "{\"image_id\":\"${IMAGE_ID}\" , \"operation\" : \"sync-tags\" }" \
"https://catalog.redhat.com/api/containers/v1/projects/certification/id/${RHEL_PROJECT_ID}/requests/images")

echo "Response: ${RESPONSE}"
echo "Created a sync-tags request, please check if the tags image are in sync."
}

wait_for_container_publish()
{
local RHEL_PROJECT_ID=$1
local IMAGE_ID=$2
local RHEL_API_KEY=$3
local TIMEOUT_IN_MINS=$4

local NOF_RETRIES=$(( TIMEOUT_IN_MINS * 2 ))
# Wait until the image is published
for i in $(seq 1 "${NOF_RETRIES}"); do
local IMAGE
local IS_PUBLISHED

IMAGE=$(get_image published "${RHEL_PROJECT_ID}" "${IMAGE_ID}" "${RHEL_API_KEY}")
IMAGE=$(get_image published)
IS_PUBLISHED=$(echo "${IMAGE}" | jq -r '.total')

if [[ ${IS_PUBLISHED} == "1" ]]; then
Expand All @@ -206,7 +154,7 @@ wait_for_container_publish()
# Add additional logging context if possible
echoerr "Test Results:"
# https://catalog.redhat.com/api/containers/docs/endpoints/RESTGetTestResultsById.html
get_image not_published "${RHEL_PROJECT_ID}" "${IMAGE_ID}" "${RHEL_API_KEY}" | jq -r '.data[]._links.test_results.href' | while read -r TEST_RESULTS_ENDPOINT; do
get_image not_published | jq -r '.data[]._links.test_results.href' | while read -r TEST_RESULTS_ENDPOINT; do
local TEST_RESULTS
TEST_RESULTS=$(curl --silent \
--request GET \
Expand All @@ -219,3 +167,44 @@ wait_for_container_publish()
fi
done
}

sync_tags()
{
echo "Starting sync tags for ${IMAGE_ID}"

local IMAGE
local IMAGE_EXISTS

IMAGE=$(get_image published)
IMAGE_EXISTS=$(echo "${IMAGE}" | jq -r '.total')

if [[ ${IMAGE_EXISTS} == "0" ]]; then
echo "Image you are trying to sync does not exist."
return 1
fi

echo "Syncing tags of the image ${IMAGE_ID}..."
# https://catalog.redhat.com/api/containers/docs/endpoints/RESTPostImageRequestByCertProjectId.html
RESPONSE=$( \
curl --silent \
--retry 5 --retry-all-errors \
--request POST \
--header "X-API-KEY: ${RHEL_API_KEY}" \
--header 'Cache-Control: no-cache' \
--header 'Content-Type: application/json' \
--data "{\"image_id\":\"${IMAGE_ID}\" , \"operation\" : \"sync-tags\" }" \
"https://catalog.redhat.com/api/containers/v1/projects/certification/id/${RHEL_PROJECT_ID}/requests/images")

echo "Response: ${RESPONSE}"
echo "Created a sync-tags request, please check if the tags image are in sync."
}

RHEL_PROJECT_ID=$1
IMAGE_ID=$2
RHEL_API_KEY=$3
TIMEOUT_IN_MINS=$4

wait_for_container_scan
publish_the_image
wait_for_container_publish
sync_tags
13 changes: 1 addition & 12 deletions .github/workflows/tag_image_push_rhel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,10 @@ jobs:
exit 1
fi

- name: Wait for Scan to Complete
if: inputs.DRY_RUN != 'true'
run: |
source .github/scripts/publish-rhel.sh

wait_for_container_scan "${RHEL_PROJECT_ID}" "${IMAGE_ID}" "${RHEL_API_KEY}" "${TIMEOUT_IN_MINS}"

- name: Publish the Hazelcast Enterprise image
if: inputs.DRY_RUN != 'true'
run: |
source .github/scripts/publish-rhel.sh

publish_the_image "${RHEL_PROJECT_ID}" "${IMAGE_ID}" "${RHEL_API_KEY}"
wait_for_container_publish "${RHEL_PROJECT_ID}" "${IMAGE_ID}" "${RHEL_API_KEY}" "${TIMEOUT_IN_MINS}"
sync_tags "${RHEL_PROJECT_ID}" "${IMAGE_ID}" "${RHEL_API_KEY}"
.github/scripts/publish-rhel.sh "${RHEL_PROJECT_ID}" "${IMAGE_ID}" "${RHEL_API_KEY}" "${TIMEOUT_IN_MINS}"

- name: Check RedHat service status
if: failure()
Expand Down