@@ -42,21 +42,27 @@ type installer struct {
4242 keepaliveTimeout time.Duration
4343 runner config.Runner
4444 labels map [string ]string
45+ loggingDriver string
46+ loggingOptions map [string ]string
4547
4648 checkInterval time.Duration
4749 checkDeadline time.Duration
4850
49- gcEnabled bool
50- gcDebug bool
51- gcImage string
52- gcIgnore []string
53- gcInterval time.Duration
54- gcCache string
55-
56- watchtowerEnabled bool
57- watchtowerImage string
58- watchtowerInterval int
59- watchtowerTimeout time.Duration
51+ gcEnabled bool
52+ gcDebug bool
53+ gcImage string
54+ gcIgnore []string
55+ gcInterval time.Duration
56+ gcCache string
57+ gcLoggingDriver string
58+ gcLoggingOptions map [string ]string
59+
60+ watchtowerEnabled bool
61+ watchtowerImage string
62+ watchtowerInterval int
63+ watchtowerTimeout time.Duration
64+ watchtowerLoggingDriver string
65+ watchtowerLoggingOptions map [string ]string
6066
6167 servers autoscaler.ServerStore
6268 metrics metrics.Collector
@@ -225,6 +231,10 @@ poller:
225231 return i .errorUpdate (ctx , instance , err )
226232 }
227233
234+ if i .loggingDriver == "" {
235+ i .loggingDriver = i .getDaemonLoggingDriver (ctx , client )
236+ }
237+
228238 res , err := client .ContainerCreate (ctx ,
229239 & container.Config {
230240 Image : i .image ,
@@ -250,6 +260,10 @@ poller:
250260 RestartPolicy : container.RestartPolicy {
251261 Name : "always" ,
252262 },
263+ LogConfig : container.LogConfig {
264+ Type : i .loggingDriver ,
265+ Config : i .loggingOptions ,
266+ },
253267 }, nil , "agent" )
254268
255269 if err != nil {
@@ -314,6 +328,11 @@ poller:
314328
315329func (i * installer ) setupWatchtower (ctx context.Context , client docker.APIClient ) error {
316330 vols := []string {"/var/run/docker.sock:/var/run/docker.sock" }
331+
332+ if i .watchtowerLoggingDriver == "" {
333+ i .watchtowerLoggingDriver = i .getDaemonLoggingDriver (ctx , client )
334+ }
335+
317336 res , err := client .ContainerCreate (ctx ,
318337 & container.Config {
319338 Image : i .watchtowerImage ,
@@ -332,6 +351,10 @@ func (i *installer) setupWatchtower(ctx context.Context, client docker.APIClient
332351 RestartPolicy : container.RestartPolicy {
333352 Name : "always" ,
334353 },
354+ LogConfig : container.LogConfig {
355+ Type : i .watchtowerLoggingDriver ,
356+ Config : i .watchtowerLoggingOptions ,
357+ },
335358 }, nil , "watchtower" )
336359 if err != nil {
337360 return err
@@ -366,6 +389,10 @@ func (i *installer) setupGarbageCollector(ctx context.Context, client docker.API
366389 io .Copy (ioutil .Discard , rc )
367390 rc .Close ()
368391
392+ if i .gcLoggingDriver == "" {
393+ i .gcLoggingDriver = i .getDaemonLoggingDriver (ctx , client )
394+ }
395+
369396 res , err := client .ContainerCreate (ctx ,
370397 & container.Config {
371398 Image : i .gcImage ,
@@ -382,13 +409,28 @@ func (i *installer) setupGarbageCollector(ctx context.Context, client docker.API
382409 RestartPolicy : container.RestartPolicy {
383410 Name : "always" ,
384411 },
412+ LogConfig : container.LogConfig {
413+ Type : i .gcLoggingDriver ,
414+ Config : i .gcLoggingOptions ,
415+ },
385416 }, nil , "drone-gc" )
386417 if err != nil {
387418 return err
388419 }
389420 return client .ContainerStart (ctx , res .ID , types.ContainerStartOptions {})
390421}
391422
423+ func (i * installer ) getDaemonLoggingDriver (ctx context.Context , client docker.APIClient ) string {
424+ info , err := client .Info (ctx )
425+ if err != nil {
426+ logger .FromContext (ctx ).
427+ WithError (err ).
428+ Warnln ("cannot acquire logging driver, using 'json-file'" )
429+ return "json-file"
430+ }
431+ return info .LoggingDriver
432+ }
433+
392434func (i * installer ) errorUpdate (ctx context.Context , server * autoscaler.Server , err error ) error {
393435 if err != nil {
394436 server .State = autoscaler .StateError
0 commit comments