Skip to content

Commit f0e6488

Browse files
committed
imagebuildah.StageExecutor.volumeCacheSaveOverlay(): force mount
Force the mount of the overlay in volumeCacheSaveOverlay(), and clean it up in volumeCacheRestoreOverlay(), so that we can take advantage of logic that tries to use fuse-overlayfs if we happen to be on top of overlay, which would otherwise fail. Signed-off-by: Nalin Dahyabhai <[email protected]>
1 parent 36c40ec commit f0e6488

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

imagebuildah/stage_executor.go

+23-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/containers/buildah/internal"
2222
"github.com/containers/buildah/internal/tmpdir"
2323
internalUtil "github.com/containers/buildah/internal/util"
24+
"github.com/containers/buildah/pkg/overlay"
2425
"github.com/containers/buildah/pkg/parse"
2526
"github.com/containers/buildah/pkg/rusage"
2627
"github.com/containers/buildah/util"
@@ -313,12 +314,24 @@ func (s *StageExecutor) volumeCacheRestoreVFS() (err error) {
313314
// using it as a lower for an overlay mount in the same location, and then
314315
// discarding the upper.
315316
func (s *StageExecutor) volumeCacheSaveOverlay() (mounts []specs.Mount, err error) {
317+
containerDir, err := s.executor.store.ContainerDirectory(s.builder.ContainerID)
318+
if err != nil {
319+
return nil, fmt.Errorf("unable to locate temporary directory for container")
320+
}
321+
volumeCacheDir := filepath.Join(containerDir, "volume-cache")
322+
options := overlay.Options{
323+
MountLabel: s.builder.MountLabel,
324+
ForceMount: true,
325+
}
316326
for cachedPath := range s.volumeCache {
317327
volumePath := filepath.Join(s.mountPoint, cachedPath)
318-
mount := specs.Mount{
319-
Source: volumePath,
320-
Destination: cachedPath,
321-
Options: []string{"O", "private"},
328+
tmpdir, err := overlay.TempDir(volumeCacheDir, 0, 0)
329+
if err != nil {
330+
return nil, fmt.Errorf("unable to create temporary directory for cache for volumes")
331+
}
332+
mount, err := overlay.MountWithOptions(tmpdir, volumePath, cachedPath, &options)
333+
if err != nil {
334+
return nil, fmt.Errorf("unable to create temporary directory for cache for volumes")
322335
}
323336
mounts = append(mounts, mount)
324337
}
@@ -327,7 +340,12 @@ func (s *StageExecutor) volumeCacheSaveOverlay() (mounts []specs.Mount, err erro
327340

328341
// Reset the contents of each of the executor's list of volumes.
329342
func (s *StageExecutor) volumeCacheRestoreOverlay() error {
330-
return nil
343+
containerDir, err := s.executor.store.ContainerDirectory(s.builder.ContainerID)
344+
if err != nil {
345+
return fmt.Errorf("unable to locate temporary directory for container")
346+
}
347+
volumeCacheDir := filepath.Join(containerDir, "volume-cache")
348+
return overlay.CleanupContent(volumeCacheDir)
331349
}
332350

333351
// Save the contents of each of the executor's list of volumes for which we

0 commit comments

Comments
 (0)