daemon: Pass ctx to image tagging operations
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com> Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
parent
b5568723ce
commit
7b6f71dced
9 changed files with 18 additions and 17 deletions
|
@ -21,7 +21,7 @@ import (
|
|||
// ImageComponent provides an interface for working with images
|
||||
type ImageComponent interface {
|
||||
SquashImage(from string, to string) (string, error)
|
||||
TagImageWithReference(image.ID, reference.Named) error
|
||||
TagImageWithReference(context.Context, image.ID, reference.Named) error
|
||||
}
|
||||
|
||||
// Builder defines interface for running a build
|
||||
|
@ -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))
|
||||
}
|
||||
if imageID != "" {
|
||||
err = tagImages(b.imageComponent, config.ProgressWriter.StdoutFormatter, image.ID(imageID), tags)
|
||||
err = tagImages(ctx, b.imageComponent, config.ProgressWriter.StdoutFormatter, image.ID(imageID), tags)
|
||||
}
|
||||
return imageID, err
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package build // import "github.com/docker/docker/api/server/backend/build"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
|
@ -10,9 +11,9 @@ import (
|
|||
)
|
||||
|
||||
// tagImages creates image tags for the imageID.
|
||||
func tagImages(ic ImageComponent, stdout io.Writer, imageID image.ID, repoAndTags []reference.Named) error {
|
||||
func tagImages(ctx context.Context, ic ImageComponent, stdout io.Writer, imageID image.ID, repoAndTags []reference.Named) error {
|
||||
for _, rt := range repoAndTags {
|
||||
if err := ic.TagImageWithReference(imageID, rt); err != nil {
|
||||
if err := ic.TagImageWithReference(ctx, imageID, rt); err != nil {
|
||||
return err
|
||||
}
|
||||
_, _ = fmt.Fprintln(stdout, "Successfully tagged", reference.FamiliarString(rt))
|
||||
|
|
|
@ -26,7 +26,7 @@ type imageBackend interface {
|
|||
ImageHistory(ctx context.Context, imageName string) ([]*image.HistoryResponseItem, error)
|
||||
Images(ctx context.Context, opts types.ImageListOptions) ([]*types.ImageSummary, error)
|
||||
GetImage(ctx context.Context, refOrID string, options image.GetImageOpts) (*dockerimage.Image, error)
|
||||
TagImage(imageName, repository, tag string) (string, error)
|
||||
TagImage(ctx context.Context, imageName, repository, tag string) (string, error)
|
||||
ImagesPrune(ctx context.Context, pruneFilters filters.Args) (*types.ImagesPruneReport, error)
|
||||
}
|
||||
|
||||
|
|
|
@ -369,7 +369,7 @@ func (ir *imageRouter) postImagesTag(ctx context.Context, w http.ResponseWriter,
|
|||
if err := httputils.ParseForm(r); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := ir.backend.TagImage(vars["name"], r.Form.Get("repo"), r.Form.Get("tag")); err != nil {
|
||||
if _, err := ir.backend.TagImage(ctx, vars["name"], r.Form.Get("repo"), r.Form.Get("tag")); err != nil {
|
||||
return err
|
||||
}
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
|
|
|
@ -171,7 +171,7 @@ func (daemon *Daemon) CreateImageFromContainer(ctx context.Context, name string,
|
|||
|
||||
var imageRef string
|
||||
if c.Repo != "" {
|
||||
imageRef, err = daemon.imageService.TagImage(string(id), c.Repo, c.Tag)
|
||||
imageRef, err = daemon.imageService.TagImage(ctx, string(id), c.Repo, c.Tag)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
package containerd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"context"
|
||||
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/image"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// TagImage creates the tag specified by newTag, pointing to the image named
|
||||
// imageName (alternatively, imageName can also be an image ID).
|
||||
func (i *ImageService) TagImage(imageName, repository, tag string) (string, error) {
|
||||
func (i *ImageService) TagImage(ctx context.Context, imageName, repository, tag string) (string, error) {
|
||||
return "", errdefs.NotImplemented(errors.New("not implemented"))
|
||||
}
|
||||
|
||||
// TagImageWithReference adds the given reference to the image ID provided.
|
||||
func (i *ImageService) TagImageWithReference(imageID image.ID, newTag reference.Named) error {
|
||||
func (i *ImageService) TagImageWithReference(ctx context.Context, imageID image.ID, newTag reference.Named) error {
|
||||
return errdefs.NotImplemented(errors.New("not implemented"))
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ type ImageService interface {
|
|||
CountImages() int
|
||||
ImagesPrune(ctx context.Context, pruneFilters filters.Args) (*types.ImagesPruneReport, error)
|
||||
ImportImage(ctx context.Context, ref reference.Named, platform *v1.Platform, msg string, layerReader io.Reader, changes []string) (image.ID, error)
|
||||
TagImage(imageName, repository, tag string) (string, error)
|
||||
TagImageWithReference(imageID image.ID, newTag reference.Named) error
|
||||
TagImage(ctx context.Context, imageName, repository, tag string) (string, error)
|
||||
TagImageWithReference(ctx context.Context, imageID image.ID, newTag reference.Named) error
|
||||
GetImage(ctx context.Context, refOrID string, options imagetype.GetImageOpts) (*image.Image, error)
|
||||
ImageHistory(ctx context.Context, name string) ([]*imagetype.HistoryResponseItem, error)
|
||||
CommitImage(ctx context.Context, c backend.CommitConfig) (image.ID, error)
|
||||
|
|
|
@ -80,7 +80,7 @@ func (i *ImageService) ImportImage(ctx context.Context, newRef reference.Named,
|
|||
}
|
||||
|
||||
if newRef != nil {
|
||||
if err := i.TagImageWithReference(id, newRef); err != nil {
|
||||
if err := i.TagImageWithReference(ctx, id, newRef); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,7 @@ import (
|
|||
|
||||
// TagImage creates the tag specified by newTag, pointing to the image named
|
||||
// imageName (alternatively, imageName can also be an image ID).
|
||||
func (i *ImageService) TagImage(imageName, repository, tag string) (string, error) {
|
||||
ctx := context.TODO()
|
||||
func (i *ImageService) TagImage(ctx context.Context, imageName, repository, tag string) (string, error) {
|
||||
img, err := i.GetImage(ctx, imageName, imagetypes.GetImageOpts{})
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -27,12 +26,12 @@ func (i *ImageService) TagImage(imageName, repository, tag string) (string, erro
|
|||
}
|
||||
}
|
||||
|
||||
err = i.TagImageWithReference(img.ID(), newTag)
|
||||
err = i.TagImageWithReference(ctx, img.ID(), newTag)
|
||||
return reference.FamiliarString(newTag), err
|
||||
}
|
||||
|
||||
// TagImageWithReference adds the given reference to the image ID provided.
|
||||
func (i *ImageService) TagImageWithReference(imageID image.ID, newTag reference.Named) error {
|
||||
func (i *ImageService) TagImageWithReference(ctx context.Context, imageID image.ID, newTag reference.Named) error {
|
||||
if err := i.referenceStore.AddTag(newTag, imageID.Digest(), true); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue