build.go 1.6 KB

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