Do not rewrite Docker FROM images built from variables - #1212
Merged
Conversation
`UpgradeDockerImageVersion` composed a `ChangeFrom` per (image, oldVersion)
pair. `DockerFrom`'s matcher treats an environment variable as a `*` wildcard
and matches bidirectionally, so `FROM ${IMAGE_NAME}:${IMAGE_TAG}` matched every
one of those globs and was rewritten to a hardcoded `eclipse-temurin:25`.
Replace the ~170 sub-recipes with a single visitor that reads the image name and
tag, skips any reference containing a variable, and bumps only tags whose
leading version is between 8 and the target version.
The digest, not the tag, decides which image is pulled, so carrying the old digest over would keep resolving to the pre-upgrade image.
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.
Fixes #1211
What's changed
UpgradeDockerImageVersionbuilt aChangeFromsub-recipe for every (image, oldVersion) pair — 170 of them when targeting Java 25.DockerFrom's matcher substitutes a*for each environment variable and then matches bidirectionally, so forthe image name matched as
matchesGlob("openjdk", "*")and the tag asmatchesGlob("8*", "*"). The firstChangeFromin the list therefore fired, the$1capture resolved to nothing, and the reference was replaced with a hardcodedeclipse-temurin:25.This replaces the sub-recipe list with a single visitor that:
FROMwhose image name or tag contains a$, since the value can not be determined statically;-jre-alpine,-jdk-jammy, ...);openjdk/adoptopenjdktoeclipse-temurin;eclipse-temurin:25-jre@sha256:<openjdk-11-digest>would keep resolving to the pre-upgrade image.As a side effect the recipe list of the aggregate migrations shrinks considerably:
UpgradeToJava25drops from 1398 to 488 recipes.Tests
Added cases covering
${VAR}and$VARin the image name, the tag, and both; a Dockerfile that mixes a variableFROMwith a literal one; unrelated images; and digest pin removal. The existing parameterized cases are unchanged and still pass.