2018-02-05 16:05:59 -05:00
|
|
|
package build // import "github.com/docker/docker/api/server/router/build"
|
2015-12-17 16:17:50 -08:00
|
|
|
|
2018-08-05 18:52:35 -07:00
|
|
|
import (
|
2022-05-29 13:45:12 +02:00
|
|
|
"runtime"
|
|
|
|
|
2018-08-05 18:52:35 -07:00
|
|
|
"github.com/docker/docker/api/server/router"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
)
|
2015-12-17 16:17:50 -08:00
|
|
|
|
|
|
|
// buildRouter is a router to talk with the build controller
|
|
|
|
type buildRouter struct {
|
2018-08-21 23:05:26 -07:00
|
|
|
backend Backend
|
|
|
|
daemon experimentalProvider
|
|
|
|
routes []router.Route
|
|
|
|
features *map[string]bool
|
2015-12-17 16:17:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewRouter initializes a new build router
|
2018-08-21 23:05:26 -07:00
|
|
|
func NewRouter(b Backend, d experimentalProvider, features *map[string]bool) router.Router {
|
|
|
|
r := &buildRouter{
|
|
|
|
backend: b,
|
|
|
|
daemon: d,
|
|
|
|
features: features,
|
|
|
|
}
|
2015-12-17 16:17:50 -08:00
|
|
|
r.initRoutes()
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
|
|
|
// Routes returns the available routers to the build controller
|
|
|
|
func (r *buildRouter) Routes() []router.Route {
|
|
|
|
return r.routes
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *buildRouter) initRoutes() {
|
|
|
|
r.routes = []router.Route{
|
2018-11-27 14:13:43 -08:00
|
|
|
router.NewPostRoute("/build", r.postBuild),
|
|
|
|
router.NewPostRoute("/build/prune", r.postPrune),
|
2018-04-19 11:08:33 -07:00
|
|
|
router.NewPostRoute("/build/cancel", r.postCancel),
|
2015-12-17 16:17:50 -08:00
|
|
|
}
|
|
|
|
}
|
2018-08-21 23:05:26 -07:00
|
|
|
|
2022-05-29 13:45:12 +02:00
|
|
|
// BuilderVersion derives the default docker builder version from the config.
|
|
|
|
//
|
|
|
|
// The default on Linux is version "2" (BuildKit), but the daemon can be
|
|
|
|
// configured to recommend version "1" (classic Builder). Windows does not
|
|
|
|
// yet support BuildKit for native Windows images, and uses "1" (classic builder)
|
|
|
|
// as a default.
|
|
|
|
//
|
|
|
|
// This value is only a recommendation as advertised by the daemon, and it is
|
|
|
|
// up to the client to choose which builder to use.
|
2018-08-21 23:05:26 -07:00
|
|
|
func BuilderVersion(features map[string]bool) types.BuilderVersion {
|
2022-05-29 13:45:12 +02:00
|
|
|
// TODO(thaJeztah) move the default to daemon/config
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
return types.BuilderV1
|
|
|
|
}
|
|
|
|
|
|
|
|
bv := types.BuilderBuildKit
|
|
|
|
if v, ok := features["buildkit"]; ok && !v {
|
|
|
|
bv = types.BuilderV1
|
2018-08-21 23:05:26 -07:00
|
|
|
}
|
|
|
|
return bv
|
|
|
|
}
|