diff --git a/cli/command/stack/deploy_composefile.go b/cli/command/stack/deploy_composefile.go index f241310bf2..e3f59de14c 100644 --- a/cli/command/stack/deploy_composefile.go +++ b/cli/command/stack/deploy_composefile.go @@ -4,6 +4,7 @@ import ( "fmt" "io/ioutil" "os" + "path/filepath" "sort" "strings" @@ -20,7 +21,7 @@ import ( ) func deployCompose(ctx context.Context, dockerCli *command.DockerCli, opts deployOptions) error { - configDetails, err := getConfigDetails(opts) + configDetails, err := getConfigDetails(opts.composefile) if err != nil { return err } @@ -108,16 +109,16 @@ func propertyWarnings(properties map[string]string) string { return strings.Join(msgs, "\n\n") } -func getConfigDetails(opts deployOptions) (composetypes.ConfigDetails, error) { +func getConfigDetails(composefile string) (composetypes.ConfigDetails, error) { var details composetypes.ConfigDetails - var err error - details.WorkingDir, err = os.Getwd() + absPath, err := filepath.Abs(composefile) if err != nil { return details, err } + details.WorkingDir = filepath.Dir(absPath) - configFile, err := getConfigFile(opts.composefile) + configFile, err := getConfigFile(composefile) if err != nil { return details, err } diff --git a/cli/command/stack/deploy_composefile_test.go b/cli/command/stack/deploy_composefile_test.go new file mode 100644 index 0000000000..d5ef5463ff --- /dev/null +++ b/cli/command/stack/deploy_composefile_test.go @@ -0,0 +1,28 @@ +package stack + +import ( + "os" + "path/filepath" + "testing" + + "github.com/docker/docker/pkg/testutil/tempfile" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestGetConfigDetails(t *testing.T) { + content := ` +version: "3.0" +services: + foo: + image: alpine:3.5 +` + file := tempfile.NewTempFile(t, "test-get-config-details", content) + defer file.Remove() + + details, err := getConfigDetails(file.Name()) + require.NoError(t, err) + assert.Equal(t, filepath.Dir(file.Name()), details.WorkingDir) + assert.Len(t, details.ConfigFiles, 1) + assert.Len(t, details.Environment, len(os.Environ())) +}