CLI operation: Add tag to an existing image
- Dominant language
- Go
- Stars
- 70
- Forks
- 52
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 12
Description
**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:
```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](https://dille.name/blog/2018/09/20/how-to-tag-docker-images-without-pulling-them/))
(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](https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-retag.html). (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](https://cloud.google.com/sdk/gcloud/reference/container/images/add-tag), very similar to what I'm pleading for in this Feature Reguest.
**Current workarounds**
- An ACR 'native' method:
```bash
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](https://github.com/google/go-containerregistry/blob/main/cmd/crane/doc/crane_tag.md). (the otherwise popular tool, Skopeo, cannot do it)
Contributor guide
Assessment
This issue has not been assessed yet.