From f7886a7094168dda4601219ec74af0650128f8c8 Mon Sep 17 00:00:00 2001 From: Dmitriy Safronov Date: Sun, 18 Feb 2024 06:26:29 +0400 Subject: [PATCH] error management Signed-off-by: Dmitriy Safronov --- entrypoint.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 2f6ca05..386ec8f 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -27,13 +27,15 @@ TEMPFILE="$(mktemp)" CONTENT_TYPE="application/vnd.docker.distribution.manifest.v2+json" TOKEN="$(curl --user "${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}" "${SERVER_HOST_SCHEMA:-https}://${CI_SERVER_HOST}/jwt/auth?offline_token=true&service=container_registry&scope=repository:${CI_PROJECT_PATH}:push,pull" 2> "${TEMPFILE}" | jq -r .token)" -test -z "${TOKEN}" && cat "${TEMPFILE}" +test -z "${TOKEN}" && ( cat "${TEMPFILE}"; die "Couldn't get token" ) MANIFEST="$(curl -H "${CONTENT_TYPE}" -H "Authorization: Bearer ${TOKEN}" "${REGISTRY_SCHEMA:-https}://${CI_REGISTRY}/v2/${IMAGE_PATH}/manifests/${REGISTRY_TAG_OLD}" 2> "${TEMPFILE}")" -test -z "${MANIFEST}" && cat "${TEMPFILE}" +test -z "${MANIFEST}" && ( cat "${TEMPFILE}"; die "Couldn't get manifest" ) -curl -X PUT -H "Content-Type: ${CONTENT_TYPE}" -H "Authorization: Bearer ${TOKEN}" -d "${MANIFEST}" "${REGISTRY_SCHEMA:-https}://${CI_REGISTRY}/v2/${IMAGE_PATH}/manifests/${REGISTRY_TAG_NEW}" 2> "${TEMPFILE}" && \ -echo "Image tag: ${CI_REGISTRY}/${IMAGE_PATH}:${REGISTRY_TAG_NEW}" || cat "${TEMPFILE}" +curl -X PUT -H "Content-Type: ${CONTENT_TYPE}" -H "Authorization: Bearer ${TOKEN}" -d "${MANIFEST}" "${REGISTRY_SCHEMA:-https}://${CI_REGISTRY}/v2/${IMAGE_PATH}/manifests/${REGISTRY_TAG_NEW}" 2> "${TEMPFILE}" +test "$?" -gt 0 && ( cat "${TEMPFILE}"; die "Couldn't retag image" ) + +echo "Image tag: ${CI_REGISTRY}/${IMAGE_PATH}:${REGISTRY_TAG_NEW}" ########################################################################################################################## rm -f "${TEMPFILE}" -- GitLab