mirror of
https://github.com/moby/moby.git
synced 2025-07-30 18:23:29 +03:00
Add --env-file
flag to docker create service
This fix tries to address the issue in 24712 and add `--env-file` file to `docker create service`. Related documentation has been updated. An additional integration has been added. This fix fixes 24712. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
@ -9,6 +9,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -568,3 +569,22 @@ func (s *DockerSwarmSuite) TestSwarmNetworkPlugin(c *check.C) {
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(strings.TrimSpace(out), checker.Equals, "foo")
|
||||
}
|
||||
|
||||
// Test case for #24712
|
||||
func (s *DockerSwarmSuite) TestSwarmServiceEnvFile(c *check.C) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
path := filepath.Join(d.folder, "env.txt")
|
||||
err := ioutil.WriteFile(path, []byte("VAR1=A\nVAR2=A\n"), 0644)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
name := "worker"
|
||||
out, err := d.Cmd("service", "create", "--env-file", path, "--env", "VAR1=B", "--env", "VAR1=C", "--env", "VAR2=", "--env", "VAR2", "--name", name, "busybox", "top")
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
|
||||
|
||||
// The complete env is [VAR1=A VAR2=A VAR1=B VAR1=C VAR2= VAR2] and duplicates will be removed => [VAR1=C VAR2]
|
||||
out, err = d.Cmd("inspect", "--format", "{{ .Spec.TaskTemplate.ContainerSpec.Env }}", name)
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(out, checker.Contains, "[VAR1=C VAR2]")
|
||||
}
|
||||
|
Reference in New Issue
Block a user