forked from LaconicNetwork/kompose
added support for multiple-compose files
This commit is contained in:
+4
-4
@@ -114,7 +114,7 @@ func ValidateFlags(bundle string, args []string, cmd *cobra.Command, opt *kobjec
|
||||
|
||||
if len(bundle) > 0 {
|
||||
inputFormat = "bundle"
|
||||
opt.InputFile = bundle
|
||||
opt.InputFiles = []string{bundle}
|
||||
}
|
||||
|
||||
if len(bundle) > 0 && isFileSet {
|
||||
@@ -185,7 +185,7 @@ func Convert(opt kobject.ConvertOptions) {
|
||||
komposeObject := kobject.KomposeObject{
|
||||
ServiceConfigs: make(map[string]kobject.ServiceConfig),
|
||||
}
|
||||
komposeObject = l.LoadFile(opt.InputFile)
|
||||
komposeObject = l.LoadFile(opt.InputFiles)
|
||||
|
||||
// Get a transformer that maps komposeObject to provider's primitives
|
||||
t := getTransformer(opt)
|
||||
@@ -211,7 +211,7 @@ func Up(opt kobject.ConvertOptions) {
|
||||
komposeObject := kobject.KomposeObject{
|
||||
ServiceConfigs: make(map[string]kobject.ServiceConfig),
|
||||
}
|
||||
komposeObject = l.LoadFile(opt.InputFile)
|
||||
komposeObject = l.LoadFile(opt.InputFiles)
|
||||
|
||||
// Get the transformer
|
||||
t := getTransformer(opt)
|
||||
@@ -237,7 +237,7 @@ func Down(opt kobject.ConvertOptions) {
|
||||
komposeObject := kobject.KomposeObject{
|
||||
ServiceConfigs: make(map[string]kobject.ServiceConfig),
|
||||
}
|
||||
komposeObject = l.LoadFile(opt.InputFile)
|
||||
komposeObject = l.LoadFile(opt.InputFiles)
|
||||
|
||||
// Get the transformer
|
||||
t := getTransformer(opt)
|
||||
|
||||
@@ -39,7 +39,7 @@ type ConvertOptions struct {
|
||||
GenerateYaml bool
|
||||
EmptyVols bool
|
||||
Replicas int
|
||||
InputFile string
|
||||
InputFiles []string
|
||||
OutFile string
|
||||
Provider string
|
||||
}
|
||||
|
||||
@@ -173,12 +173,12 @@ func loadPorts(service Service) ([]kobject.Ports, string) {
|
||||
}
|
||||
|
||||
// load dab file into KomposeObject
|
||||
func (b *Bundle) LoadFile(file string) kobject.KomposeObject {
|
||||
func (b *Bundle) LoadFile(files []string) kobject.KomposeObject {
|
||||
komposeObject := kobject.KomposeObject{
|
||||
ServiceConfigs: make(map[string]kobject.ServiceConfig),
|
||||
LoadedFrom: "bundle",
|
||||
}
|
||||
|
||||
file := files[0]
|
||||
buf, err := ioutil.ReadFile(file)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Failed to read bundles file: %s ", err)
|
||||
|
||||
@@ -221,16 +221,16 @@ func loadPorts(composePorts []string) ([]kobject.Ports, error) {
|
||||
}
|
||||
|
||||
// load compose file into KomposeObject
|
||||
func (c *Compose) LoadFile(file string) kobject.KomposeObject {
|
||||
func (c *Compose) LoadFile(files []string) kobject.KomposeObject {
|
||||
komposeObject := kobject.KomposeObject{
|
||||
ServiceConfigs: make(map[string]kobject.ServiceConfig),
|
||||
LoadedFrom: "compose",
|
||||
}
|
||||
context := &project.Context{}
|
||||
if file == "" {
|
||||
file = "docker-compose.yml"
|
||||
if len(files) == 0 {
|
||||
files = append(files, "docker-compose.yml")
|
||||
}
|
||||
context.ComposeFiles = []string{file}
|
||||
context.ComposeFiles = files
|
||||
|
||||
if context.ResourceLookup == nil {
|
||||
context.ResourceLookup = &lookup.FileResourceLookup{}
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
)
|
||||
|
||||
type Loader interface {
|
||||
LoadFile(file string) kobject.KomposeObject
|
||||
LoadFile(files []string) kobject.KomposeObject
|
||||
///Name() string
|
||||
}
|
||||
|
||||
|
||||
@@ -46,11 +46,12 @@ import (
|
||||
/**
|
||||
* Generate Helm Chart configuration
|
||||
*/
|
||||
func generateHelm(filename string, outFiles []string) error {
|
||||
func generateHelm(filenames []string, outFiles []string) error {
|
||||
type ChartDetails struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
// Let assume all the docker-compose files are in the same directory
|
||||
filename := filenames[0]
|
||||
extension := filepath.Ext(filename)
|
||||
dirName := filename[0 : len(filename)-len(extension)]
|
||||
details := ChartDetails{dirName}
|
||||
@@ -231,7 +232,7 @@ func PrintList(objects []runtime.Object, opt kobject.ConvertOptions) error {
|
||||
}
|
||||
}
|
||||
if opt.CreateChart {
|
||||
generateHelm(opt.InputFile, files)
|
||||
generateHelm(opt.InputFiles, files)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -112,7 +112,9 @@ func getGitCurrentBranch(composeFileDir string) (string, error) {
|
||||
}
|
||||
|
||||
// getComposeFileDir returns compose file directory
|
||||
func getComposeFileDir(inputFile string) (string, error) {
|
||||
func getComposeFileDir(inputFiles []string) (string, error) {
|
||||
// Lets assume all the docker-compose files are in the same directory
|
||||
inputFile := inputFiles[0]
|
||||
if strings.Index(inputFile, "/") != 0 {
|
||||
workDir, err := os.Getwd()
|
||||
if err != nil {
|
||||
@@ -332,7 +334,7 @@ func (o *OpenShift) Transform(komposeObject kobject.KomposeObject, opt kobject.C
|
||||
// buildconfig needs to be added to objects after imagestream because of this Openshift bug: https://github.com/openshift/origin/issues/4518
|
||||
if service.Build != "" {
|
||||
if !hasBuild {
|
||||
composeFileDir, err = getComposeFileDir(opt.InputFile)
|
||||
composeFileDir, err = getComposeFileDir(opt.InputFiles)
|
||||
if err != nil {
|
||||
logrus.Warningf("Error in detecting compose file's directory.")
|
||||
continue
|
||||
|
||||
@@ -214,17 +214,17 @@ func TestGetComposeFileDir(t *testing.T) {
|
||||
wd, _ := os.Getwd()
|
||||
|
||||
testCases := map[string]struct {
|
||||
inputFile string
|
||||
output string
|
||||
inputFiles []string
|
||||
output string
|
||||
}{
|
||||
"Get compose file dir for relative input file path": {"foo/bar.yaml", filepath.Join(wd, "foo")},
|
||||
"Get compose file dir for abs input file path": {"/abs/path/to/compose.yaml", "/abs/path/to"},
|
||||
"Get compose file dir for relative input file path": {[]string{"foo/bar.yaml"}, filepath.Join(wd, "foo")},
|
||||
"Get compose file dir for abs input file path": {[]string{"/abs/path/to/compose.yaml"}, "/abs/path/to"},
|
||||
}
|
||||
|
||||
for name, test := range testCases {
|
||||
t.Log("Test case: ", name)
|
||||
|
||||
output, err = getComposeFileDir(test.inputFile)
|
||||
output, err = getComposeFileDir(test.inputFiles)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Expected success, got error: %#v", err)
|
||||
|
||||
Reference in New Issue
Block a user