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