mirror of https://github.com/docker/cli.git
Set Composefile WorkingDir to dirname of the composefile.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
9c02b38bec
commit
a1b7969bce
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -20,7 +21,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func deployCompose(ctx context.Context, dockerCli *command.DockerCli, opts deployOptions) error {
|
func deployCompose(ctx context.Context, dockerCli *command.DockerCli, opts deployOptions) error {
|
||||||
configDetails, err := getConfigDetails(opts)
|
configDetails, err := getConfigDetails(opts.composefile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -108,16 +109,16 @@ func propertyWarnings(properties map[string]string) string {
|
||||||
return strings.Join(msgs, "\n\n")
|
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 details composetypes.ConfigDetails
|
||||||
var err error
|
|
||||||
|
|
||||||
details.WorkingDir, err = os.Getwd()
|
absPath, err := filepath.Abs(composefile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return details, err
|
return details, err
|
||||||
}
|
}
|
||||||
|
details.WorkingDir = filepath.Dir(absPath)
|
||||||
|
|
||||||
configFile, err := getConfigFile(opts.composefile)
|
configFile, err := getConfigFile(composefile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return details, err
|
return details, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()))
|
||||||
|
}
|
Loading…
Reference in New Issue