dev_container: Expand bare $VAR in addition to ${VAR} in Dockerfiles#59280
Open
tnayuki wants to merge 2 commits into
Open
dev_container: Expand bare $VAR in addition to ${VAR} in Dockerfiles#59280tnayuki wants to merge 2 commits into
tnayuki wants to merge 2 commits into
Conversation
Dockerfiles commonly use the bare form \$VAR alongside the braced \${VAR}
form (e.g. `FROM ruby:\$RUBY_VERSION`). The expansion loop only handled
the braced form, so bare references were passed through verbatim, causing
`docker inspect` to fail with the literal string instead of the resolved
value.
Add `expand_dockerfile_var` which handles both forms. Bare \$KEY is
replaced only when not immediately followed by a word character, so
\$RUBY_VERSION2 is not consumed when expanding \$RUBY_VERSION.
Signed-off-by: Toru Nayuki <tnayuki@icloud.com>
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.
When expanding build args in a dev container Dockerfile, only the braced
${VAR}form was substituted. The bare$VARform — which is valid Dockersyntax and common in real-world Dockerfiles — was passed through verbatim.
For example, the Rails dev container images use:
This left
$RUBY_VERSIONunexpanded, so the subsequentdocker inspect/build ran against the literal string
ruby:$RUBY_VERSIONand failed withan invalid reference format.
This adds
expand_dockerfile_var, which substitutes both${VAR}and bare$VAR. Bare$KEYis only replaced when it is not immediately followed bya word character, so expanding
$RUBY_VERSIONdoes not partially consume$RUBY_VERSION2.Self-Review Checklist:
Release Notes:
$VARform