From c9d284d0c5bd90415baf9130fdce55af8e5a506b Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Thu, 19 Nov 2020 12:01:28 +0000 Subject: [PATCH] Fix bug with tag parsing Due to empty string being given in the array for extra tags we saw an issue whenever no extra tags were given. This has been tested with and without arguments. Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- builder/publish.go | 7 +++++-- commands/publish.go | 8 ++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/builder/publish.go b/builder/publish.go index 0800dd433..07b2018b9 100644 --- a/builder/publish.go +++ b/builder/publish.go @@ -5,6 +5,7 @@ package builder import ( "fmt" + "log" "os" "strings" @@ -111,7 +112,11 @@ func getDockerBuildxCommand(build dockerBuild) (string, []string) { args = append(args, flagSlice...) + args = append(args, "--tag", build.Image, ".") + + log.Println(build.ExtraTags, len(build.ExtraTags)) for _, t := range build.ExtraTags { + log.Println("Do", t) var tag string if i := strings.LastIndex(build.Image, ":"); i > -1 { tag = applyTag(i, build.Image, t) @@ -121,8 +126,6 @@ func getDockerBuildxCommand(build dockerBuild) (string, []string) { args = append(args, "--tag", tag) } - args = append(args, "--tag", build.Image, ".") - command := "docker" return command, args diff --git a/commands/publish.go b/commands/publish.go index 0aff0a0c6..9297d5dfb 100644 --- a/commands/publish.go +++ b/commands/publish.go @@ -42,7 +42,7 @@ func init() { publishCmd.Flags().BoolVar(&quietBuild, "quiet", false, "Perform a quiet build, without showing output from Docker") publishCmd.Flags().BoolVar(&disableStackPull, "disable-stack-pull", false, "Disables the template configuration in the stack.yml") publishCmd.Flags().StringVar(&platforms, "platforms", "linux/amd64", "A set of platforms to publish") - publishCmd.Flags().StringArrayVar(&extraTags, "extra-tag", []string{""}, "Additional extra image tag") + publishCmd.Flags().StringArrayVar(&extraTags, "extra-tag", []string{}, "Additional extra image tag") // Set bash-completion. _ = publishCmd.Flags().SetAnnotation("handler", cobra.BashCompSubdirsInDir, []string{}) @@ -84,7 +84,7 @@ See also: faas-cli build`, faas-cli publish --build-option dev faas-cli publish --tag sha `, - PreRunE: preRunBuild, + PreRunE: preRunPublish, RunE: runPublish, } @@ -104,6 +104,10 @@ func preRunPublish(cmd *cobra.Command, args []string) error { return fmt.Errorf("the --parallel flag must be great than 0") } + if len(yamlFile) == 0 { + return fmt.Errorf("--yaml or -f is required") + } + return err }