From b289594c846b8bce50fb74b7686c68b2c7df7189 Mon Sep 17 00:00:00 2001 From: Janet Kuo Date: Fri, 22 Jul 2016 09:49:43 -0700 Subject: [PATCH 1/2] Add --bundle,-dab flag for specifying dab file --- cli/app/app.go | 14 ++++++++++---- cli/command/command.go | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/cli/app/app.go b/cli/app/app.go index 1635e455a..97744d60e 100644 --- a/cli/app/app.go +++ b/cli/app/app.go @@ -53,7 +53,10 @@ import ( "github.com/ghodss/yaml" ) -const letterBytes = "abcdefghijklmnopqrstuvwxyz0123456789" +const ( + letterBytes = "abcdefghijklmnopqrstuvwxyz0123456789" + DefaultComposeFile = "docker-compose.yml" +) var unsupportedKey = map[string]string{ "Build": "", @@ -998,6 +1001,7 @@ func komposeConvert(komposeObject KomposeObject, opt convertOptions) { // Convert tranforms docker compose or dab file to k8s objects func Convert(c *cli.Context) { inputFile := c.String("file") + dabFile := c.String("bundle") outFile := c.String("out") generateYaml := c.BoolT("yaml") toStdout := c.BoolT("stdout") @@ -1006,7 +1010,6 @@ func Convert(c *cli.Context) { createRS := c.BoolT("replicaset") createRC := c.BoolT("replicationcontroller") createChart := c.BoolT("chart") - fromBundles := c.BoolT("from-bundles") replicas := c.Int("replicas") singleOutput := len(outFile) != 0 || toStdout createDeploymentConfig := c.BoolT("deploymentconfig") @@ -1047,6 +1050,9 @@ func Convert(c *cli.Context) { logrus.Fatalf("Error: only one type of Kubernetes controller can be generated when --out or --stdout is specified") } } + if len(dabFile) > 0 && len(inputFile) > 0 && inputFile != DefaultComposeFile { + logrus.Fatalf("Error: compose file and dab file cannot be specified at the same time") + } var f *os.File if !createChart { @@ -1056,8 +1062,8 @@ func Convert(c *cli.Context) { komposeObject := KomposeObject{} - if fromBundles { - komposeObject = loadBundlesFile(inputFile) + if len(dabFile) > 0 { + komposeObject = loadBundlesFile(dabFile) } else { komposeObject = loadComposeFile(inputFile, c) } diff --git a/cli/command/command.go b/cli/command/command.go index bcce6aa1a..de9842b3d 100644 --- a/cli/command/command.go +++ b/cli/command/command.go @@ -17,6 +17,8 @@ limitations under the License. package command import ( + "fmt" + "github.com/skippbox/kompose/cli/app" "github.com/urfave/cli" ) @@ -25,17 +27,22 @@ import ( func ConvertCommand() cli.Command { return cli.Command{ Name: "convert", - Usage: "Convert docker-compose.yml to Kubernetes objects", + Usage: fmt.Sprintf("Convert %s to Kubernetes objects", app.DefaultComposeFile), Action: func(c *cli.Context) { app.Convert(c) }, Flags: []cli.Flag{ cli.StringFlag{ Name: "file,f", - Usage: "Specify an alternate compose file (default: docker-compose.yml)", - Value: "docker-compose.yml", + Usage: fmt.Sprintf("Specify an alternate compose file (default: %s)", app.DefaultComposeFile), + Value: app.DefaultComposeFile, EnvVar: "COMPOSE_FILE", }, + cli.StringFlag{ + Name: "bundle,dab", + Usage: "Specify a Distributed Application Bundle (DAB) file", + EnvVar: "DAB_FILE", + }, cli.StringFlag{ Name: "out,o", Usage: "Specify file name in order to save objects into", @@ -78,11 +85,6 @@ func ConvertCommand() cli.Command { Name: "stdout", Usage: "Print Kubernetes objects to stdout", }, - // FIXME: this flag should be used together with --file/-f in order to specify dab file. - cli.BoolFlag{ - Name: "from-bundles", - Usage: "Getting input from docker DAB file", - }, }, } } From 23488a29e16c964ff1f605989d3abbcdae5a8883 Mon Sep 17 00:00:00 2001 From: Janet Kuo Date: Fri, 22 Jul 2016 12:54:22 -0700 Subject: [PATCH 2/2] Respect dab file name when generate helm charts --- cli/app/app.go | 4 +++- cli/app/k8sutils.go | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cli/app/app.go b/cli/app/app.go index 97744d60e..547e45b2c 100644 --- a/cli/app/app.go +++ b/cli/app/app.go @@ -1061,9 +1061,11 @@ func Convert(c *cli.Context) { } komposeObject := KomposeObject{} + file := inputFile if len(dabFile) > 0 { komposeObject = loadBundlesFile(dabFile) + file = dabFile } else { komposeObject = loadComposeFile(inputFile, c) } @@ -1079,7 +1081,7 @@ func Convert(c *cli.Context) { createChart: createChart, generateYaml: generateYaml, replicas: replicas, - inputFile: inputFile, + inputFile: file, outFile: outFile, f: f, } diff --git a/cli/app/k8sutils.go b/cli/app/k8sutils.go index 40f6079bc..cdb83bb4f 100644 --- a/cli/app/k8sutils.go +++ b/cli/app/k8sutils.go @@ -21,7 +21,7 @@ import ( "fmt" "io/ioutil" "os" - "strings" + "path/filepath" "text/template" "github.com/Sirupsen/logrus" @@ -37,7 +37,8 @@ func generateHelm(filename string, svcnames []string, generateYaml, createD, cre Name string } - dirName := strings.Replace(filename, ".yml", "", 1) + extension := filepath.Ext(filename) + dirName := filename[0 : len(filename)-len(extension)] details := ChartDetails{dirName} manifestDir := dirName + string(os.PathSeparator) + "templates" dir, err := os.Open(dirName)