Merge pull request #32564 from dnephin/compose-file-rel-dir

Set Composefile WorkingDir to dirname of the composefile.
This commit is contained in:
Tõnis Tiigi 2017-04-26 17:30:33 -07:00 committed by GitHub
commit 22d9eadee2
3 changed files with 34 additions and 10 deletions

View file

@ -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
}

View 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()))
}

View file

@ -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) {