empty env variable with no value must be unset in container

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2024-07-04 10:29:05 +02:00 коммит произвёл Guillaume Lours
Родитель 25f85938bb
Коммит 163cdfd31d
5 изменённых файлов: 48 добавлений и 3 удалений

2
go.mod
Просмотреть файл

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

4
go.sum
Просмотреть файл

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

Просмотреть файл

@ -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: `==`})
})
}

Просмотреть файл

@ -0,0 +1,17 @@
# Copyright 2020 Docker Compose CLI authors
# 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=\""]

Просмотреть файл

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