Automatically tag previous image during release#10367
Open
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a new step in the Cloud Build pipeline to tag the previous version of the Firebase Docker image before publishing a new one. The feedback suggests modernizing the implementation by using gcloud artifacts docker commands instead of legacy gcloud container commands, improving the robustness of tag parsing, and handling cases where the image might not yet exist.
Comment on lines
+170
to
+175
| TAGS=$(gcloud container images list-tags $${IMAGE_NAME} --filter="tags:latest" --format="value(tags)") | ||
| echo "Tags for latest: $${TAGS}" | ||
| PREVIOUS_VERSION=$(echo $${TAGS} | tr ',' '\n' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$$' | head -n 1) | ||
| echo "Detected previous version: $${PREVIOUS_VERSION}" | ||
| if [ -n "$${PREVIOUS_VERSION}" ]; then | ||
| gcloud container images add-tag $${IMAGE_NAME}:latest $${IMAGE_NAME}:no-new-use-public-image-$${PREVIOUS_VERSION} --quiet |
Contributor
There was a problem hiding this comment.
The current implementation uses legacy gcloud container commands and could be more robust when parsing tags.
- Use Artifact Registry Commands: Since the registry is
us-docker.pkg.dev, it is recommended to usegcloud artifacts dockercommands instead of the legacygcloud containercommands. - Handle Missing Images: If the image does not exist yet (e.g., in a new environment or first run), the
gcloudcommand will exit with a non-zero status, which might fail the build depending on the shell environment. Adding|| trueand redirecting stderr ensures the script continues gracefully. - Robust Parsing: Quoting the
TAGSvariable inechoprevents word splitting issues. Usingtr ',;'handles different potential delimiters (semicolon is the default for manygcloudlist values) to ensure tags are correctly split into lines forgrep.
TAGS=$(gcloud artifacts docker images list $${IMAGE_NAME} --filter="tags:latest" --format="value(tags)" 2>/dev/null || true)
echo "Tags for latest: $${TAGS}"
PREVIOUS_VERSION=$(echo "$${TAGS}" | tr ',;' '\n' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$$' | head -n 1)
echo "Detected previous version: $${PREVIOUS_VERSION}"
if [ -n "$${PREVIOUS_VERSION}" ]; then
gcloud artifacts docker tags add $${IMAGE_NAME}:latest $${IMAGE_NAME}:no-new-use-public-image-$${PREVIOUS_VERSION} --quiet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Automating one more chore in the release process - on each release, tag the previous release as no-new-use-public-image. We don't republish new versions of these old images with vulnerabilties addressed. Adding this tag opts the images out of future AutoVM scans and signals to users that they should be moving to latest.