This commit is contained in:
Artem Lytkin 2026-06-25 13:55:31 +00:00 committed by GitHub
commit cd2fd4f717
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 0 deletions

View file

@ -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)

View file

@ -0,0 +1,4 @@
REGISTRY_URL=gcr.io/myproject
IMAGE_NAME=myapp
FULL_IMAGE=${REGISTRY_URL}/${IMAGE_NAME}:latest
BASE_URL=${REGISTRY_URL}/subpath

View file

@ -0,0 +1,7 @@
services:
test:
image: bash
environment:
FULL_IMAGE: ${FULL_IMAGE}
BASE_URL: ${BASE_URL}
command: echo "ok"