forked from Budry/docker-subreg-dns-updater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (43 loc) · 996 Bytes
/
main.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
package main
import (
"context"
"fmt"
"log"
"os"
"docker.io/go-docker"
"docker.io/go-docker/api/types"
"github.com/Budry/docker-subreg-dns-updater/ip"
"github.com/Budry/docker-subreg-dns-updater/subreg"
"github.com/Budry/docker-subreg-dns-updater/utils"
)
func main() {
service := subreg.NewSubregCz("", false, &subreg.BasicAuth{})
publicIp, err := ip.GetPublicIp()
if err != nil {
log.Fatalln(err)
}
dnsManager := subreg.DNSManager{
Ip: publicIp,
Client: service,
}
ctx := context.Background()
cli, err := docker.NewEnvClient()
if err != nil {
panic(err)
}
result, _ := cli.Events(ctx, types.EventsOptions{})
for {
message := <-result
if message.Action == "create" {
inspect, err := cli.ContainerInspect(ctx, message.ID)
if err != nil {
continue
}
envMap := utils.SplitKeyValueSlice(inspect.Config.Env)
err = dnsManager.Update(envMap["VIRTUAL_HOST"])
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
}
}
}
}