Skip to content

Commit

Permalink
Merge pull request #61 from janetkuo/dab-flag
Browse files Browse the repository at this point in the history
Add --bundle,-dab flag for specifying dab file
  • Loading branch information
janetkuo authored Jul 25, 2016
2 parents 5ba4f38 + 23488a2 commit 569b47f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
18 changes: 13 additions & 5 deletions cli/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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 {
Expand All @@ -1055,9 +1061,11 @@ func Convert(c *cli.Context) {
}

komposeObject := KomposeObject{}
file := inputFile

if fromBundles {
komposeObject = loadBundlesFile(inputFile)
if len(dabFile) > 0 {
komposeObject = loadBundlesFile(dabFile)
file = dabFile
} else {
komposeObject = loadComposeFile(inputFile, c)
}
Expand All @@ -1073,7 +1081,7 @@ func Convert(c *cli.Context) {
createChart: createChart,
generateYaml: generateYaml,
replicas: replicas,
inputFile: inputFile,
inputFile: file,
outFile: outFile,
f: f,
}
Expand Down
5 changes: 3 additions & 2 deletions cli/app/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"fmt"
"io/ioutil"
"os"
"strings"
"path/filepath"
"text/template"

"github.com/Sirupsen/logrus"
Expand All @@ -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)
Expand Down
18 changes: 10 additions & 8 deletions cli/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package command

import (
"fmt"

"github.com/skippbox/kompose/cli/app"
"github.com/urfave/cli"
)
Expand All @@ -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",
Expand Down Expand Up @@ -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",
},
},
}
}
Expand Down

0 comments on commit 569b47f

Please sign in to comment.