-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (35 loc) · 789 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
package main
import (
"log"
"os"
"time"
"github.com/coreos/go-etcd/etcd"
"github.com/fsouza/go-dockerclient"
"github.com/deis/deis/publisher/server"
)
const (
timeout time.Duration = 10 * time.Second
etcdTTL time.Duration = timeout * 2
)
func getopt(name, dfault string) string {
value := os.Getenv(name)
if value == "" {
value = dfault
}
return value
}
func main() {
endpoint := getopt("DOCKER_HOST", "unix:///var/run/docker.sock")
etcdHost := getopt("ETCD_HOST", "127.0.0.1")
client, err := docker.NewClient(endpoint)
if err != nil {
log.Fatal(err)
}
etcdClient := etcd.NewClient([]string{"http://" + etcdHost + ":4001"})
server := &server.Server{client, etcdClient}
go server.Listen(etcdTTL)
for {
go server.Poll(etcdTTL)
time.Sleep(timeout)
}
}