1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

api/server/backend/build: remove Tagger and NewTagger

The Tagger was introduced in 0296797f0f, as part
of a refactor, but was never used outside of the package itself. The commit
also didn't explain why this was changed into a Type with a constructor, as all
the constructor appears to be used for is to sanitize and validate the tags.

This patch removes the `Tagger` struct and its constructor, and instead just
uses a function to do the same.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-09-07 20:36:00 +02:00
parent 105eee7e24
commit ff81dc3544
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 7 additions and 28 deletions

View file

@ -54,7 +54,7 @@ func (b *Backend) Build(ctx context.Context, config backend.BuildConfig) (string
options := config.Options options := config.Options
useBuildKit := options.Version == types.BuilderBuildKit useBuildKit := options.Version == types.BuilderBuildKit
tagger, err := NewTagger(b.imageComponent, config.ProgressWriter.StdoutFormatter, options.Tags) tags, err := sanitizeRepoAndTags(options.Tags)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -93,7 +93,7 @@ func (b *Backend) Build(ctx context.Context, config backend.BuildConfig) (string
fmt.Fprintf(stdout, "Successfully built %s\n", stringid.TruncateID(imageID)) fmt.Fprintf(stdout, "Successfully built %s\n", stringid.TruncateID(imageID))
} }
if imageID != "" { if imageID != "" {
err = tagger.TagImages(image.ID(imageID)) err = tagImages(b.imageComponent, config.ProgressWriter.StdoutFormatter, image.ID(imageID), tags)
} }
return imageID, err return imageID, err
} }

View file

@ -9,34 +9,13 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
) )
// Tagger is responsible for tagging an image created by a builder // tagImages creates image tags for the imageID.
type Tagger struct { func tagImages(ic ImageComponent, stdout io.Writer, imageID image.ID, repoAndTags []reference.Named) error {
imageComponent ImageComponent for _, rt := range repoAndTags {
stdout io.Writer if err := ic.TagImageWithReference(imageID, rt); err != nil {
repoAndTags []reference.Named
}
// NewTagger returns a new Tagger for tagging the images of a build.
// If any of the names are invalid tags an error is returned.
func NewTagger(backend ImageComponent, stdout io.Writer, names []string) (*Tagger, error) {
reposAndTags, err := sanitizeRepoAndTags(names)
if err != nil {
return nil, err
}
return &Tagger{
imageComponent: backend,
stdout: stdout,
repoAndTags: reposAndTags,
}, nil
}
// TagImages creates image tags for the imageID
func (bt *Tagger) TagImages(imageID image.ID) error {
for _, rt := range bt.repoAndTags {
if err := bt.imageComponent.TagImageWithReference(imageID, rt); err != nil {
return err return err
} }
fmt.Fprintf(bt.stdout, "Successfully tagged %s\n", reference.FamiliarString(rt)) _, _ = fmt.Fprintln(stdout, "Successfully tagged", reference.FamiliarString(rt))
} }
return nil return nil
} }