Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 31 additions & 25 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,34 @@ type (
}

Agent struct {
Token string
Image string `default:"drone/drone-runner-docker:1"`
Concurrency int `default:"2"`
OS string `default:"linux"`
Arch string `default:"amd64"`
Version string
Kernel string
EnvironFile string `envconfig:"DRONE_AGENT_ENV_FILE"`
Environ []string
Volumes []string
Ports []string `envconfig:"DRONE_AGENT_PUBLISHED_PORTS"`
Labels map[string]string `envconfig:"DRONE_AGENT_LABELS"`
NamePrefix string `envconfig:"DRONE_AGENT_NAME_PREFIX" default:"agent-"`
Token string
Image string `default:"drone/drone-runner-docker:1"`
Concurrency int `default:"2"`
OS string `default:"linux"`
Arch string `default:"amd64"`
Version string
Kernel string
EnvironFile string `envconfig:"DRONE_AGENT_ENV_FILE"`
Environ []string
Volumes []string
Ports []string `envconfig:"DRONE_AGENT_PUBLISHED_PORTS"`
Labels map[string]string `envconfig:"DRONE_AGENT_LABELS"`
NamePrefix string `envconfig:"DRONE_AGENT_NAME_PREFIX" default:"agent-"`
LoggingDriver string `envconfig:"DRONE_AGENT_LOGGING_DRIVER"`
LoggingOptions map[string]string `envconfig:"DRONE_AGENT_LOGGING_OPTIONS"`
}

Runner Runner

GC struct {
Enabled bool `envconfig:"DRONE_GC_ENABLED"`
Image string `envconfig:"DRONE_GC_IMAGE" default:"drone/gc"`
Debug bool `envconfig:"DRONE_GC_DEBUG"`
Images []string `envconfig:"DRONE_GC_IGNORE_IMAGES"`
Interval time.Duration `envconfig:"DRONE_GC_INTERVAL" default:"30m"`
Cache string `envconfig:"DRONE_GC_CACHE" default:"10gb"`
Enabled bool `envconfig:"DRONE_GC_ENABLED"`
Image string `envconfig:"DRONE_GC_IMAGE" default:"drone/gc"`
Debug bool `envconfig:"DRONE_GC_DEBUG"`
Images []string `envconfig:"DRONE_GC_IGNORE_IMAGES"`
Interval time.Duration `envconfig:"DRONE_GC_INTERVAL" default:"30m"`
Cache string `envconfig:"DRONE_GC_CACHE" default:"10gb"`
LoggingDriver string `envconfig:"DRONE_GC_LOGGING_DRIVER"`
LoggingOptions map[string]string `envconfig:"DRONE_GC_LOGGING_OPTIONS"`
}

Reaper struct {
Expand All @@ -86,12 +90,14 @@ type (
}

Watchtower struct {
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"`
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"`
LoggingDriver string `envconfig:"DRONE_WATCHTOWER_LOGGING_DRIVER"`
LoggingOptions map[string]string `envconfig:"DRONE_WATCHTOWER_LOGGING_OPTIONS"`
}

HTTP struct {
Expand Down
2 changes: 1 addition & 1 deletion engine/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/drone/autoscaler"
)

// clientFunc defines a builder funciton used to build and return
// clientFunc defines a builder function used to build and return
// the docker client from a Server. This is primarily used for
// mock unit testing.
type clientFunc func(*autoscaler.Server) (docker.APIClient, io.Closer, error)
Expand Down
6 changes: 6 additions & 0 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func New(
volumes: config.Agent.Volumes,
ports: config.Agent.Ports,
labels: config.Agent.Labels,
loggingDriver: config.Agent.LoggingDriver,
loggingOptions: config.Agent.LoggingOptions,
proto: config.Server.Proto,
host: config.Server.Host,
client: newDockerClient,
Expand All @@ -80,12 +82,16 @@ func New(
gcIgnore: config.GC.Images,
gcInterval: config.GC.Interval,
gcCache: config.GC.Cache,
gcLoggingDriver: config.GC.LoggingDriver,
gcLoggingOptions: config.GC.LoggingOptions,
watchtowerEnabled: config.Watchtower.Enabled,
watchtowerImage: config.Watchtower.Image,
watchtowerStopSignal: config.Watchtower.Signal,
watchtowerSignalEnabled: config.Watchtower.SignalEnabled,
watchtowerTimeout: config.Watchtower.Timeout,
watchtowerInterval: config.Watchtower.Interval,
watchtowerLoggingDriver: config.Watchtower.LoggingDriver,
watchtowerLoggingOptions: config.Watchtower.LoggingOptions,
},
pinger: &pinger{
servers: servers,
Expand Down
54 changes: 48 additions & 6 deletions engine/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,29 @@ type installer struct {
keepaliveTimeout time.Duration
runner config.Runner
labels map[string]string
loggingDriver string
loggingOptions map[string]string

checkInterval time.Duration
checkDeadline time.Duration

gcEnabled bool
gcDebug bool
gcImage string
gcIgnore []string
gcInterval time.Duration
gcCache string
gcEnabled bool
gcDebug bool
gcImage string
gcIgnore []string
gcInterval time.Duration
gcCache string
gcLoggingDriver string
gcLoggingOptions map[string]string

watchtowerEnabled bool
watchtowerImage string
watchtowerStopSignal string
watchtowerSignalEnabled bool
watchtowerInterval int
watchtowerTimeout time.Duration
watchtowerLoggingDriver string
watchtowerLoggingOptions map[string]string

servers autoscaler.ServerStore
metrics metrics.Collector
Expand Down Expand Up @@ -227,6 +233,10 @@ poller:
return i.errorUpdate(ctx, instance, err)
}

if i.loggingDriver == "" {
i.loggingDriver = i.getDaemonLoggingDriver(ctx, client)
}

res, err := client.ContainerCreate(ctx,
&container.Config{
Image: i.image,
Expand All @@ -252,6 +262,10 @@ poller:
RestartPolicy: container.RestartPolicy{
Name: "always",
},
LogConfig: container.LogConfig{
Type: i.loggingDriver,
Config: i.loggingOptions,
},
}, nil, "agent")

if err != nil {
Expand Down Expand Up @@ -316,6 +330,11 @@ poller:

func (i *installer) setupWatchtower(ctx context.Context, client docker.APIClient) error {
vols := []string{"/var/run/docker.sock:/var/run/docker.sock"}

if i.watchtowerLoggingDriver == "" {
i.watchtowerLoggingDriver = i.getDaemonLoggingDriver(ctx, client)
}

res, err := client.ContainerCreate(ctx,
&container.Config{
Image: i.watchtowerImage,
Expand All @@ -334,6 +353,10 @@ func (i *installer) setupWatchtower(ctx context.Context, client docker.APIClient
RestartPolicy: container.RestartPolicy{
Name: "always",
},
LogConfig: container.LogConfig{
Type: i.watchtowerLoggingDriver,
Config: i.watchtowerLoggingOptions,
},
}, nil, "watchtower")
if err != nil {
return err
Expand Down Expand Up @@ -368,6 +391,10 @@ func (i *installer) setupGarbageCollector(ctx context.Context, client docker.API
io.Copy(ioutil.Discard, rc)
rc.Close()

if i.gcLoggingDriver == "" {
i.gcLoggingDriver = i.getDaemonLoggingDriver(ctx, client)
}

res, err := client.ContainerCreate(ctx,
&container.Config{
Image: i.gcImage,
Expand All @@ -384,13 +411,28 @@ func (i *installer) setupGarbageCollector(ctx context.Context, client docker.API
RestartPolicy: container.RestartPolicy{
Name: "always",
},
LogConfig: container.LogConfig{
Type: i.gcLoggingDriver,
Config: i.gcLoggingOptions,
},
}, nil, "drone-gc")
if err != nil {
return err
}
return client.ContainerStart(ctx, res.ID, types.ContainerStartOptions{})
}

func (i *installer) getDaemonLoggingDriver(ctx context.Context, client docker.APIClient) string {
info, err := client.Info(ctx)
if err != nil {
logger.FromContext(ctx).
WithError(err).
Warnln("cannot acquire logging driver, using 'json-file'")
return "json-file"
}
return info.LoggingDriver
}

func (i *installer) errorUpdate(ctx context.Context, server *autoscaler.Server, err error) error {
if err != nil {
server.State = autoscaler.StateError
Expand Down