github.com/sbuss/deis@v1.6.1/publisher/main.go (about)

     1  package main
     2  
     3  import (
     4  	"log"
     5  	"os"
     6  	"time"
     7  
     8  	"github.com/coreos/go-etcd/etcd"
     9  	"github.com/fsouza/go-dockerclient"
    10  
    11  	"github.com/deis/deis/publisher/server"
    12  )
    13  
    14  const (
    15  	timeout time.Duration = 10 * time.Second
    16  	etcdTTL time.Duration = timeout * 2
    17  )
    18  
    19  func getopt(name, dfault string) string {
    20  	value := os.Getenv(name)
    21  	if value == "" {
    22  		value = dfault
    23  	}
    24  	return value
    25  }
    26  
    27  func main() {
    28  	endpoint := getopt("DOCKER_HOST", "unix:///var/run/docker.sock")
    29  	etcdHost := getopt("ETCD_HOST", "127.0.0.1")
    30  
    31  	client, err := docker.NewClient(endpoint)
    32  	if err != nil {
    33  		log.Fatal(err)
    34  	}
    35  	etcdClient := etcd.NewClient([]string{"http://" + etcdHost + ":4001"})
    36  
    37  	server := &server.Server{DockerClient: client, EtcdClient: etcdClient}
    38  
    39  	go server.Listen(etcdTTL)
    40  
    41  	for {
    42  		go server.Poll(etcdTTL)
    43  		time.Sleep(timeout)
    44  	}
    45  }