diff --git a/entrypoint.sh b/entrypoint.sh index 2f6ca05e2b156cd8ec37e144653f0581eb53c010..386ec8fc8e1f846cf368d418eef4f166c53d653e 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}"