Skip to content

feat: support bare variable names in web_environment for host env passthrough#8209

Merged
stasadev merged 1 commit intoddev:mainfrom
rfay:20260309_use_existing_host_env
Mar 16, 2026
Merged

feat: support bare variable names in web_environment for host env passthrough#8209
stasadev merged 1 commit intoddev:mainfrom
rfay:20260309_use_existing_host_env

Conversation

@rfay
Copy link
Copy Markdown
Member

@rfay rfay commented Mar 9, 2026

The Issue

web_environment and db_environment entries without a value (e.g. - MY_VAR) were silently dropped by EnvToUniqueEnv, so docker-compose's host environment passthrough feature never worked, even though docker-compose supports it natively.

How This PR Solves The Issue

EnvToUniqueEnv now stores the full original entry string keyed by variable name, rather than requiring = to be present. Bare names pass through as-is to docker-compose, which resolves them from the host environment at container start time. The fmt import is removed as it is no longer needed.

Test cases are added for bare variable names and for override precedence (last entry wins regardless of whether it is bare or KEY=value).

Documentation in customization-extendibility.md is updated to describe the bare variable passthrough syntax.

Manual Testing Instructions

  • Add a bare variable name to web_environment in .ddev/config.yaml:
    web_environment:
      - MY_HOST_VAR
  • Set MY_HOST_VAR=hello in the host shell
  • Run ddev restart && ddev exec env | grep MY_HOST_VAR
  • Expect: MY_HOST_VAR=hello

Automated Testing Overview

TestEnvToUniqueEnv in pkg/ddevapp/config_merge_test.go is extended with cases for bare variable names and override precedence.

Release/Deployment Notes

Backwards compatible. Existing KEY=value entries are unaffected.

Co-Authored-By: Claude Sonnet 4.6 [email protected]

…through

## The Issue

`web_environment` entries without a value (e.g. `- MY_VAR`) were silently
dropped by `EnvToUniqueEnv`, so the docker-compose host environment passthrough
feature never worked, even though docker-compose supports it natively.

## How This PR Solves The Issue

`EnvToUniqueEnv` now stores the full original entry string keyed by variable
name, rather than requiring `=` to be present. Bare names pass through as-is
to docker-compose, which resolves them from the host environment at container
start time. The `fmt` import is removed as it is no longer needed.

Test cases are added for bare variable names and for override precedence
(last entry wins regardless of whether it is bare or `KEY=value`).

Documentation in `customization-extendibility.md` is updated to describe
the bare variable passthrough syntax.

## Manual Testing Instructions

- Add a bare variable name to `web_environment` in `.ddev/config.yaml`:
  `web_environment: [MY_HOST_VAR]`
- Set `MY_HOST_VAR=hello` in the host shell
- Run `ddev restart && ddev exec env | grep MY_HOST_VAR`
- Expect: `MY_HOST_VAR=hello`

## Automated Testing Overview

`TestEnvToUniqueEnv` in `pkg/ddevapp/config_merge_test.go` is extended with
cases for bare variable names and override precedence.

## Release/Deployment Notes

Backwards compatible. Existing `KEY=value` entries are unaffected.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@rfay rfay requested review from a team as code owners March 9, 2026 15:31
@github-actions github-actions Bot added the bugfix label Mar 9, 2026
@rfay rfay changed the title fix: support bare variable names in web_environment for host env passthrough feat: support bare variable names in web_environment for host env passthrough Mar 9, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 9, 2026

@rfay rfay requested a review from stasadev March 10, 2026 12:04
Copy link
Copy Markdown
Member

@stasadev stasadev left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Add a bare variable name to web_environment in .ddev/config.yaml

This already worked in v1.25.1.

And I was only able to reproduce this with web_environment in .ddev/config.<something>.yaml.

@stasadev stasadev merged commit 6d46cb0 into ddev:main Mar 16, 2026
46 of 48 checks passed
@stasadev stasadev deleted the 20260309_use_existing_host_env branch March 16, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants