@@ -40,21 +40,27 @@ type installer struct {
4040 keepaliveTimeout time.Duration
4141 runner config.Runner
4242 labels map [string ]string
43+ loggingDriver string
44+ loggingOptions map [string ]string
4345
4446 checkInterval time.Duration
4547 checkDeadline time.Duration
4648
47- gcEnabled bool
48- gcDebug bool
49- gcImage string
50- gcIgnore []string
51- gcInterval time.Duration
52- gcCache string
53-
54- watchtowerEnabled bool
55- watchtowerImage string
56- watchtowerInterval int
57- watchtowerTimeout time.Duration
49+ gcEnabled bool
50+ gcDebug bool
51+ gcImage string
52+ gcIgnore []string
53+ gcInterval time.Duration
54+ gcCache string
55+ gcLoggingDriver string
56+ gcLoggingOptions map [string ]string
57+
58+ watchtowerEnabled bool
59+ watchtowerImage string
60+ watchtowerInterval int
61+ watchtowerTimeout time.Duration
62+ watchtowerLoggingDriver string
63+ watchtowerLoggingOptions map [string ]string
5864
5965 servers autoscaler.ServerStore
6066 metrics metrics.Collector
@@ -216,6 +222,10 @@ poller:
216222 mounts = nil
217223 }
218224
225+ if i .loggingDriver == "" {
226+ i .loggingDriver = i .getDaemonLoggingDriver (ctx , client )
227+ }
228+
219229 res , err := client .ContainerCreate (ctx ,
220230 & container.Config {
221231 Image : i .image ,
@@ -239,6 +249,10 @@ poller:
239249 RestartPolicy : container.RestartPolicy {
240250 Name : "always" ,
241251 },
252+ LogConfig : container.LogConfig {
253+ Type : i .loggingDriver ,
254+ Config : i .loggingOptions ,
255+ },
242256 }, nil , "agent" )
243257
244258 if err != nil {
@@ -303,6 +317,11 @@ poller:
303317
304318func (i * installer ) setupWatchtower (ctx context.Context , client docker.APIClient ) error {
305319 vols := []string {"/var/run/docker.sock:/var/run/docker.sock" }
320+
321+ if i .watchtowerLoggingDriver == "" {
322+ i .watchtowerLoggingDriver = i .getDaemonLoggingDriver (ctx , client )
323+ }
324+
306325 res , err := client .ContainerCreate (ctx ,
307326 & container.Config {
308327 Image : i .watchtowerImage ,
@@ -321,6 +340,10 @@ func (i *installer) setupWatchtower(ctx context.Context, client docker.APIClient
321340 RestartPolicy : container.RestartPolicy {
322341 Name : "always" ,
323342 },
343+ LogConfig : container.LogConfig {
344+ Type : i .watchtowerLoggingDriver ,
345+ Config : i .watchtowerLoggingOptions ,
346+ },
324347 }, nil , "watchtower" )
325348 if err != nil {
326349 return err
@@ -355,6 +378,10 @@ func (i *installer) setupGarbageCollector(ctx context.Context, client docker.API
355378 io .Copy (ioutil .Discard , rc )
356379 rc .Close ()
357380
381+ if i .gcLoggingDriver == "" {
382+ i .gcLoggingDriver = i .getDaemonLoggingDriver (ctx , client )
383+ }
384+
358385 res , err := client .ContainerCreate (ctx ,
359386 & container.Config {
360387 Image : i .gcImage ,
@@ -371,13 +398,28 @@ func (i *installer) setupGarbageCollector(ctx context.Context, client docker.API
371398 RestartPolicy : container.RestartPolicy {
372399 Name : "always" ,
373400 },
401+ LogConfig : container.LogConfig {
402+ Type : i .gcLoggingDriver ,
403+ Config : i .gcLoggingOptions ,
404+ },
374405 }, nil , "drone-gc" )
375406 if err != nil {
376407 return err
377408 }
378409 return client .ContainerStart (ctx , res .ID , types.ContainerStartOptions {})
379410}
380411
412+ func (i * installer ) getDaemonLoggingDriver (ctx context.Context , client docker.APIClient ) string {
413+ info , err := client .Info (ctx )
414+ if err != nil {
415+ logger .FromContext (ctx ).
416+ WithError (err ).
417+ Warnln ("cannot acquire logging driver, using 'json-file'" )
418+ return "json-file"
419+ }
420+ return info .LoggingDriver
421+ }
422+
381423func (i * installer ) errorUpdate (ctx context.Context , server * autoscaler.Server , err error ) error {
382424 if err != nil {
383425 server .State = autoscaler .StateError
0 commit comments