From 1e9d04c458e90f38c970c7937830504d2e919066 Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Wed, 12 Oct 2016 10:24:19 -0700 Subject: [PATCH] Allow `docker deploy` command accept filename with/without extension This fix tries to address the issue raised in 25855 where the command `docker deploy` can only accept a STACK without extension of `.dab`. In other words, `docker deploy hellojavaee.dab` gives an error: ``` Bundle hellojavaee.dab.dab not found. Specify the path with --file ``` This fix updates the way namespace STACK is taken so that in case `STACK.dab` is provided with `docker deploy`: ``` $ docker deploy STACK.dab ``` The `STACK` is used as namespace (instead of `STACK.dab`). NOTE: This fix will only allows `.dab` extension in namespace, because it is not possible to have a namespace with `.` in the middle. In other words, a namespace `hello.java.ee` will not work anyway (whether the file `hello.java.ee` exists or not). An additional integration test has been added to cover the changes. This fix fixes 25855. Signed-off-by: Yong Tang --- cli/command/stack/deploy.go | 3 ++- integration-cli/docker_cli_stack_test.go | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cli/command/stack/deploy.go b/cli/command/stack/deploy.go index 6daf9500f0..bf31dd7753 100644 --- a/cli/command/stack/deploy.go +++ b/cli/command/stack/deploy.go @@ -4,6 +4,7 @@ package stack import ( "fmt" + "strings" "github.com/spf13/cobra" "golang.org/x/net/context" @@ -34,7 +35,7 @@ func newDeployCommand(dockerCli *command.DockerCli) *cobra.Command { Short: "Create and update a stack from a Distributed Application Bundle (DAB)", Args: cli.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - opts.namespace = args[0] + opts.namespace = strings.TrimSuffix(args[0], ".dab") return runDeploy(dockerCli, opts) }, } diff --git a/integration-cli/docker_cli_stack_test.go b/integration-cli/docker_cli_stack_test.go index fd65f39a43..04a52761a4 100644 --- a/integration-cli/docker_cli_stack_test.go +++ b/integration-cli/docker_cli_stack_test.go @@ -90,3 +90,20 @@ func (s *DockerSwarmSuite) TestStackWithDAB(c *check.C) { c.Assert(err, checker.IsNil) c.Assert(out, check.Equals, "NAME SERVICES\n") } + +func (s *DockerSwarmSuite) TestStackWithDABExtension(c *check.C) { + // 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") +}