Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

empty env variable with no value must be unset in container #11965

Merged
merged 1 commit into from
Jul 10, 2024
Merged
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/Microsoft/go-winio v0.6.2
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
github.com/buger/goterm v1.0.4
github.com/compose-spec/compose-go/v2 v2.1.3
github.com/compose-spec/compose-go/v2 v2.1.4-0.20240708103555-327323ea44d4
github.com/containerd/containerd v1.7.18
github.com/davecgh/go-spew v1.1.1
github.com/distribution/reference v0.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+g
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE=
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4=
github.com/compose-spec/compose-go/v2 v2.1.3 h1:bD67uqLuL/XgkAK6ir3xZvNLFPxPScEi1KW7R5esrLE=
github.com/compose-spec/compose-go/v2 v2.1.3/go.mod h1:lFN0DrMxIncJGYAXTfWuajfwj5haBJqrBkarHcnjJKc=
github.com/compose-spec/compose-go/v2 v2.1.4-0.20240708103555-327323ea44d4 h1:jpoA30Hs8qGuT2Rv/mk9pga4y/Glw/5O+jyOCv2la3I=
github.com/compose-spec/compose-go/v2 v2.1.4-0.20240708103555-327323ea44d4/go.mod h1:lFN0DrMxIncJGYAXTfWuajfwj5haBJqrBkarHcnjJKc=
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw=
github.com/containerd/console v1.0.4 h1:F2g4+oChYvBTsASRTz8NP6iIAi97J3TtSAsLbIFn4ro=
Expand Down
21 changes: 21 additions & 0 deletions pkg/e2e/compose_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,24 @@ func TestCommentsInEnvFile(t *testing.T) {
c.RunDockerComposeCmd(t, "--project-name", "env-file-comments", "down", "--rmi", "all")
})
}

func TestUnsetEnv(t *testing.T) {
c := NewParallelCLI(t)
t.Cleanup(func() {
c.RunDockerComposeCmd(t, "--project-name", "empty-variable", "down", "--rmi", "all")
})

t.Run("override env variable", func(t *testing.T) {
c.RunDockerComposeCmd(t, "-f", "./fixtures/environment/empty-variable/compose.yaml", "build")

res := c.RunDockerComposeCmd(t, "-f", "./fixtures/environment/empty-variable/compose.yaml",
"run", "-e", "EMPTY=hello", "--rm", "empty-variable")
res.Assert(t, icmd.Expected{Out: `=hello=`})
})

t.Run("unset env variable", func(t *testing.T) {
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/environment/empty-variable/compose.yaml",
"run", "--rm", "empty-variable")
res.Assert(t, icmd.Expected{Out: `==`})
})
}
17 changes: 17 additions & 0 deletions pkg/e2e/fixtures/environment/empty-variable/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2020 Docker Compose CLI authors
Copy link
Contributor

Choose a reason for hiding this comment

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

2024?


# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM alpine
ENV EMPTY=not_empty
CMD ["sh", "-c", "echo \"=$EMPTY=\""]
7 changes: 7 additions & 0 deletions pkg/e2e/fixtures/environment/empty-variable/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
empty-variable:
build:
context: .
image: empty-variable
environment:
- EMPTY # expect to propagate value from user's env OR unset in container
Loading