Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure docker registry - bash script to check if a docker tag already exists

What I need is to build an image (as a CI product) and push it only if the tag version is not on our private azure hosted docker registry already.

Following this stackoverflow answer I tried to replicate the bash script there with the azure registery login server but it does not seem to support the exact same api (getting a 404). How can I achieve this "check if version/tag exists in registry" via the http/REST api with azure container registry? (Without using the built in az tool)

like image 836
alonisser Avatar asked Dec 06 '25 05:12

alonisser


1 Answers

How can I achieve this "check if version/tag exists in registry" via the http/REST api with azure container registry?

In Azure container registry, we should use Authorization: Basic to authenticate it.

You can use ACR username and password to get the credentials, then use this script to list all tags:

export registry="jasonacrr.azurecr.io"
export user="jasonacrr"
export password="t4AH+K86xxxxxxx2SMxxxxxzjNAMVOFb3c" 
export operation="/v2/aci-helloworld/tags/list" 
export credentials=$(echo -n "$user:$password" | base64 -w 0) 
export catalog=$(curl -s -H "Authorization: Basic $credentials" https://$registry$operation)
echo "Catalog"
echo $catalog

Output like this:

[root@jasoncli jason]# echo $catalog
{"name":"aci-helloworld","tags":["v1","v2"]}

Then you can use shell to check the tag existing or not.

Hope this helps.


Update:

More information about Azure container registry integration with Azure AD, please refer to this article.

like image 170
Jason Ye Avatar answered Dec 09 '25 00:12

Jason Ye