forked from LaconicNetwork/kompose
initial commit, parse dab file into objects
This commit is contained in:
parent
8871baf9be
commit
c49eccf313
@ -27,6 +27,7 @@ import (
|
||||
"github.com/urfave/cli"
|
||||
|
||||
"github.com/docker/libcompose/project"
|
||||
"github.com/docker/docker/api/client/bundlefile"
|
||||
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
@ -553,7 +554,7 @@ func transformer(v interface{}, entity string, generateYaml bool) ([]byte, strin
|
||||
return data, ""
|
||||
}
|
||||
|
||||
// ProjectKuberConvert tranforms docker compose to k8s objects
|
||||
// ProjectKuberConvert tranforms docker compose or dab file to k8s objects
|
||||
func ProjectKuberConvert(p *project.Project, c *cli.Context) {
|
||||
composeFile := c.String("file")
|
||||
outFile := c.String("out")
|
||||
@ -563,6 +564,7 @@ func ProjectKuberConvert(p *project.Project, c *cli.Context) {
|
||||
createDS := c.BoolT("daemonset")
|
||||
createRS := c.BoolT("replicaset")
|
||||
createChart := c.BoolT("chart")
|
||||
fromBundles := c.BoolT("from-bundles")
|
||||
singleOutput := len(outFile) != 0 || toStdout
|
||||
|
||||
// Validate the flags
|
||||
@ -588,6 +590,29 @@ func ProjectKuberConvert(p *project.Project, c *cli.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
var f *os.File
|
||||
if !createChart {
|
||||
f = createOutFile(outFile)
|
||||
defer f.Close()
|
||||
}
|
||||
|
||||
if fromBundles {
|
||||
p = project.NewProject(&project.Context{
|
||||
ProjectName: "kube",
|
||||
})
|
||||
reader := strings.NewReader(composeFile)
|
||||
bundle, err := bundlefile.LoadFile(reader)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Error: failed to load bundles file", err)
|
||||
}
|
||||
for name, service := range bundle.Services {
|
||||
var serviceConfig *project.ServiceConfig
|
||||
serviceConfig.Image = service.Image
|
||||
// TODO: mapping other fields
|
||||
serviceConfig.WorkingDir = *service.WorkingDir
|
||||
p.Configs[name] = serviceConfig
|
||||
}
|
||||
} else {
|
||||
p = project.NewProject(&project.Context{
|
||||
ProjectName: "kube",
|
||||
ComposeFile: composeFile,
|
||||
@ -596,11 +621,6 @@ func ProjectKuberConvert(p *project.Project, c *cli.Context) {
|
||||
if err := p.Parse(); err != nil {
|
||||
logrus.Fatalf("Failed to parse the compose project from %s: %v", composeFile, err)
|
||||
}
|
||||
|
||||
var f *os.File
|
||||
if !createChart {
|
||||
f = createOutFile(outFile)
|
||||
defer f.Close()
|
||||
}
|
||||
|
||||
var mServices map[string][]byte = make(map[string][]byte)
|
||||
|
||||
@ -65,6 +65,11 @@ func ConvertCommand(factory app.ProjectFactory) 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",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user