build.go 1.7 KB

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