3

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)

alonisser
  • 11,542
  • 21
  • 85
  • 139

1 Answers1

3

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.

Jason Ye
  • 13,710
  • 2
  • 16
  • 25
  • Thanks, can you please point to the docs showing this? I was searching for this for quite a while – alonisser Apr 03 '18 at 10:57
  • 1
    Strange I get an authorization error: ```{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":[{"Type":"repository","Name":"myrepo","Action":"pull"}]}]}``` – alonisser Apr 03 '18 at 12:35
  • @alonisser have you enable ACR user login? – Jason Ye Apr 03 '18 at 12:37
  • You mean admin user flag? I can do docker login https://$registry -u $user -p $password with the credentials supplied – alonisser Apr 03 '18 at 13:42
  • @alonisser Sorry, I am out of office now, I will check it tomorrow:) – Jason Ye Apr 03 '18 at 13:51
  • @alonisser Could you please check your script and user name and password, When I use wrong password, I get the same error message as you. – Jason Ye Apr 04 '18 at 01:42
  • @alonisser I have update my answer with ACR docs, please check it. that script works fine, please try it:) – Jason Ye Apr 04 '18 at 02:00
  • Works! thanks. the problem was jq (I was using to extract the username in the script from acr response) was adding extra " around the string, using ```jq -r``` solved it, so the hash was now correct – alonisser Apr 07 '18 at 16:42