github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/api/server/router/build/build.go (about)

     1  package build // import "github.com/docker/docker/api/server/router/build"
     2  
     3  import (
     4  	"runtime"
     5  
     6  	"github.com/docker/docker/api/server/router"
     7  	"github.com/docker/docker/api/types"
     8  )
     9  
    10  // buildRouter is a router to talk with the build controller
    11  type buildRouter struct {
    12  	backend  Backend
    13  	daemon   experimentalProvider
    14  	routes   []router.Route
    15  	features *map[string]bool
    16  }
    17  
    18  // NewRouter initializes a new build router
    19  func NewRouter(b Backend, d experimentalProvider, features *map[string]bool) router.Router {
    20  	r := &buildRouter{
    21  		backend:  b,
    22  		daemon:   d,
    23  		features: features,
    24  	}
    25  	r.initRoutes()
    26  	return r
    27  }
    28  
    29  // Routes returns the available routers to the build controller
    30  func (r *buildRouter) Routes() []router.Route {
    31  	return r.routes
    32  }
    33  
    34  func (r *buildRouter) initRoutes() {
    35  	r.routes = []router.Route{
    36  		router.NewPostRoute("/build", r.postBuild),
    37  		router.NewPostRoute("/build/prune", r.postPrune),
    38  		router.NewPostRoute("/build/cancel", r.postCancel),
    39  	}
    40  }
    41  
    42  // BuilderVersion derives the default docker builder version from the config.
    43  //
    44  // The default on Linux is version "2" (BuildKit), but the daemon can be
    45  // configured to recommend version "1" (classic Builder). Windows does not
    46  // yet support BuildKit for native Windows images, and uses "1" (classic builder)
    47  // as a default.
    48  //
    49  // This value is only a recommendation as advertised by the daemon, and it is
    50  // up to the client to choose which builder to use.
    51  func BuilderVersion(features map[string]bool) types.BuilderVersion {
    52  	// TODO(thaJeztah) move the default to daemon/config
    53  	if runtime.GOOS == "windows" {
    54  		return types.BuilderV1
    55  	}
    56  
    57  	bv := types.BuilderBuildKit
    58  	if v, ok := features["buildkit"]; ok && !v {
    59  		bv = types.BuilderV1
    60  	}
    61  	return bv
    62  }