mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
builder: remove unused Retain/Release and put Mount/Unmount back
Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
parent
c70f8b3c9c
commit
93c0de2af4
5 changed files with 36 additions and 19 deletions
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue