cloud-build-docker: stop clobbering :latest on PR builds#33
Merged
Conversation
The Tag/Push cache steps unconditionally retagged the freshly-built
image under $_IMAGE_NAME:$_CACHE_TAG and pushed it. That is fine when
$_IMAGE_TAG and $_IMAGE_NAME:$_CACHE_TAG resolve to the same tag
(canonical/master builds, where both are :latest), but breaks on any
first-time PR build:
build_image.py:get_effective_cache_tag() falls back to "latest" when
the requested image_tag_suffix tag does not yet exist in Artifact
Registry. So a first-time PR build runs with
_IMAGE_TAG = $_IMAGE_NAME:revert-nfs (correct)
_CACHE_TAG = latest (read-side fallback)
The Push cache step then publishes the PR's image content under
$_IMAGE_NAME:latest, overwriting whatever master last pushed there.
In Khan/internal-services this manifested as a perpetual drift loop on
the GitHub Actions Runner terraform config: each PR plan and the master
push plan pushed different content to :latest, and the apply workflow's
chained re-plan kept seeing the runner image digest "change" even
though nothing had actually been redeployed.
The Tag/Push cache steps are redundant with the `images:` block — that
block already publishes $_IMAGE_TAG, so canonical (master) builds still
update :latest correctly. The only effect of the removed steps was the
clobber. $_CACHE_TAG continues to serve its read-side purpose in
--cache-from.
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.
Summary
The
cloud-build-dockermodule'scloudbuild.ymlhas an explicit "Tag cache image" + "Push cache image" pair of steps that unconditionally pushes the freshly-built image under$_IMAGE_NAME:$_CACHE_TAG. That tag is chosen as a read-side fallback bybuild_image.py:get_effective_cache_tag()— it falls back to"latest"whenever the caller's requestedimage_tag_suffixdoesn't yet exist in Artifact Registry. So a first-time PR build runs with:…and the cache push step then writes the PR's image content to
$_IMAGE_NAME:latest, overwriting whatever master last pushed there.The Tag/Push cache steps are redundant with the existing
images:block, which already publishes$_IMAGE_TAG— canonical (master) builds still update:latestcorrectly viaimages:. The only effect of the removed steps was the clobber.$_CACHE_TAGcontinues to be used for the read side (--cache-from).Why this matters
This bug caused a perpetual drift loop on
Khan/internal-services's GitHub Actions Runner terraform config. Thedata.external "build_image"data source reads:latest's digest into the plan; when concurrent PR + master plan workflows each pushed different image content to:latest, the apply workflow's chained re-plan kept seeing the runner image digest "change" even when nothing had actually been redeployed, opening repeated terraform-plan PRs.Once this is merged, internal-services bumps
ref=cloud-build-docker-v0.2.0(or v0.3.0) to the new tag.Test plan
cloud-build-docker-v0.4.0) after merging.ref=and run a PR plan against a branch whose tag doesn't yet exist in AR; confirm Cloud Build pushes only$_IMAGE_TAG(the branch tag) and does NOT also push:latest.:latest.