Skip to content

Commit 130cd61

Browse files
authored
ci: Skopeo: Update latest tag when uploading a new version (#448)
1 parent 7c5b7d4 commit 130cd61

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

taskcluster/docker/skopeo/push_image.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,31 @@ umoci insert --image ${NAME}:final version.json /version.json
3838

3939
echo "=== Pushing to docker hub ==="
4040
DOCKER_TAG="${NAME}-v${VERSION}"
41+
42+
# Get all remote tags | jq filter only starting with ${NAME}-v | Sort by version | Get the last one
43+
LATEST_REMOTE_VERSION=$(skopeo list-tags docker://$DOCKER_REPO | jq ".Tags[] | select(. | test(\"^${NAME}-v\\\\d\"))" -r | sort -V | tail -1)
44+
4145
skopeo copy oci:${NAME}:final docker://$DOCKER_REPO:$DOCKER_TAG
4246
skopeo inspect docker://$DOCKER_REPO:$DOCKER_TAG
4347

48+
# This bit is intentionally verbose so it's easier to track when we override the latest tag
49+
if [ "${LATEST_REMOTE_VERSION}" = "" ]; then
50+
echo "Couldn't find a remote version. Tagging as latest."
51+
skopeo copy oci:${NAME}:final docker://$DOCKER_REPO:$NAME-latest
52+
elif [ "${LATEST_REMOTE_VERSION}" = "${DOCKER_TAG}" ]; then
53+
echo "Updating latest tag, the latest version on remote matches the provided version."
54+
skopeo copy oci:${NAME}:final docker://$DOCKER_REPO:$NAME-latest
55+
else
56+
# Printf the latest remote version and the current tag | Sort by version | Get the last one
57+
LATEST_VERSION=$(printf "$REMOTE_VERSION\n$DOCKER_TAG" | sort -V | tail -1)
58+
# If current tag > latest remote, then we should tag as latest
59+
if [ "${LATEST_VERSION}" != "${REMOTE_VERSION}" ]; then
60+
echo "Updating latest tag, the current version is higher than the remote."
61+
skopeo copy oci:${NAME}:final docker://$DOCKER_REPO:$NAME-latest
62+
else
63+
echo "Skipped tagging as current tag is not higher than the remote's latest."
64+
fi
65+
fi
66+
4467
echo "=== Clean up ==="
4568
rm -rf $HOME/.docker

0 commit comments

Comments
 (0)