forked from LaconicNetwork/kompose
initially support compose v2 format, and close #8 as well
This commit is contained in:
parent
a9184491b7
commit
a8add081ab
@ -27,6 +27,8 @@ import (
|
|||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
|
||||||
"github.com/docker/docker/api/client/bundlefile"
|
"github.com/docker/docker/api/client/bundlefile"
|
||||||
|
"github.com/docker/libcompose/docker"
|
||||||
|
"github.com/docker/libcompose/project"
|
||||||
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -41,6 +43,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fatih/structs"
|
"github.com/fatih/structs"
|
||||||
"github.com/ghodss/yaml"
|
"github.com/ghodss/yaml"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const letterBytes = "abcdefghijklmnopqrstuvwxyz0123456789"
|
const letterBytes = "abcdefghijklmnopqrstuvwxyz0123456789"
|
||||||
@ -619,6 +622,37 @@ func loadBundlesFile(file string) KomposeObject {
|
|||||||
return komposeObject
|
return komposeObject
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load compose file version 1 into KomposeObject
|
||||||
|
func loadComposeFile(file string, c *cli.Context) KomposeObject {
|
||||||
|
komposeObject := KomposeObject{
|
||||||
|
ServiceConfigs: make(map[string]ServiceConfig),
|
||||||
|
}
|
||||||
|
context := &docker.Context{}
|
||||||
|
if file == "" {
|
||||||
|
file = "docker-compose.yml"
|
||||||
|
}
|
||||||
|
context.ComposeFiles = []string{file}
|
||||||
|
|
||||||
|
// load compose file into composeObject
|
||||||
|
composeObject := project.NewProject(&context.Context, nil, nil)
|
||||||
|
err := composeObject.Parse()
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatalf("Failed to load compose file", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// transform composeObject into komposeObject
|
||||||
|
composeServiceNames := composeObject.ServiceConfigs.Keys()
|
||||||
|
for _, name := range composeServiceNames {
|
||||||
|
if composeServiceConfig, ok := composeObject.ServiceConfigs.Get(name); ok {
|
||||||
|
// TODO: mapping composeObject config to komposeObject config
|
||||||
|
serviceConfig := ServiceConfig{}
|
||||||
|
serviceConfig.Image = composeServiceConfig.Image
|
||||||
|
komposeObject.ServiceConfigs[name] = serviceConfig
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return komposeObject
|
||||||
|
}
|
||||||
|
|
||||||
// Convert komposeObject to K8S controllers
|
// Convert komposeObject to K8S controllers
|
||||||
func komposeConvert(komposeObject KomposeObject, toStdout, createD, createRS, createDS, createChart, generateYaml bool, replicas int, inputFile string, outFile string, f *os.File) {
|
func komposeConvert(komposeObject KomposeObject, toStdout, createD, createRS, createDS, createChart, generateYaml bool, replicas int, inputFile string, outFile string, f *os.File) {
|
||||||
mServices := make(map[string][]byte)
|
mServices := make(map[string][]byte)
|
||||||
@ -839,6 +873,8 @@ func Convert(c *cli.Context) {
|
|||||||
// Parse DAB file into komposeObject
|
// Parse DAB file into komposeObject
|
||||||
if fromBundles {
|
if fromBundles {
|
||||||
komposeObject = loadBundlesFile(inputFile)
|
komposeObject = loadBundlesFile(inputFile)
|
||||||
|
} else {
|
||||||
|
komposeObject = loadComposeFile(inputFile, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert komposeObject to K8S controllers
|
// Convert komposeObject to K8S controllers
|
||||||
|
|||||||
@ -75,6 +75,10 @@ func ConvertCommand() cli.Command {
|
|||||||
Name: "from-bundles",
|
Name: "from-bundles",
|
||||||
Usage: "Getting input from docker DAB file",
|
Usage: "Getting input from docker DAB file",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "from-compose-v2",
|
||||||
|
Usage: "Getting input from docker compose file version 2",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
29
examples/docker-voting.yml
Normal file
29
examples/docker-voting.yml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
version: "2"
|
||||||
|
|
||||||
|
services:
|
||||||
|
vote:
|
||||||
|
build: ./vote
|
||||||
|
command: python app.py
|
||||||
|
volumes:
|
||||||
|
- ./vote:/app
|
||||||
|
ports:
|
||||||
|
- "5000:80"
|
||||||
|
|
||||||
|
redis:
|
||||||
|
image: redis:alpine
|
||||||
|
ports: ["6379"]
|
||||||
|
|
||||||
|
worker:
|
||||||
|
build: ./worker
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres:9.4
|
||||||
|
|
||||||
|
result:
|
||||||
|
build: ./result
|
||||||
|
command: nodemon --debug server.js
|
||||||
|
volumes:
|
||||||
|
- ./result:/app
|
||||||
|
ports:
|
||||||
|
- "5001:80"
|
||||||
|
- "5858:5858"
|
||||||
Loading…
Reference in New Issue
Block a user