Skip to content

Commit

Permalink
feat(buildah): support autodetection of native mode for overlayfs
Browse files Browse the repository at this point in the history
  • Loading branch information
distorhead committed Dec 10, 2021
1 parent c87f7c3 commit 7858360
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/buildah/common.go
Expand Up @@ -175,7 +175,7 @@ func ResolveMode(mode Mode) Mode {
}
}

func GetOverlayOptions() ([]string, error) {
func GetFuseOverlayfsOptions() ([]string, error) {
fuseOverlayBinPath, err := exec.LookPath("fuse-overlayfs")
if err != nil {
return nil, fmt.Errorf("\"fuse-overlayfs\" binary not found in PATH: %s", err)
Expand Down
5 changes: 3 additions & 2 deletions pkg/buildah/docker_with_fuse.go
Expand Up @@ -276,11 +276,12 @@ func runStorageContainer(ctx context.Context, name, image string) error {
func newBuildahCliStoreOptions(driver StorageDriver) (*StoreOptions, error) {
var graphDriverOptions []string
if driver == StorageDriverOverlay {
overlayOpts, err := GetOverlayOptions()
fuseOpts, err := GetFuseOverlayfsOptions()
if err != nil {
return nil, fmt.Errorf("unable to get overlay options: %s", err)
}
graphDriverOptions = append(graphDriverOptions, overlayOpts...)
graphDriverOptions = append(graphDriverOptions, fuseOpts...)
graphDriverOptions = append(graphDriverOptions, fmt.Sprintf("%s.ignore_chown_errors=true", StorageDriverOverlay))
}

return &StoreOptions{
Expand Down
21 changes: 17 additions & 4 deletions pkg/buildah/native_linux.go
Expand Up @@ -13,6 +13,8 @@ import (
"strings"
"time"

"github.com/containers/storage/drivers/overlay"

"github.com/containers/buildah"
"github.com/containers/buildah/define"
"github.com/containers/buildah/imagebuildah"
Expand Down Expand Up @@ -360,12 +362,23 @@ func NewNativeStoreOptions(rootlessUID int, driver StorageDriver) (*thirdparty.S
}

var graphDriverOptions []string
if driver == StorageDriverOverlay {
overlayOpts, err := GetOverlayOptions()
switch driver {
case StorageDriverOverlay:
supportsNative, err := overlay.SupportsNativeOverlay(graphRoot, runRoot)
if err != nil {
return nil, fmt.Errorf("unable to get overlay options: %s", err)
return nil, fmt.Errorf("unable to check native overlayfs support: %s", err)
}
graphDriverOptions = append(graphDriverOptions, overlayOpts...)

if !supportsNative {
fuseOpts, err := GetFuseOverlayfsOptions()
if err != nil {
return nil, fmt.Errorf("unable to get fuse overlayfs options: %s", err)
}

graphDriverOptions = append(graphDriverOptions, fuseOpts...)
}

graphDriverOptions = append(graphDriverOptions, fmt.Sprintf("%s.ignore_chown_errors=true", StorageDriverOverlay))
}

return &thirdparty.StoreOptions{
Expand Down

0 comments on commit 7858360

Please sign in to comment.