CLI operation: Add tag to an existing image
What is the problem you're trying to solve For CI/CD pipelines it is often the case that a tag needs to be applied to an existing image in the registry. (Just Google how often this question comes up).
Describe the solution you'd like
Direct support in the az acr CLI with a solution that doesn't imply pull-then-push.
It is technically possibly to do the operation via the Docker Registry API so there's no reason not support it via the CLI. Here is what it would look like with curl/bash:
REGISTRY_NAME="https://myacrregistry.azurecr.io"
REPOSITORY=foo/bar/baz
TAG_OLD=xxx
TAG_NEW=yyy
CONTENT_TYPE="application/vnd.docker.distribution.manifest.v2+json"
MANIFEST=$(curl -H "Accept: ${CONTENT_TYPE}" "${REGISTRY_NAME}/v2/${REPOSITORY}/manifests/${TAG_OLD}")
curl -X PUT -H "Content-Type: ${CONTENT_TYPE}" -d "${MANIFEST}" "${REGISTRY_NAME}/v2/${REPOSITORY}/manifests/${TAG_NEW}"
(ref)
(The above is meant to describe what to do from an API point of view, not a recipe for a current workaround on ACR.)
What do competitors do?
-
AWS: Have documented as way to do this HERE. (not sure why they didn't take it one step further and added it to their CLI)
-
Google Cloud: Has direct support in their CLI, very similar to what I'm pleading for in this Feature Reguest.
Current workarounds
- An ACR 'native' method:
az acr import \
--name myacrregistry \
--source myacrregistry.azurecr.io/foo/bar/baz:xxx \
--image foo/bar/baz:yyy \
--force
which will add the tag yyy to the existing image foo/bar/baz:xxx. This is for sure a sub-optimal workaround as it will first pull the image and then push it. Which is what we are trying to avoid. But at the very least it is performed "locally" on the same Azure region.
- Use a third-party tool. For example Google crane. (the otherwise popular tool, Skopeo, cannot do it)