From 635e64e30066b31647409072324f191e8934e8a5 Mon Sep 17 00:00:00 2001 From: Dmitriy Safronov Date: Fri, 25 Mar 2022 15:51:31 +0300 Subject: [PATCH 1/3] errors --- entrypoint.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 09aa92e..a31e861 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -25,9 +25,14 @@ test -n "${TO_DIE}" && exit 1 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" | jq -r .token)" +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> /dev/null | jq -r .token)" +test -z "${TOKEN}" && die "Could not obtain token" -MANIFEST="$(curl -H "${CONTENT_TYPE}" -H "Authorization: Bearer ${TOKEN}" "${REGISTRY_SCHEMA:-https}://${CI_REGISTRY}/v2/${IMAGE_PATH}/manifests/${REGISTRY_TAG_OLD}")" +MANIFEST="$(curl -H "${CONTENT_TYPE}" -H "Authorization: Bearer ${TOKEN}" "${REGISTRY_SCHEMA:-https}://${CI_REGISTRY}/v2/${IMAGE_PATH}/manifests/${REGISTRY_TAG_OLD}" 2> /dev/null)" +test -z "${TOKEN}" && die "Could not obtain 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}" && \ -echo "New image: ${CI_REGISTRY}/${IMAGE_PATH}:${REGISTRY_TAG_NEW}" +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> /dev/null && \ +echo "New image: ${CI_REGISTRY}/${IMAGE_PATH}:${REGISTRY_TAG_NEW}" || die "Could not set tag" + +########################################################################################################################## +test -n "${TO_DIE}" && exit 1 -- GitLab From 97a9ad3b84a325438ceb5e13e2fb786e8987ad00 Mon Sep 17 00:00:00 2001 From: Dmitriy Safronov Date: Fri, 25 Mar 2022 15:54:31 +0300 Subject: [PATCH 2/3] hadolint --- .hadolint.yaml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .hadolint.yaml diff --git a/.hadolint.yaml b/.hadolint.yaml new file mode 100644 index 0000000..e4170d8 --- /dev/null +++ b/.hadolint.yaml @@ -0,0 +1,3 @@ +ignored: + - DL3007 + - DL3018 -- GitLab From 85a29fc82ba89cf5d3d36a821d2ff1ea682661b0 Mon Sep 17 00:00:00 2001 From: Dmitriy Safronov Date: Fri, 25 Mar 2022 16:11:25 +0300 Subject: [PATCH 3/3] fix --- entrypoint.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index a31e861..ff26060 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -23,16 +23,17 @@ test -z "${REGISTRY_TAG_NEW}" && REGISTRY_TAG_NEW=latest test -n "${TO_DIE}" && exit 1 ########################################################################################################################## +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> /dev/null | jq -r .token)" -test -z "${TOKEN}" && die "Could not obtain token" +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}" -MANIFEST="$(curl -H "${CONTENT_TYPE}" -H "Authorization: Bearer ${TOKEN}" "${REGISTRY_SCHEMA:-https}://${CI_REGISTRY}/v2/${IMAGE_PATH}/manifests/${REGISTRY_TAG_OLD}" 2> /dev/null)" -test -z "${TOKEN}" && die "Could not obtain manifest" +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}" -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> /dev/null && \ -echo "New image: ${CI_REGISTRY}/${IMAGE_PATH}:${REGISTRY_TAG_NEW}" || die "Could not set tag" +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 "New image: ${CI_REGISTRY}/${IMAGE_PATH}:${REGISTRY_TAG_NEW}" || cat "${TEMPFILE}" ########################################################################################################################## -test -n "${TO_DIE}" && exit 1 +rm -f "${TEMPFILE}" -- GitLab