Skip to content

Commit c9d284d

Browse files
committed
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) <[email protected]>
1 parent 9e3c15e commit c9d284d

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

builder/publish.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package builder
55

66
import (
77
"fmt"
8+
"log"
89
"os"
910
"strings"
1011

@@ -111,7 +112,11 @@ func getDockerBuildxCommand(build dockerBuild) (string, []string) {
111112

112113
args = append(args, flagSlice...)
113114

115+
args = append(args, "--tag", build.Image, ".")
116+
117+
log.Println(build.ExtraTags, len(build.ExtraTags))
114118
for _, t := range build.ExtraTags {
119+
log.Println("Do", t)
115120
var tag string
116121
if i := strings.LastIndex(build.Image, ":"); i > -1 {
117122
tag = applyTag(i, build.Image, t)
@@ -121,8 +126,6 @@ func getDockerBuildxCommand(build dockerBuild) (string, []string) {
121126
args = append(args, "--tag", tag)
122127
}
123128

124-
args = append(args, "--tag", build.Image, ".")
125-
126129
command := "docker"
127130

128131
return command, args

commands/publish.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func init() {
4242
publishCmd.Flags().BoolVar(&quietBuild, "quiet", false, "Perform a quiet build, without showing output from Docker")
4343
publishCmd.Flags().BoolVar(&disableStackPull, "disable-stack-pull", false, "Disables the template configuration in the stack.yml")
4444
publishCmd.Flags().StringVar(&platforms, "platforms", "linux/amd64", "A set of platforms to publish")
45-
publishCmd.Flags().StringArrayVar(&extraTags, "extra-tag", []string{""}, "Additional extra image tag")
45+
publishCmd.Flags().StringArrayVar(&extraTags, "extra-tag", []string{}, "Additional extra image tag")
4646

4747
// Set bash-completion.
4848
_ = publishCmd.Flags().SetAnnotation("handler", cobra.BashCompSubdirsInDir, []string{})
@@ -84,7 +84,7 @@ See also: faas-cli build`,
8484
faas-cli publish --build-option dev
8585
faas-cli publish --tag sha
8686
`,
87-
PreRunE: preRunBuild,
87+
PreRunE: preRunPublish,
8888
RunE: runPublish,
8989
}
9090

@@ -104,6 +104,10 @@ func preRunPublish(cmd *cobra.Command, args []string) error {
104104
return fmt.Errorf("the --parallel flag must be great than 0")
105105
}
106106

107+
if len(yamlFile) == 0 {
108+
return fmt.Errorf("--yaml or -f is required")
109+
}
110+
107111
return err
108112
}
109113

0 commit comments

Comments
 (0)