Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pkg/e2e/compose_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,24 @@ func TestEnvInterpolation(t *testing.T) {
})
}

func TestEnvSelfReference(t *testing.T) {
c := NewParallelCLI(t)

t.Run("self-referencing variables expand within env file", func(t *testing.T) {
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/environment/env-self-reference/compose.yaml", "config")
res.Assert(t, icmd.Expected{Out: `FULL_IMAGE: gcr.io/myproject/myapp:latest`})
res.Assert(t, icmd.Expected{Out: `BASE_URL: gcr.io/myproject/subpath`})
})

t.Run("OS env overrides base variable and cascades through references", func(t *testing.T) {
cmd := c.NewDockerComposeCmd(t, "-f", "./fixtures/environment/env-self-reference/compose.yaml", "config")
cmd.Env = append(cmd.Env, "REGISTRY_URL=override.io")
res := icmd.RunCmd(cmd)
res.Assert(t, icmd.Expected{Out: `FULL_IMAGE: override.io/myapp:latest`})
res.Assert(t, icmd.Expected{Out: `BASE_URL: override.io/subpath`})
})
}

func TestCommentsInEnvFile(t *testing.T) {
c := NewParallelCLI(t)

Expand Down
4 changes: 4 additions & 0 deletions pkg/e2e/fixtures/environment/env-self-reference/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
REGISTRY_URL=gcr.io/myproject
IMAGE_NAME=myapp
FULL_IMAGE=${REGISTRY_URL}/${IMAGE_NAME}:latest
BASE_URL=${REGISTRY_URL}/subpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
test:
image: bash
environment:
FULL_IMAGE: ${FULL_IMAGE}
BASE_URL: ${BASE_URL}
command: echo "ok"