diff --git a/config/config.go b/config/config.go index 427e4da..95ace89 100644 --- a/config/config.go +++ b/config/config.go @@ -86,10 +86,12 @@ type ( } Watchtower struct { - Enabled bool `envconfig:"DRONE_WATCHTOWER_ENABLED"` - Image string `envconfig:"DRONE_WATCHTOWER_IMAGE" default:"webhippie/watchtower"` - Interval int `envconfig:"DRONE_WATCHTOWER_INTERVAL" default:"300"` - Timeout time.Duration `envconfig:"DRONE_WATCHTOWER_TIMEOUT" default:"120m"` + Enabled bool `envconfig:"DRONE_WATCHTOWER_ENABLED"` + SignalEnabled bool `envconfig:"DRONE_WATCHTOWER_SIGNAL_ENABLED" default:"true"` + Signal string `envconfig:"DRONE_WATCHTOWER_STOP_SIGNAL" default:"SIGHUP"` + Image string `envconfig:"DRONE_WATCHTOWER_IMAGE" default:"webhippie/watchtower"` + Interval int `envconfig:"DRONE_WATCHTOWER_INTERVAL" default:"300"` + Timeout time.Duration `envconfig:"DRONE_WATCHTOWER_TIMEOUT" default:"120m"` } HTTP struct { diff --git a/config/load_test.go b/config/load_test.go index e9aeb5c..77a05f9 100644 --- a/config/load_test.go +++ b/config/load_test.go @@ -157,6 +157,8 @@ func TestLoad(t *testing.T) { "DRONE_OPENSTACK_USERDATA": "#cloud-init", "DRONE_OPENSTACK_USERDATA_FILE": "/path/to/cloud/init.yml", "OS_REGION_NAME": "sto-01", + "DRONE_WATCHTOWER_SIGNAL_ENABLED": "false", + "DRONE_WATCHTOWER_STOP_SIGNAL": "", } defer func() { diff --git a/engine/engine.go b/engine/engine.go index 3e5b381..f32e134 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -58,32 +58,34 @@ func New( client: newDockerClient, }, installer: &installer{ - metrics: metrics, - servers: servers, - os: config.Agent.OS, - arch: config.Agent.Arch, - image: config.Agent.Image, - secret: config.Agent.Token, - envs: config.Agent.Environ, - volumes: config.Agent.Volumes, - ports: config.Agent.Ports, - labels: config.Agent.Labels, - proto: config.Server.Proto, - host: config.Server.Host, - client: newDockerClient, - runner: config.Runner, - checkInterval: config.Check.Interval, - checkDeadline: config.Check.Deadline, - gcEnabled: config.GC.Enabled, - gcDebug: config.GC.Debug, - gcImage: config.GC.Image, - gcIgnore: config.GC.Images, - gcInterval: config.GC.Interval, - gcCache: config.GC.Cache, - watchtowerEnabled: config.Watchtower.Enabled, - watchtowerImage: config.Watchtower.Image, - watchtowerTimeout: config.Watchtower.Timeout, - watchtowerInterval: config.Watchtower.Interval, + metrics: metrics, + servers: servers, + os: config.Agent.OS, + arch: config.Agent.Arch, + image: config.Agent.Image, + secret: config.Agent.Token, + envs: config.Agent.Environ, + volumes: config.Agent.Volumes, + ports: config.Agent.Ports, + labels: config.Agent.Labels, + proto: config.Server.Proto, + host: config.Server.Host, + client: newDockerClient, + runner: config.Runner, + checkInterval: config.Check.Interval, + checkDeadline: config.Check.Deadline, + gcEnabled: config.GC.Enabled, + gcDebug: config.GC.Debug, + gcImage: config.GC.Image, + gcIgnore: config.GC.Images, + gcInterval: config.GC.Interval, + gcCache: config.GC.Cache, + watchtowerEnabled: config.Watchtower.Enabled, + watchtowerImage: config.Watchtower.Image, + watchtowerStopSignal: config.Watchtower.Signal, + watchtowerSignalEnabled: config.Watchtower.SignalEnabled, + watchtowerTimeout: config.Watchtower.Timeout, + watchtowerInterval: config.Watchtower.Interval, }, pinger: &pinger{ servers: servers, diff --git a/engine/install.go b/engine/install.go index 9c1f786..b5c29b4 100644 --- a/engine/install.go +++ b/engine/install.go @@ -53,10 +53,12 @@ type installer struct { gcInterval time.Duration gcCache string - watchtowerEnabled bool - watchtowerImage string - watchtowerInterval int - watchtowerTimeout time.Duration + watchtowerEnabled bool + watchtowerImage string + watchtowerStopSignal string + watchtowerSignalEnabled bool + watchtowerInterval int + watchtowerTimeout time.Duration servers autoscaler.ServerStore metrics metrics.Collector @@ -234,8 +236,8 @@ poller: Volumes: toVol(volumes), ExposedPorts: exposedPorts, Labels: map[string]string{ - "com.centurylinklabs.watchtower.enable": "true", - "com.centurylinklabs.watchtower.stop-signal": "SIGHUP", + "com.centurylinklabs.watchtower.enable": fmt.Sprint(i.watchtowerSignalEnabled), + "com.centurylinklabs.watchtower.stop-signal": i.watchtowerStopSignal, "io.drone.agent.name": instance.Name, "io.drone.agent.zone": instance.Region, "io.drone.agent.size": instance.Size, @@ -374,7 +376,7 @@ func (i *installer) setupGarbageCollector(ctx context.Context, client docker.API Volumes: toVol(vols), Env: envs, Labels: map[string]string{ - "com.centurylinklabs.watchtower.enable": "true", + "com.centurylinklabs.watchtower.enable": fmt.Sprint(i.watchtowerSignalEnabled), }, }, &container.HostConfig{