I need to add a tag on an image on a repo in Google Container Registry, and I was wondering whether this could be done without having to install docker locally and doing pull
, tag
, push
on the image. I know how to do so using the UI, but I wanted to automate this process.
Thanks.
If you are looking for a Google Container Registry specific solution, you can use the gcloud container images add-tag
command. For example:
gcloud container images add-tag gcr.io/myproject/myimage:mytag1 \
gcr.io/myproject/myimage:mytag2
Reference: https://cloud.google.com/sdk/gcloud/reference/container/images/add-tag
If you want to use code, I'd suggest taking a look at those libraries
If you don't want to use Docker you have the option to use the gcloud command line, you need just to configured Docker to use gcloud as a credential helper:
gcloud auth configure-docker
After that you can List images by their storage location:
gcloud container images list --repository=[HOSTNAME]/[PROJECT-ID]
Or List the versions of an image
gcloud container images list-tags [HOSTNAME]/[PROJECT-ID]/[IMAGE]
And you can as well Tag images
gcloud container images add-tag \
[HOSTNAME]/[PROJECT-ID]/[IMAGE]:[TAG] \
[HOSTNAME]/[PROJECT-ID]/[IMAGE]:[NEW_TAG]
or
gcloud container images add-tag \
[HOSTNAME]/[PROJECT-ID]/[IMAGE]@[IMAGE_DIGEST] \
[HOSTNAME]/[PROJECT-ID]/[IMAGE]:[NEW_TAG]
All the described above can be done trough the UI as well.
For your question "I wanted to automate this process" not sure what are you looking for but you can create a bash script including the gcloud command and run it from you cloud shell
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With