Files
katenary/main.go

63 lines
1.7 KiB
Go
Raw Normal View History

2021-11-30 12:04:28 +01:00
package main
import (
"flag"
2021-12-01 08:31:51 +01:00
"fmt"
"katenary/compose"
"katenary/generator"
"katenary/helm"
2021-11-30 12:04:28 +01:00
"os"
"path/filepath"
2021-11-30 12:09:07 +01:00
"strings"
2021-11-30 12:04:28 +01:00
)
var ComposeFile = "docker-compose.yaml"
var AppName = "MyApp"
2021-12-01 09:27:12 +01:00
var AppVersion = "0.0.1"
var Version = "master" // set at build time to the git version/tag
2021-12-01 10:36:43 +01:00
var ChartsDir = "chart"
2021-11-30 12:04:28 +01:00
func main() {
2021-12-01 10:36:43 +01:00
flag.StringVar(&ChartsDir, "chart-dir", ChartsDir, "set the chart directory")
2021-11-30 12:04:28 +01:00
flag.StringVar(&ComposeFile, "compose", ComposeFile, "set the compose file to parse")
flag.StringVar(&AppName, "appname", helm.GetProjectName(), "set the helm chart app name")
2021-12-01 10:36:43 +01:00
flag.StringVar(&AppVersion, "appversion", AppVersion, "set the chart appVersion")
2021-12-17 10:35:21 +01:00
version := flag.Bool("version", false, "show version and exit")
2021-12-01 10:36:43 +01:00
force := flag.Bool("force", false, "force the removal of the chart-dir")
2021-11-30 12:04:28 +01:00
flag.Parse()
// Only display the version
2021-12-01 08:31:51 +01:00
if *version {
2021-12-01 09:27:12 +01:00
fmt.Println(Version)
2021-12-01 08:31:51 +01:00
os.Exit(0)
}
dirname := filepath.Join(ChartsDir, AppName)
2021-12-01 10:36:43 +01:00
if _, err := os.Stat(dirname); err == nil && !*force {
response := ""
for response != "y" && response != "n" {
response = "n"
fmt.Printf(""+
"The %s directory already exists, it will be \x1b[31;1mremoved\x1b[0m!\n"+
"Do you really want to continue? [y/N]: ", dirname)
2021-12-01 10:36:43 +01:00
fmt.Scanf("%s", &response)
response = strings.ToLower(response)
}
if response == "n" {
2021-12-01 10:47:20 +01:00
fmt.Println("Cancelled")
2021-12-01 10:36:43 +01:00
os.Exit(0)
}
}
// cleanup and create the chart directory (until "templates")
2021-12-01 10:36:43 +01:00
os.RemoveAll(dirname)
templatesDir := filepath.Join(dirname, "templates")
os.MkdirAll(templatesDir, 0755)
// Parse the compose file now
2021-11-30 12:04:28 +01:00
p := compose.NewParser(ComposeFile)
p.Parse(AppName)
generator.Generate(p, Version, AppName, AppVersion, ComposeFile, dirname)
2021-11-30 12:04:28 +01:00
}