forked from krystal/guvnor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
guvnor.go
58 lines (53 loc) · 1.27 KB
/
guvnor.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
package guvnor
import (
"github.com/docker/docker/client"
"github.com/go-playground/validator/v10"
"github.com/krystal/guvnor/caddy"
"github.com/krystal/guvnor/state"
"go.uber.org/zap"
)
const (
serviceLabel = "io.k.guvnor.service"
processLabel = "io.k.guvnor.process"
taskLabel = "io.k.guvnor.task"
deploymentLabel = "io.k.guvnor.deployment"
managedLabel = "io.k.guvnor.managed"
portLabel = "io.k.guvnor.port"
)
type Engine struct {
log *zap.Logger
docker client.APIClient
config EngineConfig
caddy *caddy.Manager
state *state.FileBasedStore
validate *validator.Validate
}
func NewEngine(log *zap.Logger, docker client.APIClient, cfg EngineConfig, validate *validator.Validate) *Engine {
if validate == nil {
validate = validator.New()
}
if log == nil {
log = zap.NewNop()
}
return &Engine{
log: log,
docker: docker,
config: cfg,
caddy: &caddy.Manager{
Docker: docker,
Log: log.Named("caddy"),
Config: cfg.Caddy,
ContainerLabels: map[string]string{
managedLabel: "1",
},
CaddyConfigurator: caddy.NewAdminAPIClient(
log.Named("caddy").Named("client"),
),
},
validate: validate,
state: &state.FileBasedStore{
RootPath: cfg.Paths.State,
Log: log.Named("state"),
},
}
}