Allow ARGs in COPY --from and RUN --mount=from #3551
Draft
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 #2717 (#2412 is also relevant)
Previously, using ARGs in COPY --from or RUN --mounts from was not supported, requiring using an extra intermediate stage. This patch allows global args to be used directly in these locations.
To do this, we need to resolve a dependency issue:
It is theoretically possible to refactor to not have this restriction, however, this is not required to implement the base functionality for global args.
To resolve this, we can use just the global args to evaluate the FROM fields using the toCommand helper, where the stage resolution occurs today.
At some point, it should be possible to implement local arg resolution as well here - however, this requires a change from the current approach of creating an intermediate dispatchState for those components.
@tonistiigi does this seem like a reasonable approach for a first pass?