diff --git a/builder/builder.go b/builder/builder.go index bbf0a30e15..caff35aead 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -111,7 +111,7 @@ func (fi *HashedFileInfo) SetHash(h string) { type Backend interface { // TODO: use digest reference instead of name - // LookupImage looks up a Docker image referenced by `name`. + // GetImage looks up a Docker image referenced by `name`. GetImage(name string) (*image.Image, error) // Pull tells Docker to pull image referenced by `name`. Pull(name string) (*image.Image, error) @@ -142,12 +142,11 @@ type Backend interface { // TODO: use copyBackend api BuilderCopy(containerID string, destPath string, src FileInfo, decompress bool) error - // Retain retains an image avoiding it to be removed or overwritten until a corresponding Release() call. // TODO: remove - Retain(sessionID, imgID string) - // Release releases a list of images that were retained for the time of a build. - // TODO: remove - Release(sessionID string, activeImages []string) + // Mount mounts the root filesystem for the container. + Mount(containerID string) error + // Unmount unmounts the root filesystem for the container. + Unmount(containerID string) error } // ImageCache abstracts an image cache store. diff --git a/builder/dockerfile/builder.go b/builder/dockerfile/builder.go index 554e0c9558..5b254440eb 100644 --- a/builder/dockerfile/builder.go +++ b/builder/dockerfile/builder.go @@ -95,8 +95,7 @@ type Builder struct { allowedBuildArgs map[string]bool // list of build-time args that are allowed for expansion/substitution and passing to commands in 'run'. // TODO: remove once docker.Commit can receive a tag - id string - activeImages []string + id string } // NewBuilder creates a new Dockerfile builder from an optional dockerfile and a Config. @@ -145,11 +144,6 @@ func NewBuilder(config *Config, docker builder.Backend, context builder.Context, // * NOT tag the image, that is responsibility of the caller. // func (b *Builder) Build() (string, error) { - // TODO: remove once b.docker.Commit can take a tag parameter. - defer func() { - b.docker.Release(b.id, b.activeImages) - }() - // If Dockerfile was not parsed yet, extract it from the Context if b.dockerfile == nil { if err := b.readDockerfile(); err != nil { diff --git a/builder/dockerfile/dispatchers.go b/builder/dockerfile/dispatchers.go index 038a2c8c61..97f50bb4e9 100644 --- a/builder/dockerfile/dispatchers.go +++ b/builder/dockerfile/dispatchers.go @@ -399,6 +399,9 @@ func run(b *Builder, args []string, attributes map[string]bool, original string) return err } + b.docker.Mount(cID) + defer b.docker.Unmount(cID) + if err := b.run(cID); err != nil { return err } diff --git a/builder/dockerfile/internals.go b/builder/dockerfile/internals.go index 91b2c0eb02..0d87c12b04 100644 --- a/builder/dockerfile/internals.go +++ b/builder/dockerfile/internals.go @@ -66,6 +66,10 @@ func (b *Builder) commit(id string, autoCmd *stringutils.StrSlice, comment strin if err != nil { return err } + if err := b.docker.Mount(id); err != nil { + return err + } + defer b.docker.Unmount(id) } // Note: Actually copy the struct @@ -83,8 +87,6 @@ func (b *Builder) commit(id string, autoCmd *stringutils.StrSlice, comment strin if err != nil { return err } - b.docker.Retain(b.id, imageID) - b.activeImages = append(b.activeImages, imageID) b.image = imageID return nil } @@ -191,6 +193,10 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowLocalD if err != nil { return err } + if err := b.docker.Mount(container.ID); err != nil { + return err + } + defer b.docker.Unmount(container.ID) b.tmpContainers[container.ID] = struct{}{} comment := fmt.Sprintf("%s %s in %s", cmdName, origPaths, dest) @@ -471,10 +477,6 @@ func (b *Builder) probeCache() (bool, error) { logrus.Debugf("[BUILDER] Use cached version: %s", b.runConfig.Cmd) b.image = string(cache) - // TODO: remove once Commit can take a tag parameter. - b.docker.Retain(b.id, b.image) - b.activeImages = append(b.activeImages, b.image) - return true, nil } diff --git a/daemon/daemonbuilder/builder.go b/daemon/daemonbuilder/builder.go index 61d09f6a76..6da9896301 100644 --- a/daemon/daemonbuilder/builder.go +++ b/daemon/daemonbuilder/builder.go @@ -176,6 +176,25 @@ func (d Docker) BuilderCopy(cID string, destPath string, src builder.FileInfo, d return fixPermissions(srcPath, destPath, rootUID, rootGID, destExists) } +// Mount mounts the root filesystem for the container. +func (d Docker) Mount(cID string) error { + c, err := d.Daemon.GetContainer(cID) + if err != nil { + return err + } + return d.Daemon.Mount(c) +} + +// Unmount unmounts the root filesystem for the container. +func (d Docker) Unmount(cID string) error { + c, err := d.Daemon.GetContainer(cID) + if err != nil { + return err + } + d.Daemon.Unmount(c) + return nil +} + // GetCachedImage returns a reference to a cached image whose parent equals `parent` // and runconfig equals `cfg`. A cache miss is expected to return an empty ID and a nil error. func (d Docker) GetCachedImage(imgID string, cfg *runconfig.Config) (string, error) {