From 6cd1af015b665d93d217e94fdbfcbb89a762ed09 Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Fri, 1 Apr 2022 08:15:39 +0200 Subject: [PATCH] Manage empty image name And avoid removing charts if there are problems before generating the helm chart fix #6 --- cmd/utils.go | 8 ++++---- compose/parser.go | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/cmd/utils.go b/cmd/utils.go index 60e790a..308eeed 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -103,6 +103,10 @@ func Convert(composeFile, appVersion, appName, chartDir string, force bool) { os.Exit(1) } + // Parse the compose file now + p := compose.NewParser(composeFile) + p.Parse(appName) + dirname := filepath.Join(chartDir, appName) if _, err := os.Stat(dirname); err == nil && !force { response := "" @@ -133,10 +137,6 @@ func Convert(composeFile, appVersion, appName, chartDir string, force bool) { os.Exit(1) } - // Parse the compose file now - p := compose.NewParser(composeFile) - p.Parse(appName) - // start generator generator.Generate(p, Version, appName, appVersion, ComposeFile, dirname) diff --git a/compose/parser.go b/compose/parser.go index f8bd0d1..9b4da6c 100644 --- a/compose/parser.go +++ b/compose/parser.go @@ -94,6 +94,22 @@ func (p *Parser) Parse(appname string) { log.Fatal(strings.Join(missing, "\n")) } + // check if all "image" properties are set + missing = []string{} + for name, s := range c.Services { + if s.Image == "" { + missing = append(missing, fmt.Sprintf( + "The service \"%s\" hasn't got "+ + "an image property - please "+ + "append an image property in the docker-compose file", + name, + )) + } + } + if len(missing) > 0 { + log.Fatal(strings.Join(missing, "\n")) + } + // check the build element for name, s := range c.Services { if s.RawBuild == nil {