Skip to content

dev_container: Expand bare $VAR in addition to ${VAR} in Dockerfiles#59280

Merged
Veykril merged 2 commits into
zed-industries:mainfrom
tnayuki:fix/dev-container-bare-dollar-expansion
Jun 15, 2026
Merged

dev_container: Expand bare $VAR in addition to ${VAR} in Dockerfiles#59280
Veykril merged 2 commits into
zed-industries:mainfrom
tnayuki:fix/dev-container-bare-dollar-expansion

Conversation

@tnayuki

@tnayuki tnayuki commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

When expanding build args in a dev container Dockerfile, only the braced
${VAR} form was substituted. The bare $VAR form — which is valid Docker
syntax and common in real-world Dockerfiles — was passed through verbatim.

For example, the Rails dev container images use:

ARG RUBY_VERSION=3.4.4
FROM ghcr.io/rails/devcontainer/images/ruby:$RUBY_VERSION

This left $RUBY_VERSION unexpanded, so the subsequent docker inspect /
build ran against the literal string ruby:$RUBY_VERSION and failed with
an invalid reference format.

This adds expand_dockerfile_var, which substitutes both ${VAR} and bare
$VAR. Bare $KEY is only replaced when it is not immediately followed by
a word character, so expanding $RUBY_VERSION does not partially consume
$RUBY_VERSION2.

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Fixed dev container Dockerfiles not expanding build args written in the bare $VAR form

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>
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jun 14, 2026
@zed-community-bot zed-community-bot Bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Jun 14, 2026
@ChristopherBiscardi ChristopherBiscardi added the area:dev containers Feedback for Zed's dev containers feature label Jun 15, 2026

@Veykril Veykril left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Veykril Veykril enabled auto-merge June 15, 2026 06:47
@Veykril Veykril added this pull request to the merge queue Jun 15, 2026
Merged via the queue into zed-industries:main with commit 832ab56 Jun 15, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:dev containers Feedback for Zed's dev containers feature cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants