diff --git a/builder/dockerfile/internals.go b/builder/dockerfile/internals.go index 3376b0bcdd..77b51d35d9 100644 --- a/builder/dockerfile/internals.go +++ b/builder/dockerfile/internals.go @@ -11,7 +11,6 @@ import ( "os" "path" "path/filepath" - "runtime" "strings" "github.com/docker/docker/api/types" @@ -448,8 +447,7 @@ func (b *Builder) probeAndCreate(dispatchState *dispatchState, runConfig *contai func (b *Builder) create(runConfig *container.Config) (string, error) { logrus.Debugf("[BUILDER] Command to be executed: %v", runConfig.Cmd) - isWCOW := runtime.GOOS == "windows" && b.platform != nil && b.platform.OS == "windows" - hostConfig := hostConfigFromOptions(b.options, isWCOW) + hostConfig := hostConfigFromOptions(b.options) container, err := b.containerManager.Create(runConfig, hostConfig) if err != nil { return "", err @@ -462,7 +460,7 @@ func (b *Builder) create(runConfig *container.Config) (string, error) { return container.ID, nil } -func hostConfigFromOptions(options *types.ImageBuildOptions, isWCOW bool) *container.HostConfig { +func hostConfigFromOptions(options *types.ImageBuildOptions) *container.HostConfig { resources := container.Resources{ CgroupParent: options.CgroupParent, CPUShares: options.CPUShares, @@ -485,16 +483,6 @@ func hostConfigFromOptions(options *types.ImageBuildOptions, isWCOW bool) *conta LogConfig: defaultLogConfig, ExtraHosts: options.ExtraHosts, } - - // For WCOW, the default of 20GB hard-coded in the platform - // is too small for builder scenarios where many users are - // using RUN statements to install large amounts of data. - // Use 127GB as that's the default size of a VHD in Hyper-V. - if isWCOW { - hc.StorageOpt = make(map[string]string) - hc.StorageOpt["size"] = "127GB" - } - return hc } diff --git a/daemon/graphdriver/windows/windows.go b/daemon/graphdriver/windows/windows.go index a5f614dfae..5213dda6f0 100644 --- a/daemon/graphdriver/windows/windows.go +++ b/daemon/graphdriver/windows/windows.go @@ -38,8 +38,15 @@ import ( "golang.org/x/sys/windows" ) -// filterDriver is an HCSShim driver type for the Windows Filter driver. -const filterDriver = 1 +const ( + // filterDriver is an HCSShim driver type for the Windows Filter driver. + filterDriver = 1 + // For WCOW, the default of 20GB hard-coded in the platform + // is too small for builder scenarios where many users are + // using RUN or COPY statements to install large amounts of data. + // Use 127GB as that's the default size of a VHD in Hyper-V. + defaultSandboxSize = "127GB" +) var ( // mutatedFiles is a list of files that are mutated by the import process @@ -73,6 +80,10 @@ func (c *checker) IsMounted(path string) bool { return false } +type storageOptions struct { + size uint64 +} + // Driver represents a windows graph driver. type Driver struct { // info stores the shim driver information @@ -80,8 +91,9 @@ type Driver struct { ctr *graphdriver.RefCounter // it is safe for windows to use a cache here because it does not support // restoring containers when the daemon dies. - cacheMu sync.Mutex - cache map[string]string + cacheMu sync.Mutex + cache map[string]string + defaultStorageOpts *storageOptions } // InitFilter returns a new Windows storage filter driver. @@ -100,6 +112,11 @@ func InitFilter(home string, options []string, uidMaps, gidMaps []idtools.IDMap) return nil, fmt.Errorf("windowsfilter failed to create '%s': %v", home, err) } + size, err := units.RAMInBytes(defaultSandboxSize) + if err != nil { + return nil, fmt.Errorf("windowsfilter failed to parse default size '%s': %v", defaultSandboxSize, err) + } + d := &Driver{ info: hcsshim.DriverInfo{ HomeDir: home, @@ -107,6 +124,9 @@ func InitFilter(home string, options []string, uidMaps, gidMaps []idtools.IDMap) }, cache: make(map[string]string), ctr: graphdriver.NewRefCounter(&checker{}), + defaultStorageOpts: &storageOptions{ + size: uint64(size), + }, } return d, nil } @@ -231,8 +251,13 @@ func (d *Driver) create(id, parent, mountLabel string, readOnly bool, storageOpt return fmt.Errorf("Failed to parse storage options - %s", err) } + sandboxSize := d.defaultStorageOpts.size if storageOptions.size != 0 { - if err := hcsshim.ExpandSandboxSize(d.info, id, storageOptions.size); err != nil { + sandboxSize = storageOptions.size + } + + if sandboxSize != 0 { + if err := hcsshim.ExpandSandboxSize(d.info, id, sandboxSize); err != nil { return err } } @@ -935,10 +960,6 @@ func (d *Driver) DiffGetter(id string) (graphdriver.FileGetCloser, error) { return &fileGetCloserWithBackupPrivileges{d.dir(id)}, nil } -type storageOptions struct { - size uint64 -} - func parseStorageOpt(storageOpt map[string]string) (*storageOptions, error) { options := storageOptions{}