Add --bundle,-dab flag for specifying dab file

This commit is contained in:
Janet Kuo 2016-07-22 09:49:43 -07:00
parent 5ba4f38c65
commit b289594c84
2 changed files with 20 additions and 12 deletions

View File

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

View File

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