2021-11-30 12:04:28 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-02-14 17:00:32 +01:00
|
|
|
"katenary/cmd"
|
2022-02-16 10:56:21 +01:00
|
|
|
"katenary/generator/writers"
|
2021-12-01 08:31:51 +01:00
|
|
|
"katenary/helm"
|
2022-02-16 10:56:21 +01:00
|
|
|
"strconv"
|
2022-02-14 17:00:32 +01:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
2021-11-30 12:04:28 +01:00
|
|
|
)
|
|
|
|
|
2022-02-14 17:15:11 +01:00
|
|
|
var Version = "master" // changed at compile time
|
|
|
|
|
2022-02-14 17:00:32 +01:00
|
|
|
var longHelp = `Katenary aims to be a tool to convert docker-compose files to Helm Charts.
|
|
|
|
It will create deployments, services, volumes, secrets, and ingress resources.
|
|
|
|
But it will also create initContainers based on depend_on, healthcheck, and other features.
|
|
|
|
It's not magical, sometimes you'll need to fix the generated charts.
|
|
|
|
The general way to use it is to call one of these commands:
|
|
|
|
|
|
|
|
katenary convert
|
|
|
|
katenary convert -f docker-compose.yml
|
|
|
|
katenary convert -f docker-compose.yml -o ./charts
|
|
|
|
|
|
|
|
In case of, check the help of each command using:
|
|
|
|
katenary <command> --help
|
|
|
|
or
|
|
|
|
"katenary help <command>"
|
|
|
|
`
|
2021-12-17 10:59:57 +01:00
|
|
|
|
2021-11-30 12:04:28 +01:00
|
|
|
func main() {
|
2022-02-14 17:15:11 +01:00
|
|
|
|
|
|
|
// set the version to "cmd" package - yes... it's ugly
|
|
|
|
cmd.Version = Version
|
|
|
|
|
2022-02-14 17:00:32 +01:00
|
|
|
// The base command
|
|
|
|
rootCmd := &cobra.Command{
|
|
|
|
Use: "katenary",
|
|
|
|
Long: longHelp,
|
|
|
|
Short: "Katenary is a tool to convert docker-compose files to Helm Charts",
|
2022-02-14 14:37:09 +01:00
|
|
|
}
|
|
|
|
|
2022-02-14 17:00:32 +01:00
|
|
|
// to display the version
|
|
|
|
versionCmd := &cobra.Command{
|
|
|
|
Use: "version",
|
|
|
|
Short: "Display version",
|
|
|
|
Run: func(c *cobra.Command, args []string) { c.Println(Version) },
|
2021-12-01 08:31:51 +01:00
|
|
|
}
|
|
|
|
|
2022-02-14 17:00:32 +01:00
|
|
|
// convert command, need some flags
|
|
|
|
convertCmd := &cobra.Command{
|
|
|
|
Use: "convert",
|
|
|
|
Short: "Convert docker-compose to helm chart",
|
|
|
|
Long: "Convert docker-compose to helm chart. The resulting helm chart will be in the current directory/" +
|
|
|
|
cmd.ChartsDir + "/" + cmd.AppName +
|
2022-02-16 10:56:21 +01:00
|
|
|
".\nThe appversion will be generated that way:\n" +
|
|
|
|
"- if it's in a git project, it takes git version or tag\n" +
|
2022-02-14 17:00:32 +01:00
|
|
|
"- if it's not defined, so the version will be get from the --apVersion flag \n" +
|
|
|
|
"- if it's not defined, so the 0.0.1 version is used",
|
|
|
|
Run: func(c *cobra.Command, args []string) {
|
|
|
|
force := c.Flag("force").Changed
|
2022-02-16 10:56:21 +01:00
|
|
|
// TODO: is there a way to get typed values from cobra?
|
2022-02-14 17:00:32 +01:00
|
|
|
appversion := c.Flag("app-version").Value.String()
|
|
|
|
composeFile := c.Flag("compose-file").Value.String()
|
|
|
|
appName := c.Flag("app-name").Value.String()
|
|
|
|
chartDir := c.Flag("output-dir").Value.String()
|
2022-02-16 10:56:21 +01:00
|
|
|
indentation, err := strconv.Atoi(c.Flag("indent-size").Value.String())
|
|
|
|
if err != nil {
|
|
|
|
writers.IndentSize = indentation
|
|
|
|
}
|
2022-02-14 17:00:32 +01:00
|
|
|
cmd.Convert(composeFile, appversion, appName, chartDir, force)
|
|
|
|
},
|
2022-02-02 10:30:32 +01:00
|
|
|
}
|
2022-02-14 17:00:32 +01:00
|
|
|
convertCmd.Flags().BoolP(
|
|
|
|
"force", "f", false, "Force overwrite of existing files")
|
|
|
|
convertCmd.Flags().StringP(
|
|
|
|
"app-version", "a", cmd.AppVersion, "App version")
|
|
|
|
convertCmd.Flags().StringP(
|
|
|
|
"compose-file", "c", cmd.ComposeFile, "Docker compose file")
|
|
|
|
convertCmd.Flags().StringP(
|
|
|
|
"app-name", "n", cmd.AppName, "Application name")
|
|
|
|
convertCmd.Flags().StringP(
|
|
|
|
"output-dir", "o", cmd.ChartsDir, "Chart directory")
|
2022-02-16 10:56:21 +01:00
|
|
|
convertCmd.Flags().IntP(
|
|
|
|
"indent-size", "i", 2, "Set the indent size of the YAML files")
|
2022-02-14 17:00:32 +01:00
|
|
|
|
|
|
|
// show possible labels to set in docker-compose file
|
|
|
|
showLabelsCmd := &cobra.Command{
|
|
|
|
Use: "show-labels",
|
|
|
|
Short: "Show labels of a resource",
|
|
|
|
Run: func(c *cobra.Command, args []string) {
|
|
|
|
c.Println(helm.GetLabelsDocumentation())
|
|
|
|
},
|
2021-12-17 10:59:57 +01:00
|
|
|
}
|
2021-12-01 10:36:43 +01:00
|
|
|
|
2022-02-14 17:00:32 +01:00
|
|
|
rootCmd.AddCommand(versionCmd)
|
|
|
|
rootCmd.AddCommand(convertCmd)
|
|
|
|
rootCmd.AddCommand(showLabelsCmd)
|
2021-12-17 10:59:57 +01:00
|
|
|
|
2022-02-14 17:00:32 +01:00
|
|
|
rootCmd.Execute()
|
2021-11-30 12:04:28 +01:00
|
|
|
|
|
|
|
}
|