Skip to content

Commit

Permalink
Fix bug with tag parsing
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
alexellis committed Nov 19, 2020
1 parent 9e3c15e commit c9d284d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions builder/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package builder

import (
"fmt"
"log"
"os"
"strings"

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions commands/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down Expand Up @@ -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,
}

Expand All @@ -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
}

Expand Down

0 comments on commit c9d284d

Please sign in to comment.