Skip to content

Conversation

@ndeloof
Copy link
Contributor

@ndeloof ndeloof commented Mar 6, 2025

What I did
resolve env_file after active services have been selected, so we don't read (potentially missing) env_file for inactive ones

Related issue
fixes #8713
requires compose-spec/compose-go#751

(not mandatory) A picture of a cute animal, if possible in relation to what you did

@ndeloof ndeloof requested a review from a team as a code owner March 6, 2025 15:18
@ndeloof ndeloof requested review from Copilot and glours and removed request for glours March 6, 2025 15:18
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR ensures that env_file entries are only loaded for active services, preventing potential errors when an env_file does not exist for inactive services.

  • Adds a new compose file fixture with two services where only one references an env_file.
  • Introduces a new end-to-end test to confirm that missing env_file for inactive services does not trigger an error.
  • Adjusts the project environment resolution logic in cmd/compose/compose.go to resolve env_file only after services selection.

Reviewed Changes

File Description
pkg/e2e/fixtures/env_file/compose.yaml New test fixture with two services, one specifying a missing env_file
pkg/e2e/env_file_test.go Added test to verify that env_file for inactive services is not loaded
cmd/compose/compose.go Updated environment resolution order to resolve after services are selected

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

pkg/e2e/env_file_test.go:38

  • Consider adding an assertion to verify that the missing env_file for serviceB is not processed, ensuring the test precisely validates that inactive services do not trigger an env_file load error.
    c.RunDockerComposeCmd(t, "-f", "./fixtures/env_file/compose.yaml", "up", "-d", "serviceA")

Copy link
Contributor

@glours glours left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@ndeloof ndeloof force-pushed the UnusedMissingEnvFile branch from 35f3e64 to 6297e75 Compare March 9, 2025 15:05
@ndeloof ndeloof enabled auto-merge (rebase) March 9, 2025 15:05
@ndeloof ndeloof force-pushed the UnusedMissingEnvFile branch from 6297e75 to de64016 Compare March 9, 2025 15:08
@ndeloof ndeloof force-pushed the UnusedMissingEnvFile branch from de64016 to 2bd65f4 Compare March 10, 2025 07:21
@ndeloof ndeloof merged commit b237289 into docker:main Mar 10, 2025
25 checks passed
@ndeloof ndeloof deleted the UnusedMissingEnvFile branch March 10, 2025 08:14
@masalim2
Copy link

@ndeloof is it possible this change would cause env_file not to be read when a docker compose run command is invoked on a service without specifying its profile explicitly?

Concretely:

service-foo:
  profiles: ["foo"]
  env_file: settings.env
# stuff from settings.env is missing!
$ docker compose run --entrypoint /bin/bash service-foo -c 'printenv'

Apologies if a closed PR is not a good thread for this type of question. I've noticed a regression in my CI suite in moving from Compose 2.33.1 to 2.34.0, and I'm realizing it may be that I was depending on the behavior prior to this change. It doesn't feel exactly like a bug and I wasn't able to put together a quick reproducer.

@ndeloof
Copy link
Contributor Author

ndeloof commented Mar 20, 2025

@masalim2 see #12644

@masalim2
Copy link

Ah I was only looking at open issues and missed this. Thank you!!

tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Mar 26, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [docker/compose](https://github.com/docker/compose) | minor | `v2.33.1` -> `v2.34.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>docker/compose (docker/compose)</summary>

### [`v2.34.0`](https://github.com/docker/compose/releases/tag/v2.34.0)

[Compare Source](docker/compose@v2.33.1...v2.34.0)

#### What's Changed

##### ✨ Improvements

-   Support refresh pull policy by [@&#8203;ndeloof](https://github.com/ndeloof) in docker/compose#12568
-   Introduced `include` to filter files considered by `watch` by [@&#8203;ndeloof](https://github.com/ndeloof) in docker/compose#12584
-   Introduced `--env-from-file` in `docker compose run` command by [@&#8203;ndeloof](https://github.com/ndeloof) in docker/compose#12626
-   Make `publish` a regular command of Compose by [@&#8203;glours](https://github.com/glours) in docker/compose#12629

##### 🐛 Fixes

-   Build: only print COMPOSE_BAKE recommendation when disabled by [@&#8203;emersion](https://github.com/emersion) in docker/compose#12572
-   Improve message suggesting using bake by [@&#8203;glours](https://github.com/glours) in docker/compose#12612
-   Fixed service: reference in additional_contexts for builds without bake by [@&#8203;ndeloof](https://github.com/ndeloof) in docker/compose#12582
-   Block the publication of an OCI artifact if one or more services contain only a build section by [@&#8203;glours](https://github.com/glours) in docker/compose#12597
-   Display the location of OCI or GIT Compose stack download by [@&#8203;glours](https://github.com/glours) in docker/compose#12595
-   Refuse to publish compose file with local include by [@&#8203;ndeloof](https://github.com/ndeloof) in docker/compose#12600
-   `publish`reject compose file with bind mounts by [@&#8203;ndeloof](https://github.com/ndeloof) in docker/compose#12601
-   Display interpolation variables and their values when running a remote stack by [@&#8203;glours](https://github.com/glours) in docker/compose#12604
-   Publish compose file with required siblings used by `extends` by [@&#8203;ndeloof](https://github.com/ndeloof) in docker/compose#12606
-   Add warning message when a remote configuration include an another remote config by [@&#8203;glours](https://github.com/glours) in docker/compose#12610
-   Only load env_file after services have been selected by [@&#8203;ndeloof](https://github.com/ndeloof) in docker/compose#12611
-   Deprecate --y, prefer --yes by [@&#8203;ndeloof](https://github.com/ndeloof) in docker/compose#12623
-   Use Defang secret-detector to identify potential secret leaks before publishing OCI artifacts by [@&#8203;glours](https://github.com/glours) in docker/compose#12620

##### 🔧  Internal

-   Link to configuration file docs by [@&#8203;andrew-kramer](https://github.com/andrew-kramer) in docker/compose#12559
-   Otel attribute to track builder implementation selected by [@&#8203;ndeloof](https://github.com/ndeloof) in docker/compose#12586
-   Test version command by [@&#8203;maxproske](https://github.com/maxproske) in docker/compose#12576
-   Implement extends.file replace without yqlib by [@&#8203;ndeloof](https://github.com/ndeloof) in docker/compose#12615
-   Add `cli.isatty` attribute to spans generated by compose by [@&#8203;landism](https://github.com/landism) in docker/compose#12630
-   Condense output of `compose top` by [@&#8203;dmke](https://github.com/dmke) in docker/compose#12628

##### ⚙️ Dependencies

-   Require go `1.23`|`1.24` (stable) by [@&#8203;ndeloof](https://github.com/ndeloof) in docker/compose#12571
-   Build(deps): bump tags.cncf.io/container-device-interface from 0.8.0 to 0.8.1 by [@&#8203;dependabot](https://github.com/dependabot) in docker/compose#12583
-   Build(deps): bump github.com/google/go-cmp from `0.6.0` to `0.7.0` by [@&#8203;dependabot](https://github.com/dependabot) in docker/compose#12578
-   Build(deps): bump github.com/docker/cli from `28.0.0+incompatible` to `28.0.1+incompatible` by [@&#8203;dependabot](https://github.com/dependabot) in docker/compose#12590
-   Build(deps): bump github.com/docker/docker from `28.0.0+incompatible` to `28.0.1+incompatible` by [@&#8203;dependabot](https://github.com/dependabot) in docker/compose#12591
-   Build(deps): bump github.com/docker/buildx from `0.21.1` to `0.21.2` by [@&#8203;dependabot](https://github.com/dependabot) in docker/compose#12598
-   Build(deps): bump github.com/opencontainers/image-spec from `1.1.0` to `1.1.1` by [@&#8203;dependabot](https://github.com/dependabot) in docker/compose#12599
-   Build(deps): bump golang.org/x/sync from `0.11.0` to `0.12.0` by [@&#8203;dependabot](https://github.com/dependabot) in docker/compose#12607
-   Build(deps): bump google.golang.org/grpc from `1.70.0` to `1.71.0` by [@&#8203;dependabot](https://github.com/dependabot) in docker/compose#12603
-   Build(deps): bump golang.org/x/sys from `0.30.0` to `0.31.0` by [@&#8203;dependabot](https://github.com/dependabot) in docker/compose#12608
-   Build(deps): bump github.com/moby/buildkit from `0.20.0` to `0.20.1` by [@&#8203;dependabot](https://github.com/dependabot) in docker/compose#12609
-   Build(deps): bump tags.cncf.io/container-device-interface from `0.8.1` to `1.0.0` by [@&#8203;dependabot](https://github.com/dependabot) in docker/compose#12617
-   Bump compose-go to version `v2.4.9` by [@&#8203;glours](https://github.com/glours) in docker/compose#12633

#### New Contributors

-   [@&#8203;emersion](https://github.com/emersion) made their first contribution in docker/compose#12572
-   [@&#8203;andrew-kramer](https://github.com/andrew-kramer) made their first contribution in docker/compose#12559
-   [@&#8203;landism](https://github.com/landism) made their first contribution in docker/compose#12630
-   [@&#8203;dmke](https://github.com/dmke) made their first contribution in docker/compose#12628

**Full Changelog**: docker/compose@v2.33.1...v2.34.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4yMTMuNSIsInVwZGF0ZWRJblZlciI6IjM5LjIxMy41IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.env file referenced underneath env_file in a compose file is being parsed when file is not used.

3 participants