mirror of https://github.com/docker/compose.git
Allow compose up from stdin with `-f -`. Cf https://github.com/docker/desktop-microsoft/issues/15
This commit is contained in:
parent
8f6cd7c63f
commit
90acf5eddc
|
@ -1,7 +1,6 @@
|
|||
package compose
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -130,12 +129,13 @@ func parseConfigs(configPaths []string) ([]types.ConfigFile, error) {
|
|||
var b []byte
|
||||
var err error
|
||||
if f == "-" {
|
||||
return []types.ConfigFile{}, errors.New("reading compose file from stdin is not supported")
|
||||
b, err = ioutil.ReadAll(os.Stdin)
|
||||
} else {
|
||||
if _, err := os.Stat(f); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b, err = ioutil.ReadFile(f)
|
||||
}
|
||||
if _, err := os.Stat(f); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b, err = ioutil.ReadFile(f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package compose
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
type ComposeTest struct {
|
||||
suite.Suite
|
||||
}
|
||||
|
||||
func (suite *ComposeTest) TestParseComposeFile() {
|
||||
files := []string{"../tests/composefiles/aci-demo/aci_demo_port.yaml"}
|
||||
config, err := parseConfigs(files)
|
||||
Expect(err).To(BeNil())
|
||||
services := config[0].Config["services"].(map[string]interface{})
|
||||
Expect(len(services)).To(Equal(3))
|
||||
}
|
||||
|
||||
func (suite *ComposeTest) TestParseComposeStdin() {
|
||||
files := []string{"-"}
|
||||
f, err := os.Open("../tests/composefiles/aci-demo/aci_demo_port.yaml")
|
||||
Expect(err).To(BeNil())
|
||||
defer func() {
|
||||
err := f.Close()
|
||||
Expect(err).To(BeNil())
|
||||
}()
|
||||
oldStdin := os.Stdin
|
||||
defer func() { os.Stdin = oldStdin }() // Restore original Stdin
|
||||
|
||||
os.Stdin = f
|
||||
config, err := parseConfigs(files)
|
||||
Expect(err).To(BeNil())
|
||||
services := config[0].Config["services"].(map[string]interface{})
|
||||
Expect(len(services)).To(Equal(3))
|
||||
}
|
||||
|
||||
func TestComposeProject(t *testing.T) {
|
||||
RegisterTestingT(t)
|
||||
suite.Run(t, new(ComposeTest))
|
||||
}
|
Loading…
Reference in New Issue