mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add integration test for stack deploy.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
b45581b786
commit
eefccc25c5
4 changed files with 31 additions and 67 deletions
|
@ -19,8 +19,8 @@ import (
|
||||||
"github.com/docker/docker/cli"
|
"github.com/docker/docker/cli"
|
||||||
"github.com/docker/docker/cli/command"
|
"github.com/docker/docker/cli/command"
|
||||||
servicecmd "github.com/docker/docker/cli/command/service"
|
servicecmd "github.com/docker/docker/cli/command/service"
|
||||||
runconfigopts "github.com/docker/docker/runconfig/opts"
|
|
||||||
"github.com/docker/docker/opts"
|
"github.com/docker/docker/opts"
|
||||||
|
runconfigopts "github.com/docker/docker/runconfig/opts"
|
||||||
"github.com/docker/go-connections/nat"
|
"github.com/docker/go-connections/nat"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -85,7 +85,12 @@ func runDeploy(dockerCli *command.DockerCli, opts deployOptions) error {
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
namespace := namespace{name: opts.namespace}
|
namespace := namespace{name: opts.namespace}
|
||||||
if err := createNetworks(ctx, dockerCli, config.Networks, namespace); err != nil {
|
|
||||||
|
networks := config.Networks
|
||||||
|
if networks == nil {
|
||||||
|
networks = make(map[string]composetypes.NetworkConfig)
|
||||||
|
}
|
||||||
|
if err := createNetworks(ctx, dockerCli, networks, namespace); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return deployServices(ctx, dockerCli, config, namespace, opts.sendRegistryAuth)
|
return deployServices(ctx, dockerCli, config, namespace, opts.sendRegistryAuth)
|
||||||
|
|
|
@ -141,7 +141,6 @@ func (c *containerConfig) config() *enginecontainer.Config {
|
||||||
Labels: c.labels(),
|
Labels: c.labels(),
|
||||||
Tty: c.spec().TTY,
|
Tty: c.spec().TTY,
|
||||||
User: c.spec().User,
|
User: c.spec().User,
|
||||||
Hostname: c.spec().Hostname,
|
|
||||||
Env: c.spec().Env,
|
Env: c.spec().Env,
|
||||||
Hostname: c.spec().Hostname,
|
Hostname: c.spec().Hostname,
|
||||||
WorkingDir: c.spec().Dir,
|
WorkingDir: c.spec().Dir,
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/integration/checker"
|
"github.com/docker/docker/pkg/integration/checker"
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
)
|
)
|
||||||
|
@ -41,72 +38,26 @@ func (s *DockerSwarmSuite) TestStackServices(c *check.C) {
|
||||||
c.Assert(out, check.Equals, "Nothing found in stack: UNKNOWN_STACK\n")
|
c.Assert(out, check.Equals, "Nothing found in stack: UNKNOWN_STACK\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
// testDAB is the DAB JSON used for testing.
|
func (s *DockerSwarmSuite) TestStackDeployComposeFile(c *check.C) {
|
||||||
// TODO: Use template/text and substitute "Image" with the result of
|
|
||||||
// `docker inspect --format '{{index .RepoDigests 0}}' busybox:latest`
|
|
||||||
const testDAB = `{
|
|
||||||
"Version": "0.1",
|
|
||||||
"Services": {
|
|
||||||
"srv1": {
|
|
||||||
"Image": "busybox@sha256:e4f93f6ed15a0cdd342f5aae387886fba0ab98af0a102da6276eaf24d6e6ade0",
|
|
||||||
"Command": ["top"]
|
|
||||||
},
|
|
||||||
"srv2": {
|
|
||||||
"Image": "busybox@sha256:e4f93f6ed15a0cdd342f5aae387886fba0ab98af0a102da6276eaf24d6e6ade0",
|
|
||||||
"Command": ["tail"],
|
|
||||||
"Args": ["-f", "/dev/null"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}`
|
|
||||||
|
|
||||||
func (s *DockerSwarmSuite) TestStackWithDAB(c *check.C) {
|
|
||||||
testRequires(c, ExperimentalDaemon)
|
testRequires(c, ExperimentalDaemon)
|
||||||
// setup
|
|
||||||
testStackName := "test"
|
|
||||||
testDABFileName := testStackName + ".dab"
|
|
||||||
defer os.RemoveAll(testDABFileName)
|
|
||||||
err := ioutil.WriteFile(testDABFileName, []byte(testDAB), 0444)
|
|
||||||
c.Assert(err, checker.IsNil)
|
|
||||||
d := s.AddDaemon(c, true, true)
|
d := s.AddDaemon(c, true, true)
|
||||||
// deploy
|
|
||||||
stackArgs := []string{"stack", "deploy", testStackName}
|
testStackName := "testdeploy"
|
||||||
|
stackArgs := []string{
|
||||||
|
"stack", "deploy",
|
||||||
|
"--compose-file", "fixtures/deploy/default.yaml",
|
||||||
|
testStackName,
|
||||||
|
}
|
||||||
out, err := d.Cmd(stackArgs...)
|
out, err := d.Cmd(stackArgs...)
|
||||||
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
||||||
|
|
||||||
|
out, err = d.Cmd([]string{"stack", "ls"}...)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(out, checker.Contains, "Loading bundle from test.dab\n")
|
c.Assert(out, check.Equals, "NAME SERVICES\n"+"testdeploy 2\n")
|
||||||
c.Assert(out, checker.Contains, "Creating service test_srv1\n")
|
|
||||||
c.Assert(out, checker.Contains, "Creating service test_srv2\n")
|
out, err = d.Cmd([]string{"stack", "rm", testStackName}...)
|
||||||
// ls
|
|
||||||
stackArgs = []string{"stack", "ls"}
|
|
||||||
out, err = d.Cmd(stackArgs...)
|
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(out, check.Equals, "NAME SERVICES\n"+"test 2\n")
|
out, err = d.Cmd([]string{"stack", "ls"}...)
|
||||||
// rm
|
|
||||||
stackArgs = []string{"stack", "rm", testStackName}
|
|
||||||
out, err = d.Cmd(stackArgs...)
|
|
||||||
c.Assert(err, checker.IsNil)
|
|
||||||
c.Assert(out, checker.Contains, "Removing service test_srv1\n")
|
|
||||||
c.Assert(out, checker.Contains, "Removing service test_srv2\n")
|
|
||||||
// ls (empty)
|
|
||||||
stackArgs = []string{"stack", "ls"}
|
|
||||||
out, err = d.Cmd(stackArgs...)
|
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(out, check.Equals, "NAME SERVICES\n")
|
c.Assert(out, check.Equals, "NAME SERVICES\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSwarmSuite) TestStackWithDABExtension(c *check.C) {
|
|
||||||
testRequires(c, ExperimentalDaemon)
|
|
||||||
// setup
|
|
||||||
testStackName := "test.dab"
|
|
||||||
testDABFileName := testStackName
|
|
||||||
defer os.RemoveAll(testDABFileName)
|
|
||||||
err := ioutil.WriteFile(testDABFileName, []byte(testDAB), 0444)
|
|
||||||
c.Assert(err, checker.IsNil)
|
|
||||||
d := s.AddDaemon(c, true, true)
|
|
||||||
// deploy
|
|
||||||
stackArgs := []string{"stack", "deploy", testStackName}
|
|
||||||
out, err := d.Cmd(stackArgs...)
|
|
||||||
c.Assert(err, checker.IsNil)
|
|
||||||
c.Assert(out, checker.Contains, "Loading bundle from test.dab\n")
|
|
||||||
c.Assert(out, checker.Contains, "Creating service test_srv1\n")
|
|
||||||
c.Assert(out, checker.Contains, "Creating service test_srv2\n")
|
|
||||||
}
|
|
||||||
|
|
9
integration-cli/fixtures/deploy/default.yaml
Normal file
9
integration-cli/fixtures/deploy/default.yaml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
version: "3"
|
||||||
|
services:
|
||||||
|
web:
|
||||||
|
image: busybox@sha256:e4f93f6ed15a0cdd342f5aae387886fba0ab98af0a102da6276eaf24d6e6ade0
|
||||||
|
command: top
|
||||||
|
db:
|
||||||
|
image: busybox@sha256:e4f93f6ed15a0cdd342f5aae387886fba0ab98af0a102da6276eaf24d6e6ade0
|
||||||
|
command: "tail -f /dev/null"
|
Loading…
Reference in a new issue