-
Notifications
You must be signed in to change notification settings - Fork 229
/
controller.go
66 lines (56 loc) · 1.66 KB
/
controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package client
import (
"fmt"
"path/filepath"
"github.com/moby/buildkit/control"
"github.com/moby/buildkit/frontend"
"github.com/moby/buildkit/frontend/dockerfile"
"github.com/moby/buildkit/frontend/gateway"
"github.com/moby/buildkit/solver/boltdbcachestorage"
"github.com/moby/buildkit/worker"
"github.com/moby/buildkit/worker/base"
)
func (c *Client) createController() error {
sm, err := c.getSessionManager()
if err != nil {
return fmt.Errorf("creating session manager failed: %v", err)
}
// Create the worker opts.
opt, err := c.createWorkerOpt(true)
if err != nil {
return fmt.Errorf("creating worker opt failed: %v", err)
}
// Create the new worker.
w, err := base.NewWorker(opt)
if err != nil {
return fmt.Errorf("creating worker failed: %v", err)
}
// Create the worker controller.
wc := &worker.Controller{}
if err := wc.Add(w); err != nil {
return fmt.Errorf("adding worker to worker controller failed: %v", err)
}
// Add the frontends.
frontends := map[string]frontend.Frontend{}
frontends["dockerfile.v0"] = dockerfile.NewDockerfileFrontend()
frontends["gateway.v0"] = gateway.NewGatewayFrontend()
// Create the cache storage
cacheStorage, err := boltdbcachestorage.NewStore(filepath.Join(c.root, "cache.db"))
if err != nil {
return err
}
// Create the controller.
controller, err := control.NewController(control.Opt{
SessionManager: sm,
WorkerController: wc,
Frontends: frontends,
CacheKeyStorage: cacheStorage,
// No cache importer/exporter
})
if err != nil {
return fmt.Errorf("creating new controller failed: %v", err)
}
// Set the controller for the client.
c.controller = controller
return nil
}