Signed-off-by: Tibor Vass <tibor@docker.com>
| ... | ... |
@@ -111,7 +111,7 @@ func (fi *HashedFileInfo) SetHash(h string) {
|
| 111 | 111 |
type Backend interface {
|
| 112 | 112 |
// TODO: use digest reference instead of name |
| 113 | 113 |
|
| 114 |
- // LookupImage looks up a Docker image referenced by `name`. |
|
| 114 |
+ // GetImage looks up a Docker image referenced by `name`. |
|
| 115 | 115 |
GetImage(name string) (*image.Image, error) |
| 116 | 116 |
// Pull tells Docker to pull image referenced by `name`. |
| 117 | 117 |
Pull(name string) (*image.Image, error) |
| ... | ... |
@@ -142,12 +142,11 @@ type Backend interface {
|
| 142 | 142 |
// TODO: use copyBackend api |
| 143 | 143 |
BuilderCopy(containerID string, destPath string, src FileInfo, decompress bool) error |
| 144 | 144 |
|
| 145 |
- // Retain retains an image avoiding it to be removed or overwritten until a corresponding Release() call. |
|
| 146 | 145 |
// TODO: remove |
| 147 |
- Retain(sessionID, imgID string) |
|
| 148 |
- // Release releases a list of images that were retained for the time of a build. |
|
| 149 |
- // TODO: remove |
|
| 150 |
- Release(sessionID string, activeImages []string) |
|
| 146 |
+ // Mount mounts the root filesystem for the container. |
|
| 147 |
+ Mount(containerID string) error |
|
| 148 |
+ // Unmount unmounts the root filesystem for the container. |
|
| 149 |
+ Unmount(containerID string) error |
|
| 151 | 150 |
} |
| 152 | 151 |
|
| 153 | 152 |
// ImageCache abstracts an image cache store. |
| ... | ... |
@@ -95,8 +95,7 @@ type Builder struct {
|
| 95 | 95 |
allowedBuildArgs map[string]bool // list of build-time args that are allowed for expansion/substitution and passing to commands in 'run'. |
| 96 | 96 |
|
| 97 | 97 |
// TODO: remove once docker.Commit can receive a tag |
| 98 |
- id string |
|
| 99 |
- activeImages []string |
|
| 98 |
+ id string |
|
| 100 | 99 |
} |
| 101 | 100 |
|
| 102 | 101 |
// 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, |
| 145 | 145 |
// * NOT tag the image, that is responsibility of the caller. |
| 146 | 146 |
// |
| 147 | 147 |
func (b *Builder) Build() (string, error) {
|
| 148 |
- // TODO: remove once b.docker.Commit can take a tag parameter. |
|
| 149 |
- defer func() {
|
|
| 150 |
- b.docker.Release(b.id, b.activeImages) |
|
| 151 |
- }() |
|
| 152 |
- |
|
| 153 | 148 |
// If Dockerfile was not parsed yet, extract it from the Context |
| 154 | 149 |
if b.dockerfile == nil {
|
| 155 | 150 |
if err := b.readDockerfile(); err != nil {
|
| ... | ... |
@@ -66,6 +66,10 @@ func (b *Builder) commit(id string, autoCmd *stringutils.StrSlice, comment strin |
| 66 | 66 |
if err != nil {
|
| 67 | 67 |
return err |
| 68 | 68 |
} |
| 69 |
+ if err := b.docker.Mount(id); err != nil {
|
|
| 70 |
+ return err |
|
| 71 |
+ } |
|
| 72 |
+ defer b.docker.Unmount(id) |
|
| 69 | 73 |
} |
| 70 | 74 |
|
| 71 | 75 |
// Note: Actually copy the struct |
| ... | ... |
@@ -83,8 +87,6 @@ func (b *Builder) commit(id string, autoCmd *stringutils.StrSlice, comment strin |
| 83 | 83 |
if err != nil {
|
| 84 | 84 |
return err |
| 85 | 85 |
} |
| 86 |
- b.docker.Retain(b.id, imageID) |
|
| 87 |
- b.activeImages = append(b.activeImages, imageID) |
|
| 88 | 86 |
b.image = imageID |
| 89 | 87 |
return nil |
| 90 | 88 |
} |
| ... | ... |
@@ -191,6 +193,10 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowLocalD |
| 191 | 191 |
if err != nil {
|
| 192 | 192 |
return err |
| 193 | 193 |
} |
| 194 |
+ if err := b.docker.Mount(container.ID); err != nil {
|
|
| 195 |
+ return err |
|
| 196 |
+ } |
|
| 197 |
+ defer b.docker.Unmount(container.ID) |
|
| 194 | 198 |
b.tmpContainers[container.ID] = struct{}{}
|
| 195 | 199 |
|
| 196 | 200 |
comment := fmt.Sprintf("%s %s in %s", cmdName, origPaths, dest)
|
| ... | ... |
@@ -471,10 +477,6 @@ func (b *Builder) probeCache() (bool, error) {
|
| 471 | 471 |
logrus.Debugf("[BUILDER] Use cached version: %s", b.runConfig.Cmd)
|
| 472 | 472 |
b.image = string(cache) |
| 473 | 473 |
|
| 474 |
- // TODO: remove once Commit can take a tag parameter. |
|
| 475 |
- b.docker.Retain(b.id, b.image) |
|
| 476 |
- b.activeImages = append(b.activeImages, b.image) |
|
| 477 |
- |
|
| 478 | 474 |
return true, nil |
| 479 | 475 |
} |
| 480 | 476 |
|
| ... | ... |
@@ -176,6 +176,25 @@ func (d Docker) BuilderCopy(cID string, destPath string, src builder.FileInfo, d |
| 176 | 176 |
return fixPermissions(srcPath, destPath, rootUID, rootGID, destExists) |
| 177 | 177 |
} |
| 178 | 178 |
|
| 179 |
+// Mount mounts the root filesystem for the container. |
|
| 180 |
+func (d Docker) Mount(cID string) error {
|
|
| 181 |
+ c, err := d.Daemon.GetContainer(cID) |
|
| 182 |
+ if err != nil {
|
|
| 183 |
+ return err |
|
| 184 |
+ } |
|
| 185 |
+ return d.Daemon.Mount(c) |
|
| 186 |
+} |
|
| 187 |
+ |
|
| 188 |
+// Unmount unmounts the root filesystem for the container. |
|
| 189 |
+func (d Docker) Unmount(cID string) error {
|
|
| 190 |
+ c, err := d.Daemon.GetContainer(cID) |
|
| 191 |
+ if err != nil {
|
|
| 192 |
+ return err |
|
| 193 |
+ } |
|
| 194 |
+ d.Daemon.Unmount(c) |
|
| 195 |
+ return nil |
|
| 196 |
+} |
|
| 197 |
+ |
|
| 179 | 198 |
// GetCachedImage returns a reference to a cached image whose parent equals `parent` |
| 180 | 199 |
// and runconfig equals `cfg`. A cache miss is expected to return an empty ID and a nil error. |
| 181 | 200 |
func (d Docker) GetCachedImage(imgID string, cfg *runconfig.Config) (string, error) {
|