Skip to content

Commit

Permalink
fix: [CI-7241]: Support configurable watchtower(#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
smjt-h authored Oct 6, 2023
1 parent 79082b3 commit 9cec5e7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 37 deletions.
10 changes: 6 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
54 changes: 28 additions & 26 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 9 additions & 7 deletions engine/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 9cec5e7

Please sign in to comment.