images: Pass context to commit related operations
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
parent
868c897ad7
commit
9b5c21309b
8 changed files with 21 additions and 15 deletions
|
@ -41,7 +41,7 @@ type Backend interface {
|
|||
|
||||
// CommitBuildStep creates a new Docker image from the config generated by
|
||||
// a build step.
|
||||
CommitBuildStep(backend.CommitConfig) (image.ID, error)
|
||||
CommitBuildStep(context.Context, backend.CommitConfig) (image.ID, error)
|
||||
// ContainerCreateWorkdir creates the workdir
|
||||
ContainerCreateWorkdir(containerID string) error
|
||||
|
||||
|
|
|
@ -318,7 +318,7 @@ func dispatchWorkdir(ctx context.Context, d dispatchRequest, c *instructions.Wor
|
|||
return err
|
||||
}
|
||||
|
||||
return d.builder.commitContainer(d.state, containerID, runConfigWithCommentCmd)
|
||||
return d.builder.commitContainer(ctx, d.state, containerID, runConfigWithCommentCmd)
|
||||
}
|
||||
|
||||
// RUN some command yo
|
||||
|
@ -392,7 +392,7 @@ func dispatchRun(ctx context.Context, d dispatchRequest, c *instructions.RunComm
|
|||
runConfigForCacheProbe.ArgsEscaped = stateRunConfig.ArgsEscaped
|
||||
}
|
||||
|
||||
return d.builder.commitContainer(d.state, cID, runConfigForCacheProbe)
|
||||
return d.builder.commitContainer(ctx, d.state, cID, runConfigForCacheProbe)
|
||||
}
|
||||
|
||||
// Derive the command to use for probeCache() and to commit in this container.
|
||||
|
|
|
@ -42,10 +42,10 @@ func (b *Builder) commit(ctx context.Context, dispatchState *dispatchState, comm
|
|||
return err
|
||||
}
|
||||
|
||||
return b.commitContainer(dispatchState, id, runConfigWithCommentCmd)
|
||||
return b.commitContainer(ctx, dispatchState, id, runConfigWithCommentCmd)
|
||||
}
|
||||
|
||||
func (b *Builder) commitContainer(dispatchState *dispatchState, id string, containerConfig *container.Config) error {
|
||||
func (b *Builder) commitContainer(ctx context.Context, dispatchState *dispatchState, id string, containerConfig *container.Config) error {
|
||||
if b.disableCommit {
|
||||
return nil
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ func (b *Builder) commitContainer(dispatchState *dispatchState, id string, conta
|
|||
ContainerID: id,
|
||||
}
|
||||
|
||||
imageID, err := b.docker.CommitBuildStep(commitCfg)
|
||||
imageID, err := b.docker.CommitBuildStep(ctx, commitCfg)
|
||||
dispatchState.imageID = string(imageID)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ func (m *MockBackend) ContainerRm(name string, config *types.ContainerRmConfig)
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m *MockBackend) CommitBuildStep(c backend.CommitConfig) (image.ID, error) {
|
||||
func (m *MockBackend) CommitBuildStep(ctx context.Context, c backend.CommitConfig) (image.ID, error) {
|
||||
if m.commitFunc != nil {
|
||||
return m.commitFunc(c)
|
||||
}
|
||||
|
|
|
@ -155,7 +155,7 @@ func (daemon *Daemon) CreateImageFromContainer(ctx context.Context, name string,
|
|||
return "", err
|
||||
}
|
||||
|
||||
id, err := daemon.imageService.CommitImage(backend.CommitConfig{
|
||||
id, err := daemon.imageService.CommitImage(ctx, backend.CommitConfig{
|
||||
Author: c.Author,
|
||||
Comment: c.Comment,
|
||||
Config: newConfig,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package containerd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/docker/docker/api/types/backend"
|
||||
|
@ -9,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
// CommitImage creates a new image from a commit config.
|
||||
func (i *ImageService) CommitImage(c backend.CommitConfig) (image.ID, error) {
|
||||
func (i *ImageService) CommitImage(ctx context.Context, c backend.CommitConfig) (image.ID, error) {
|
||||
return "", errdefs.NotImplemented(errors.New("not implemented"))
|
||||
}
|
||||
|
||||
|
@ -22,6 +23,6 @@ func (i *ImageService) CommitImage(c backend.CommitConfig) (image.ID, error) {
|
|||
// - it doesn't log a container commit event
|
||||
//
|
||||
// This is a temporary shim. Should be removed when builder stops using commit.
|
||||
func (i *ImageService) CommitBuildStep(c backend.CommitConfig) (image.ID, error) {
|
||||
func (i *ImageService) CommitBuildStep(ctx context.Context, c backend.CommitConfig) (image.ID, error) {
|
||||
return "", errdefs.NotImplemented(errors.New("not implemented"))
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ type ImageService interface {
|
|||
TagImageWithReference(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(c backend.CommitConfig) (image.ID, error)
|
||||
CommitImage(ctx context.Context, c backend.CommitConfig) (image.ID, error)
|
||||
SquashImage(id, parent string) (string, error)
|
||||
|
||||
// Layers
|
||||
|
@ -62,7 +62,7 @@ type ImageService interface {
|
|||
// Build
|
||||
|
||||
MakeImageCache(ctx context.Context, cacheFrom []string) (builder.ImageCache, error)
|
||||
CommitBuildStep(c backend.CommitConfig) (image.ID, error)
|
||||
CommitBuildStep(ctx context.Context, c backend.CommitConfig) (image.ID, error)
|
||||
|
||||
// Other
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package images // import "github.com/docker/docker/daemon/images"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
|
||||
|
@ -12,7 +13,11 @@ import (
|
|||
)
|
||||
|
||||
// CommitImage creates a new image from a commit config
|
||||
func (i *ImageService) CommitImage(c backend.CommitConfig) (image.ID, error) {
|
||||
func (i *ImageService) CommitImage(ctx context.Context, c backend.CommitConfig) (image.ID, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
rwTar, err := exportContainerRw(i.layerStore, c.ContainerID, c.ContainerMountLabel)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -109,7 +114,7 @@ func exportContainerRw(layerStore layer.Store, id, mountLabel string) (arch io.R
|
|||
// - it doesn't log a container commit event
|
||||
//
|
||||
// This is a temporary shim. Should be removed when builder stops using commit.
|
||||
func (i *ImageService) CommitBuildStep(c backend.CommitConfig) (image.ID, error) {
|
||||
func (i *ImageService) CommitBuildStep(ctx context.Context, c backend.CommitConfig) (image.ID, error) {
|
||||
ctr := i.containers.Get(c.ContainerID)
|
||||
if ctr == nil {
|
||||
// TODO: use typed error
|
||||
|
@ -118,5 +123,5 @@ func (i *ImageService) CommitBuildStep(c backend.CommitConfig) (image.ID, error)
|
|||
c.ContainerMountLabel = ctr.MountLabel
|
||||
c.ContainerOS = ctr.OS
|
||||
c.ParentImageID = string(ctr.ImageID)
|
||||
return i.CommitImage(c)
|
||||
return i.CommitImage(ctx, c)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue