github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/pkg/system/lcow.go (about)

     1  // +build windows,!no_lcow
     2  
     3  package system // import "github.com/demonoid81/moby/pkg/system"
     4  
     5  import (
     6  	"strings"
     7  
     8  	"github.com/Microsoft/hcsshim/osversion"
     9  	specs "github.com/opencontainers/image-spec/specs-go/v1"
    10  	"github.com/pkg/errors"
    11  )
    12  
    13  var (
    14  	// lcowSupported determines if Linux Containers on Windows are supported.
    15  	lcowSupported = false
    16  )
    17  
    18  // InitLCOW sets whether LCOW is supported or not. Requires RS5+
    19  func InitLCOW(experimental bool) {
    20  	if experimental && osversion.Build() >= osversion.RS5 {
    21  		lcowSupported = true
    22  	}
    23  }
    24  
    25  func LCOWSupported() bool {
    26  	return lcowSupported
    27  }
    28  
    29  // ValidatePlatform determines if a platform structure is valid.
    30  // TODO This is a temporary windows-only function, should be replaced by
    31  // comparison of worker capabilities
    32  func ValidatePlatform(platform specs.Platform) error {
    33  	if !IsOSSupported(platform.OS) {
    34  		return errors.Errorf("unsupported os %s", platform.OS)
    35  	}
    36  	return nil
    37  }
    38  
    39  // IsOSSupported determines if an operating system is supported by the host
    40  func IsOSSupported(os string) bool {
    41  	if strings.EqualFold("windows", os) {
    42  		return true
    43  	}
    44  	if LCOWSupported() && strings.EqualFold(os, "linux") {
    45  		return true
    46  	}
    47  	return false
    48  }