mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-21 21:30:48 +02:00
Allow user-configurable DOCKER_HOST
This commit is contained in:
parent
00f2875abf
commit
4ba21639a0
10 changed files with 202 additions and 35 deletions
18
main.go
18
main.go
|
@ -9,6 +9,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/CenturyLinkLabs/watchtower/actions"
|
||||
"github.com/CenturyLinkLabs/watchtower/container"
|
||||
"github.com/codegangsta/cli"
|
||||
)
|
||||
|
||||
|
@ -23,6 +24,12 @@ func main() {
|
|||
app.Before = before
|
||||
app.Action = start
|
||||
app.Flags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "host, H",
|
||||
Value: "unix:///var/run/docker.sock",
|
||||
Usage: "Docker daemon socket to connect to",
|
||||
EnvVar: "DOCKER_HOST",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "interval, i",
|
||||
Value: 300,
|
||||
|
@ -48,15 +55,17 @@ func handleSignals() {
|
|||
}
|
||||
|
||||
func before(c *cli.Context) error {
|
||||
return actions.CheckPrereqs()
|
||||
client := newContainerClient(c)
|
||||
return actions.CheckPrereqs(client)
|
||||
}
|
||||
|
||||
func start(c *cli.Context) {
|
||||
client := newContainerClient(c)
|
||||
secs := time.Duration(c.Int("interval")) * time.Second
|
||||
|
||||
for {
|
||||
wg.Add(1)
|
||||
if err := actions.Update(); err != nil {
|
||||
if err := actions.Update(client); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
wg.Done()
|
||||
|
@ -64,3 +73,8 @@ func start(c *cli.Context) {
|
|||
time.Sleep(secs)
|
||||
}
|
||||
}
|
||||
|
||||
func newContainerClient(c *cli.Context) container.Client {
|
||||
dockerHost := c.GlobalString("host")
|
||||
return container.NewClient(dockerHost)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue