builder: remove unused Retain/Release and put Mount/Unmount back

Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
Tibor Vass 2015-12-15 17:21:04 +01:00
parent c70f8b3c9c
commit 93c0de2af4
5 changed files with 36 additions and 19 deletions

View File

@ -111,7 +111,7 @@ func (fi *HashedFileInfo) SetHash(h string) {
type Backend interface { type Backend interface {
// TODO: use digest reference instead of name // 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) GetImage(name string) (*image.Image, error)
// Pull tells Docker to pull image referenced by `name`. // Pull tells Docker to pull image referenced by `name`.
Pull(name string) (*image.Image, error) Pull(name string) (*image.Image, error)
@ -142,12 +142,11 @@ type Backend interface {
// TODO: use copyBackend api // TODO: use copyBackend api
BuilderCopy(containerID string, destPath string, src FileInfo, decompress bool) error 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 // TODO: remove
Retain(sessionID, imgID string) // Mount mounts the root filesystem for the container.
// Release releases a list of images that were retained for the time of a build. Mount(containerID string) error
// TODO: remove // Unmount unmounts the root filesystem for the container.
Release(sessionID string, activeImages []string) Unmount(containerID string) error
} }
// ImageCache abstracts an image cache store. // ImageCache abstracts an image cache store.

View File

@ -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'. 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 // TODO: remove once docker.Commit can receive a tag
id string id string
activeImages []string
} }
// NewBuilder creates a new Dockerfile builder from an optional dockerfile and a Config. // 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. // * NOT tag the image, that is responsibility of the caller.
// //
func (b *Builder) Build() (string, error) { 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 Dockerfile was not parsed yet, extract it from the Context
if b.dockerfile == nil { if b.dockerfile == nil {
if err := b.readDockerfile(); err != nil { if err := b.readDockerfile(); err != nil {

View File

@ -399,6 +399,9 @@ func run(b *Builder, args []string, attributes map[string]bool, original string)
return err return err
} }
b.docker.Mount(cID)
defer b.docker.Unmount(cID)
if err := b.run(cID); err != nil { if err := b.run(cID); err != nil {
return err return err
} }

View File

@ -66,6 +66,10 @@ func (b *Builder) commit(id string, autoCmd *stringutils.StrSlice, comment strin
if err != nil { if err != nil {
return err return err
} }
if err := b.docker.Mount(id); err != nil {
return err
}
defer b.docker.Unmount(id)
} }
// Note: Actually copy the struct // Note: Actually copy the struct
@ -83,8 +87,6 @@ func (b *Builder) commit(id string, autoCmd *stringutils.StrSlice, comment strin
if err != nil { if err != nil {
return err return err
} }
b.docker.Retain(b.id, imageID)
b.activeImages = append(b.activeImages, imageID)
b.image = imageID b.image = imageID
return nil return nil
} }
@ -191,6 +193,10 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowLocalD
if err != nil { if err != nil {
return err return err
} }
if err := b.docker.Mount(container.ID); err != nil {
return err
}
defer b.docker.Unmount(container.ID)
b.tmpContainers[container.ID] = struct{}{} b.tmpContainers[container.ID] = struct{}{}
comment := fmt.Sprintf("%s %s in %s", cmdName, origPaths, dest) 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) logrus.Debugf("[BUILDER] Use cached version: %s", b.runConfig.Cmd)
b.image = string(cache) 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 return true, nil
} }

View File

@ -176,6 +176,25 @@ func (d Docker) BuilderCopy(cID string, destPath string, src builder.FileInfo, d
return fixPermissions(srcPath, destPath, rootUID, rootGID, destExists) 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` // 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. // 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) { func (d Docker) GetCachedImage(imgID string, cfg *runconfig.Config) (string, error) {