diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ef61ae9..3a9574d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -40,8 +40,7 @@ test_image: publish_image: stage: "publish" script: - - ./scripts/push-rolling-image.sh - - ./scripts/remove-tag.sh + - ./scripts/promote-image.sh tags: - builder - ubuntu diff --git a/scripts/push-rolling-image.sh b/scripts/promote-image.sh similarity index 67% rename from scripts/push-rolling-image.sh rename to scripts/promote-image.sh index 4fe4b3b..db20a59 100755 --- a/scripts/push-rolling-image.sh +++ b/scripts/promote-image.sh @@ -30,14 +30,14 @@ function fail { cat << EOF -The following will done to publish latest rolling image: +The following will publish latest rolling image: 1. Pull ${CONTAINER}:${TAG} 2. Tag #1 as ${CONTAINER}:${TARGET_TAG} 3. Tag #1 as ${CONTAINER}:latest-${TARGET_TAG} -4. Push #2 -5. Push #3 -6. Delete ${CONTAINER}:${TAG} +4. Delete ${CONTAINER}:${TAG} +5. Push #2 +6. Push #3 EOF @@ -52,6 +52,28 @@ docker tag ${REGISTRY_URL}/${CONTAINER}:${TAG} \ ${REGISTRY_URL}/${CONTAINER}:latest-${TARGET_TAG} || fail "Unable to tag image (2/2)" +# Parse out the FQDN from the REGISTRY_URL and escape +# the group/project/path +FQDN=${REGISTRY_URL%%/*} +PROJECT=$(echo ${REGISTRY_URL#*/}/${CONTAINER} | sed s,/,%2F,g) + +echo -e "Deleting tag:\n ${CONTAINER}:${TAG}\nFrom:\n ${PROJECT}" + +RESULTS=$(curl --noproxy '*' -s -k \ + -u ${HARBOR_USER}:${HARBOR_PASSWD} \ + -i \ + -X DELETE \ + -H "accept: application/json" \ + "https://${FQDN}/api/repositories/${PROJECT}/tags/${TAG}") + +echo ${RESULTS} | grep -q "HTTP.*200" && { + echo "Tag deleted successfully." +} || { + >&2 echo "Error deleting tag:" + >&2 echo "${RESULTS}" + exit 1 +} + docker push ${REGISTRY_URL}/${CONTAINER}:${TARGET_TAG} || fail "Unable to push ${CONTAINER}:${TARGET_TAG}" diff --git a/scripts/remove-tag.sh b/scripts/remove-tag.sh deleted file mode 100755 index 0ef4779..0000000 --- a/scripts/remove-tag.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -# Bring in the variables from SOLUTION file, supporting -# nested substitution -. SOLUTION -. MANIFEST - -VARS=($(sed -nE "s,(^[^#][^=]*).*$,\1,pg" SOLUTION)) -VARS+=($(sed -nE "s,(^[^#][^=]*).*$,\1,pg" MANIFEST)) -for var in ${VARS[@]}; do - export ${var} -done - -RELEASE_INFO=${RELEASE_INFO:-N/A} -[[ "${RELEASE_INFO}" == "N/A" ]] && { - TAG=${TAG:-test-build-${OS_DISTRO}-${PACKAGE_STREAM}-$(date +%Y%m%d)} -} || { - TAG=${TAG:-test-${OS_DISTRO}-${PACKAGE_STREAM}-${RELEASE_INFO}} -} - -# Parse out the FQDN from the REGISTRY_URL and escape -# the group/project/path -FQDN=${REGISTRY_URL%%/*} -PROJECT=$(echo ${REGISTRY_URL#*/}/${CONTAINER} | sed s,/,%2F,g) - -echo -e "Deleting tag:\n ${CONTAINER}:${TAG}\nFrom:\n ${PROJECT}" - -RESULTS=$(curl --noproxy '*' -s -k \ - -u ${HARBOR_USER}:${HARBOR_PASSWD} \ - -i \ - -X DELETE \ - -H "accept: application/json" \ - "https://${FQDN}/api/repositories/${PROJECT}/tags/${TAG}") - -echo ${RESULTS} | grep -q "HTTP.*200" && { - echo "Tag deleted successfully." -} || { - >&2 echo "Error deleting tag:" - >&2 echo "${RESULTS}" - exit 1 -}