|
@@ -31,21 +31,25 @@ func monitorSignals() <-chan bool {
|
31
|
31
|
}
|
32
|
32
|
|
33
|
33
|
func main() {
|
34
|
|
- config := zap.NewDevelopmentConfig()
|
35
|
|
- config.DisableCaller = true
|
36
|
|
- config.DisableStacktrace = true
|
37
|
|
- config.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
38
|
|
- config.OutputPaths = []string{"stdout"}
|
39
|
|
- config.ErrorOutputPaths = []string{"stdout"}
|
40
|
|
- logger, _ := config.Build()
|
|
34
|
+ zapConfig := zap.NewDevelopmentConfig()
|
|
35
|
+ zapConfig.DisableCaller = true
|
|
36
|
+ zapConfig.DisableStacktrace = true
|
|
37
|
+ zapConfig.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
|
38
|
+ zapConfig.OutputPaths = []string{"stdout"}
|
|
39
|
+ zapConfig.ErrorOutputPaths = []string{"stdout"}
|
|
40
|
+ logger, _ := zapConfig.Build()
|
41
|
41
|
sugar := logger.Sugar()
|
42
|
42
|
sugar.Info("Dotege is starting")
|
43
|
43
|
|
44
|
44
|
done := monitorSignals()
|
45
|
45
|
containerChan := make(chan model.Container, 1)
|
46
|
46
|
expiryChan := make(chan string, 1)
|
47
|
|
- labelConfig := model.LabelConfig{
|
48
|
|
- Hostnames: "com.chameth.vhost",
|
|
47
|
+ config := model.Config{
|
|
48
|
+ Labels: model.LabelConfig{
|
|
49
|
+ Hostnames: "com.chameth.vhost",
|
|
50
|
+ },
|
|
51
|
+ DefaultCertActions: model.COMBINE | model.FLATTEN,
|
|
52
|
+ DefaultCertDestination: "/data/certs/",
|
49
|
53
|
}
|
50
|
54
|
|
51
|
55
|
cli, err := client.NewEnvClient()
|
|
@@ -54,12 +58,12 @@ func main() {
|
54
|
58
|
}
|
55
|
59
|
|
56
|
60
|
certMonitor := certs.NewCertificateManager(sugar)
|
57
|
|
- certMonitor.AddDirectory("/certs/certs")
|
|
61
|
+ certMonitor.AddDirectory("/data/certrequests/certs")
|
58
|
62
|
|
59
|
63
|
templateGenerator := NewTemplateGenerator(sugar)
|
60
|
64
|
templateGenerator.AddTemplate(model.TemplateConfig{
|
61
|
65
|
Source: "./templates/domains.txt.tpl",
|
62
|
|
- Destination: "domains.txt",
|
|
66
|
+ Destination: "/data/certrequests/domains.txt",
|
63
|
67
|
})
|
64
|
68
|
templateGenerator.AddTemplate(model.TemplateConfig{
|
65
|
69
|
Source: "./templates/haproxy.cfg.tpl",
|
|
@@ -85,7 +89,7 @@ func main() {
|
85
|
89
|
case <-timer.C:
|
86
|
90
|
templateGenerator.Generate(Context{
|
87
|
91
|
Containers: containers,
|
88
|
|
- Hostnames: getHostnames(containers, labelConfig),
|
|
92
|
+ Hostnames: getHostnames(containers, config),
|
89
|
93
|
})
|
90
|
94
|
}
|
91
|
95
|
}
|
|
@@ -99,18 +103,20 @@ func main() {
|
99
|
103
|
}
|
100
|
104
|
}
|
101
|
105
|
|
102
|
|
-func getHostnames(containers map[string]model.Container, config model.LabelConfig) (hostnames map[string]*model.Hostname) {
|
|
106
|
+func getHostnames(containers map[string]model.Container, config model.Config) (hostnames map[string]*model.Hostname) {
|
103
|
107
|
hostnames = make(map[string]*model.Hostname)
|
104
|
108
|
for _, container := range containers {
|
105
|
|
- if label, ok := container.Labels[config.Hostnames]; ok {
|
|
109
|
+ if label, ok := container.Labels[config.Labels.Hostnames]; ok {
|
106
|
110
|
names := strings.Split(strings.Replace(label, ",", " ", -1), " ")
|
107
|
111
|
if hostname, ok := hostnames[names[0]]; ok {
|
108
|
112
|
hostname.Containers = append(hostname.Containers, container)
|
109
|
113
|
} else {
|
110
|
114
|
hostnames[names[0]] = &model.Hostname{
|
111
|
|
- Name: names[0],
|
112
|
|
- Alternatives: make(map[string]bool),
|
113
|
|
- Containers: []model.Container{container},
|
|
115
|
+ Name: names[0],
|
|
116
|
+ Alternatives: make(map[string]bool),
|
|
117
|
+ Containers: []model.Container{container},
|
|
118
|
+ CertActions: config.DefaultCertActions,
|
|
119
|
+ CertDestination: config.DefaultCertDestination,
|
114
|
120
|
}
|
115
|
121
|
}
|
116
|
122
|
addAlternatives(hostnames[names[0]], names[1:])
|