Do not treat multi-stage build stage references as images to pull in ParsedDockerfile#11936
Open
TimurRakhmatullin86 wants to merge 1 commit into
Open
Conversation
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.
What
ParsedDockerfiletreats everyFROMline's first non-flag token as an external image to pre-pull. In a multi-stage Dockerfile, aFROMreferencing a previously declared build stage is an internal reference, not an external image:Before this change,
getDependencyImageNames()returned{alpine:3.17, build}, and Testcontainers attempted to pull an image namedbuildfrom the registry.Impact of the broken behaviour
WARN/retry in the logs when the phantom image does not exist.build,test,base), an unrelated image is actually pulled.The build itself succeeded despite this, so this is about spurious network traffic and log noise rather than failures.
How it is fixed
FROMline pattern now also captures an optionalAS <stage>alias (case-insensitively, matching Docker's semantics).parse()collects declared stage names and skipsFROMimages that reference a previously declared stage. Ordering follows Docker semantics: an alias only shadows an image name after the stage is declared.Existing behaviour is preserved:
--platform/other flags (#2772), tags, digests, trailing content after the image, and stages whose alias is never referenced are all still handled as before;COPY --from=<stage>lines were never matched and still are not.Tests
Added unit tests covering: a stage referenced by a later
FROM(fails without the fix withexpected: ["alpine:3.17"] but was: ["build", "alpine:3.17"]), a typical maven/eclipse-temurin multi-stage file, case-insensitive stage name matching, and unreferenced stage aliases.