Set Composefile WorkingDir to dirname of the composefile.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
f33f257888
commit
cad32e0111
3 changed files with 34 additions and 10 deletions
|
@ -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
|
||||
}
|
||||
|
|
28
cli/command/stack/deploy_composefile_test.go
Normal file
28
cli/command/stack/deploy_composefile_test.go
Normal file
|
@ -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()))
|
||||
}
|
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
"path"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
|
@ -23,10 +22,6 @@ import (
|
|||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
fieldNameRegexp = regexp.MustCompile("[A-Z][a-z0-9]+")
|
||||
)
|
||||
|
||||
// ParseYAML reads the bytes from a file, parses the bytes into a mapping
|
||||
// structure, and returns it.
|
||||
func ParseYAML(source []byte) (map[string]interface{}, error) {
|
||||
|
|
Loading…
Reference in a new issue