Tagging release images in Google Artifact Registry
# 🌱|help-and-getting-started
b
Hello, We'd like to set up a scheduled cleanup of our Artifact Registry but we don't want that to affect release images. The idea that would work best with our tool and also sounds like a general good practice would be to tag release images with a release tag. Unfortunately, I can't find a non-hacky way to do that. I tried to fetch info about images garden builds in a given release job - seems like "v-*" tag would be the most reliable - and then use that to locate image in registry to add the release tag using gcloud but none of the solutions is satisfactory. Here's what I tried: - Add
--output=json
flag and grep "v-.\*" on the output - the problem with this solution is that we prefer to see regular logs in pipeline for debugging and monitoring progress and in this way we'd only see json. - Fetch info from one of the logs in
.garden/logs
- the problem here is that grepping gets even more complex and it's relying on the log structure and wording to stay the same which doesn't seem reliable and would be difficult to track Is there any other method you could recommend?
b
Hey @best-flower-46100 thanks a lot for asking; an easy way to identify which images doesn't have the tags would be:
Copy code
gcloud artifacts docker images list $YOUR_REPO_PATH --include-tags --filter='NOT tags~"^v-"'
This command returns the images that don't include the tag v-*. Then to delete them you can use subshells to do something like: *Note: * Please test this in a different repository first and see if it solves the problem you have, running
docker images delete
is a really destructive command, please try to play around with the filters before executing the following command
Copy code
gcloud artifacts docker images delete $(gcloud artifacts docker images list $YOUR_REPO_PATH --include-tags --filter='NOT tags~"^v-"')
To test this and isolate my commands the best practice would be that you create a new repository, push some dummy images without tags and some images created with garden and test if the filters work correctly!
b
Hey, I think I didn't explain myself well, sorry 😄 the v-\* tags are assigned by garden by default. The release rags would probably be in r-\* format. I'd only use v- tags to collect the images built in a given release and then add r- tags to them
b
No worries! So basically you want to just re-tag all of the images that starts with v-* to the format you like that is r-*?
I guess you will need to keep both tags in the image because Garden might be using the v-* tags to identify them and deploy them to Kubernetes. If I understand correctly you just want to add the r-* tag to make sure your automation doesn't delete those images?
b
Yes, exactly. Leaving v- is fine, the -r tag can be additional. And just to make sure we're on the same page - that would only apply to the images built in the release pipeline - not ones we build locally, neither the ones we build in other pipelines.
b
Hey @best-flower-46100 sorry for taking a long time to give you a solution, I already scalated this question to our Garden OSS developers to give you a better answer! Thanks a lot for your patience🌸
6 Views