Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
build: fail for invalid tags (#73)
Browse files Browse the repository at this point in the history
Error out when passed an invalid tag to build operations.

Additionally, make sure that "tags" lacking the tag suffix default to `:latest`.

Fixes #70

Signed-off-by: Jacob Blain Christen <jacob@rancher.com>
  • Loading branch information
dweomer committed Sep 1, 2021
1 parent 6bc1724 commit 23c4980
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pkg/client/image/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ func (s *Build) Do(ctx context.Context, k8s *client.Interface, path string) erro
Session: []session.Attachable{authprovider.NewDockerAuthProvider(os.Stderr)},
}
if len(s.Tag) > 0 {
options.Exports = s.defaultExporter()
exports, err := s.defaultExporter()
if err != nil {
return err
}
options.Exports = exports
}
if len(s.Output) > 0 {
exports, err := build.ParseOutput(s.Output)
Expand Down Expand Up @@ -196,7 +200,7 @@ func (s *Build) progress(group *errgroup.Group) chan *buildkit.SolveStatus {
return ch
}

func (s *Build) defaultExporter() []buildkit.ExportEntry {
func (s *Build) defaultExporter() ([]buildkit.ExportEntry, error) {
exp := buildkit.ExportEntry{
Type: buildkit.ExporterImage,
Attrs: map[string]string{},
Expand All @@ -206,13 +210,12 @@ func (s *Build) defaultExporter() []buildkit.ExportEntry {
for i, tag := range tags {
ref, err := reference.ParseNormalizedNamed(tag)
if err != nil {
logrus.Warnf("Failed to normalize tag `%s` => %v", tag, err)
continue
return nil, err
}
tags[i] = ref.String()
tags[i] = reference.TagNameOnly(ref).String()
}
exp.Attrs["name"] = strings.Join(tags, ",")
exp.Attrs["name-canonical"] = "" // true
}
return []buildkit.ExportEntry{exp}
return []buildkit.ExportEntry{exp}, nil
}

0 comments on commit 23c4980

Please sign in to comment.