-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwatchtower.go
64 lines (56 loc) · 1.45 KB
/
watchtower.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
package main
import (
"errors"
"github.com/docker/docker/api/types/container"
"github.com/rivo/tview"
)
const (
WATCHTOWER_IMAGE_NAME = "containrrr/watchtower:latest"
)
type WatchtowerConfig struct {
Configured bool
}
func (i *WatchtowerConfig) ConfigureForm(form *tview.Form, frame *tview.Frame, app *tview.Application) {
enabled := i.Configured
form.AddCheckbox("Automatic Updates", enabled, func(checked bool) {
enabled = checked
})
form.AddButton("Save", func() {
i.Configured = enabled
returnToMenu(frame, app)
})
form.AddButton("Cancel", func() {
returnToMenu(frame, app)
})
}
func (i *WatchtowerConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Form) (string, error) {
switch kind {
case KIND_DOCKER_COMPOSE:
return `watchtower:
image: ` + WATCHTOWER_IMAGE_NAME + `
volumes:
- /var/run/docker.sock:/var/run/docker.sock
restart: always
`, nil
case KIND_DIRECTLY_CONFIGURE_DOCKER:
containerConfig := &container.Config{
Image: WATCHTOWER_IMAGE_NAME,
}
hostConfig := &container.HostConfig{
Binds: []string{
"/var/run/docker.sock:/var/run/docker.sock",
},
RestartPolicy: container.RestartPolicy{
Name: "always",
},
}
return "", createContainer("watchtower", containerConfig, hostConfig, form)
default:
return "", errors.New("unknown kind")
}
}
func (i *WatchtowerConfig) IsConfigured() bool {
return i.Configured
}
func (i *WatchtowerConfig) PostConfigure(form *tview.Form, app *tview.Application) {
}