Skip to content

Commit

Permalink
Merge pull request #9 from psu-libraries/tag-release-fix
Browse files Browse the repository at this point in the history
new tag release file for single repo apps
  • Loading branch information
lauterman authored Aug 26, 2024
2 parents 28fa59e + 85f0cab commit 9e3c85f
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions bin/tag-image-singlerepo
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
# tag an existing image without needing to pull it first
set -u

REGISTRY_NAME="${REGISTRY_HOST}"
REPOSITORY="${REGISTRY_REPO}"
TAG_OLD="${CIRCLE_SHA1}"
CONTENT_TYPE="application/vnd.docker.distribution.manifest.v2+json"
DOCKER_USERNAME="${DOCKER_USERNAME}"
DOCKER_PASSWORD="${DOCKER_PASSWORD}"
TAG_NEW=${CIRCLE_TAG}

# find latest image build
i=0
message=$(git log --pretty=oneline --skip=$i -1 | grep 'skip ci')
while [[ $message ]]
do
((i++))
message=$(git log --pretty=oneline --skip=$i -1 | grep 'skip ci')
done
TAG_OLD=$(git log --pretty=oneline --skip=$i -1 --format=%H)

# get manifest of latest image build
MANIFEST=$(curl -u "$DOCKER_USERNAME:$DOCKER_PASSWORD" --silent --fail -H "Accept: ${CONTENT_TYPE}" "https://${REGISTRY_NAME}/v2/${REPOSITORY}/manifests/${TAG_OLD}")

if [ "$?" != "0" ]; then
echo "Failed to get manifest for ${REGISTRY_HOST}/${REGISTRY_REPO}:${TAG_OLD}"
exit 1
fi

echo "tagging ${REGISTRY_HOST}/${REGISTRY_REPO}:${TAG_OLD} with tag ${TAG_NEW}"

curl --fail -u "$DOCKER_USERNAME:$DOCKER_PASSWORD" -X PUT -H "Content-Type: ${CONTENT_TYPE}" -d "${MANIFEST}" "https://${REGISTRY_NAME}/v2/${REPOSITORY}/manifests/${TAG_NEW}"

0 comments on commit 9e3c85f

Please sign in to comment.