Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Make image tag immutable for releases
Browse files Browse the repository at this point in the history
Signed-off-by: Shalier Xia <shalierxia@microsoft.com>
  • Loading branch information
shalier committed Jan 26, 2021
1 parent ddcdb0f commit d06015c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ jobs:
- name: Push images with version tag
env:
CTR_TAG: ${{ needs.version.outputs.version }}
run: make docker-push
run: make docker-push VERIFY_TAGS=1
- name: Push images with latest tag
env:
CTR_TAG: latest
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ docker-build: $(DOCKER_DEMO_TARGETS) docker-build-init docker-build-osm-controll

# docker-push-bookbuyer, etc
DOCKER_PUSH_TARGETS = $(addprefix docker-push-, $(DEMO_TARGETS) init osm-controller)
VERIFY_TAGS = 0
.PHONY: $(DOCKER_PUSH_TARGETS)
$(DOCKER_PUSH_TARGETS): NAME=$(@:docker-push-%=%)
$(DOCKER_PUSH_TARGETS):
make docker-build-$(NAME)
docker push "$(CTR_REGISTRY)/$(NAME):$(CTR_TAG)" || { echo "Error pushing images to container registry $(CTR_REGISTRY)/$(NAME):$(CTR_TAG)"; exit 1; }
@if [ $(VERIFY_TAGS) != 1 ]; then make docker-build-$(NAME); docker push "$(CTR_REGISTRY)/$(NAME):$(CTR_TAG)" || { echo "Error pushing images to container registry $(CTR_REGISTRY)/$(NAME):$(CTR_TAG)"; exit 1; }; else bash scripts/publish-image.sh $(NAME); fi

.PHONY: docker-push
docker-push: $(DOCKER_PUSH_TARGETS)
Expand Down
24 changes: 24 additions & 0 deletions scripts/publish-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
# shellcheck disable=SC1091

IMAGE_TAG=$1
IMAGE_REPO=openservicemesh

if [ -z "${CTR_TAG}" ]
then
echo "Error CTR_TAG is empty"
exit 1
fi

tokenUri="https://auth.docker.io/token?service=registry.docker.io&scope=repository:$IMAGE_REPO/$IMAGE_TAG:pull"
bearerToken="$(curl --silent --get "$tokenUri" | jq --raw-output '.token')"
listUri="https://registry-1.docker.io/v2/$IMAGE_REPO/$IMAGE_TAG/tags/list"
authz="Authorization: Bearer $bearerToken"
version_list="$(curl --silent --get -H "Accept: application/json" -H "$authz" "$listUri" | jq --raw-output '.')"
exists=$(echo "$version_list" | jq --arg t "${CTR_TAG}" '.tags | index($t)')

if [[ $exists == null ]]
then
make docker-build-"$IMAGE_TAG"
docker push "$IMAGE_REPO/$IMAGE_TAG:${CTR_TAG}" || { echo "Error pushing images to container registry $(CTR_REGISTRY)/$(NAME):$(CTR_TAG)"; exit 1; }
fi

0 comments on commit d06015c

Please sign in to comment.