Feat cronjob #23
@@ -50,6 +50,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// convert command, need some flags
|
// convert command, need some flags
|
||||||
|
var composeFiles *[]string
|
||||||
convertCmd := &cobra.Command{
|
convertCmd := &cobra.Command{
|
||||||
Use: "convert",
|
Use: "convert",
|
||||||
Short: "Convert docker-compose to helm chart",
|
Short: "Convert docker-compose to helm chart",
|
||||||
@@ -61,9 +62,7 @@ func main() {
|
|||||||
"- if it's not defined, so the 0.0.1 version is used",
|
"- if it's not defined, so the 0.0.1 version is used",
|
||||||
Run: func(c *cobra.Command, args []string) {
|
Run: func(c *cobra.Command, args []string) {
|
||||||
force := c.Flag("force").Changed
|
force := c.Flag("force").Changed
|
||||||
// TODO: is there a way to get typed values from cobra?
|
|
||||||
appversion := c.Flag("app-version").Value.String()
|
appversion := c.Flag("app-version").Value.String()
|
||||||
composeFile := c.Flag("compose-file").Value.String()
|
|
||||||
appName := c.Flag("app-name").Value.String()
|
appName := c.Flag("app-name").Value.String()
|
||||||
chartVersion := c.Flag("chart-version").Value.String()
|
chartVersion := c.Flag("chart-version").Value.String()
|
||||||
chartDir := c.Flag("output-dir").Value.String()
|
chartDir := c.Flag("output-dir").Value.String()
|
||||||
@@ -71,17 +70,17 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
writers.IndentSize = indentation
|
writers.IndentSize = indentation
|
||||||
}
|
}
|
||||||
Convert(composeFile, appversion, appName, chartDir, chartVersion, force)
|
Convert(*composeFiles, appversion, appName, chartDir, chartVersion, force)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
composeFiles = convertCmd.Flags().StringArrayP(
|
||||||
|
"compose-file", "c", []string{ComposeFile}, "compose file to convert, can be use several times to override previous file. Order is important!")
|
||||||
convertCmd.Flags().BoolP(
|
convertCmd.Flags().BoolP(
|
||||||
"force", "f", false, "force overwrite of existing output files")
|
"force", "f", false, "force overwrite of existing output files")
|
||||||
convertCmd.Flags().StringP(
|
convertCmd.Flags().StringP(
|
||||||
"app-version", "a", AppVersion, "app version")
|
"app-version", "a", AppVersion, "app version")
|
||||||
convertCmd.Flags().StringP(
|
convertCmd.Flags().StringP(
|
||||||
"chart-version", "v", ChartVersion, "chart version")
|
"chart-version", "v", ChartVersion, "chart version")
|
||||||
convertCmd.Flags().StringP(
|
|
||||||
"compose-file", "c", ComposeFile, "docker compose file")
|
|
||||||
convertCmd.Flags().StringP(
|
convertCmd.Flags().StringP(
|
||||||
"app-name", "n", AppName, "application name")
|
"app-name", "n", AppName, "application name")
|
||||||
convertCmd.Flags().StringP(
|
convertCmd.Flags().StringP(
|
||||||
|
@@ -93,19 +93,24 @@ func detectGitVersion() (string, error) {
|
|||||||
return defaulVersion, errors.New("git log failed")
|
return defaulVersion, errors.New("git log failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
func Convert(composeFile, appVersion, appName, chartDir, chartVersion string, force bool) {
|
func Convert(composeFile []string, appVersion, appName, chartDir, chartVersion string, force bool) {
|
||||||
if len(composeFile) == 0 {
|
if len(composeFile) == 0 {
|
||||||
fmt.Println("No compose file given")
|
fmt.Println("No compose file given")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err := os.Stat(composeFile)
|
|
||||||
if err != nil {
|
composeFiles := composeFile
|
||||||
fmt.Println("No compose file found")
|
ComposeFile = composeFiles[0]
|
||||||
os.Exit(1)
|
|
||||||
|
for _, cf := range composeFiles {
|
||||||
|
if _, err := os.Stat(cf); err != nil {
|
||||||
|
fmt.Printf("Compose file %s not found\n", cf)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the compose file now
|
// Parse the compose file now
|
||||||
p := compose.NewParser(composeFile)
|
p := compose.NewParser(composeFiles)
|
||||||
p.Parse(appName)
|
p.Parse(appName)
|
||||||
|
|
||||||
dirname := filepath.Join(chartDir, appName)
|
dirname := filepath.Join(chartDir, appName)
|
||||||
|
@@ -26,32 +26,37 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// NewParser create a Parser and parse the file given in filename. If filename is empty, we try to parse the content[0] argument that should be a valid YAML content.
|
// NewParser create a Parser and parse the file given in filename. If filename is empty, we try to parse the content[0] argument that should be a valid YAML content.
|
||||||
func NewParser(filename string, content ...string) *Parser {
|
func NewParser(filename []string, content ...string) *Parser {
|
||||||
|
|
||||||
p := &Parser{}
|
p := &Parser{}
|
||||||
|
|
||||||
if len(content) > 0 { // mainly for the tests...
|
if len(content) > 0 { // mainly for the tests...
|
||||||
dir := filepath.Dir(filename)
|
dir := filepath.Dir(filename[0])
|
||||||
err := os.MkdirAll(dir, 0755)
|
err := os.MkdirAll(dir, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
p.temporary = &dir
|
p.temporary = &dir
|
||||||
ioutil.WriteFile(filename, []byte(content[0]), 0644)
|
ioutil.WriteFile(filename[0], []byte(content[0]), 0644)
|
||||||
cli.DefaultFileNames = []string{filename}
|
cli.DefaultFileNames = filename
|
||||||
}
|
}
|
||||||
// if filename is not in cli Default files, add it
|
// if filename is not in cli Default files, add it
|
||||||
if len(filename) > 0 {
|
if len(filename) > 0 {
|
||||||
found := false
|
found := false
|
||||||
for _, f := range cli.DefaultFileNames {
|
for _, defaultFileName := range cli.DefaultFileNames {
|
||||||
if f == filename {
|
for _, givenFileName := range filename {
|
||||||
found = true
|
if defaultFileName == givenFileName {
|
||||||
break
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// add the file at first position
|
// add the file at first position
|
||||||
if !found {
|
if !found {
|
||||||
cli.DefaultFileNames = append([]string{filename}, cli.DefaultFileNames...)
|
cli.DefaultFileNames = append([]string{filename[0]}, cli.DefaultFileNames...)
|
||||||
|
}
|
||||||
|
if len(filename) > 1 {
|
||||||
|
cli.DefaultOverrideFileNames = append(filename[1:], cli.DefaultOverrideFileNames...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -127,7 +127,7 @@ func setUp(t *testing.T) (string, *compose.Parser) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
composefile := filepath.Join(tmpwork, "docker-compose.yaml")
|
composefile := filepath.Join(tmpwork, "docker-compose.yaml")
|
||||||
p := compose.NewParser(composefile, DOCKER_COMPOSE_YML)
|
p := compose.NewParser([]string{composefile}, DOCKER_COMPOSE_YML)
|
||||||
|
|
||||||
// create envfile for "useenvfile" service
|
// create envfile for "useenvfile" service
|
||||||
err = os.Mkdir(filepath.Join(tmpwork, "config"), 0777)
|
err = os.Mkdir(filepath.Join(tmpwork, "config"), 0777)
|
||||||
|
Reference in New Issue
Block a user