Skip to content

refactor: inject Topo-generated env vars into process environment once at start-up - #418

Merged
awphi merged 5 commits into
mainfrom
global-env-vars
Aug 20, 2026
Merged

refactor: inject Topo-generated env vars into process environment once at start-up#418
awphi merged 5 commits into
mainfrom
global-env-vars

Conversation

@awphi

@awphi awphi commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Background

#413 introduced compose-style interpolation in deployment_success_message. Originally this was achived by creating env vars in the CLI and injecting them into all docker compose subprocesses and compose-go calls. We downscoped this to only inject at call sites where it was needed i.e. post_deploy.go.

This has had the unfortunate consequence of causing docker compose and compose-go calls to raise a bunch of warnings when your x-topo block contains one of these env vars without a fallback value e.g.

# compose.yaml
services:
  welcome-service:
    platform: linux/arm64
    image: busybox:latest

x-topo:
  deployment_success_message: "Welcome service deployed successfully! Access it at http://${TOPO_TARGET_HOSTNAME}:8080"
❯ go run ../cmd/topo deploy --target localhost
WARN[0000] The "TOPO_TARGET_HOSTNAME" variable is not set. Defaulting to a blank string.
11:10:46 WARN registry transfer is not yet supported with this configuration. Falling back to direct transfer.

┌─ Build images ────────────────────────────────────────
WARN[0000] The "TOPO_TARGET_HOSTNAME" variable is not set. Defaulting to a blank string.
WARN[0000] No services to build

┌─ Pull images ─────────────────────────────────────────
WARN[0000] The "TOPO_TARGET_HOSTNAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "TOPO_TARGET_HOSTNAME" variable is not set. Defaulting to a blank string.
[+] pull 1/1
 ✔ Image busybox:latest Pulled                                                                                        0.7s

┌─ Start services ──────────────────────────────────────
WARN[0000] The "TOPO_TARGET_HOSTNAME" variable is not set. Defaulting to a blank string.
[+] up 1/1
 ✔ Container test-workspace-welcome-service-1 Started                                                                 0.1s

┌─ Deployment Success ──────────────────────────────────
Welcome service deployed successfully! Access it at http://localhost:8080/

Changes

  • Reverts back to the original behaviour of feat: support compose-style interpolation in x-topo attributes #413 with a new implementation - we set the env vars once when parsing the --target flag or env var for the entire process. This means the injected env vars are passed to call compose-go calls (that use WithOsEnv) and subprocess invocations.

Checklist

  • 🤖 This change is covered by tests as required.
  • 🤹 All required manual testing has been performed.
  • 📖 All documentation updates are complete.

awphi added 2 commits August 20, 2026 11:38
Signed-off-by: awphi <26072111+awphi@users.noreply.github.com>
Signed-off-by: awphi <26072111+awphi@users.noreply.github.com>
@awphi
awphi requested a review from a team as a code owner August 20, 2026 10:50
@awphi
awphi marked this pull request as draft August 20, 2026 10:50
Signed-off-by: awphi <26072111+awphi@users.noreply.github.com>
@awphi
awphi marked this pull request as ready for review August 20, 2026 12:04

@muchzill4 muchzill4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I’m still split between this being horrible and or the best thing ever. On one hand we have global env that gets propagated as such to compose, which is a superset of what this does. On the other, it's implicit arguments between layers and would not work if topo was a web service (it is not!).

I think it is the right call (for now at least!). Let’s see if we find this foot-gunny.

Comment thread cmd/topo/root.go Outdated
awphi added 2 commits August 20, 2026 13:37
Signed-off-by: awphi <26072111+awphi@users.noreply.github.com>
@awphi
awphi merged commit 6776e27 into main Aug 20, 2026
5 checks passed
@awphi
awphi deleted the global-env-vars branch August 20, 2026 12:56
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.

2 participants