@@ -42,21 +42,27 @@ type installer struct {
42
42
keepaliveTimeout time.Duration
43
43
runner config.Runner
44
44
labels map [string ]string
45
+ loggingDriver string
46
+ loggingOptions map [string ]string
45
47
46
48
checkInterval time.Duration
47
49
checkDeadline time.Duration
48
50
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
60
66
61
67
servers autoscaler.ServerStore
62
68
metrics metrics.Collector
@@ -225,6 +231,10 @@ poller:
225
231
return i .errorUpdate (ctx , instance , err )
226
232
}
227
233
234
+ if i .loggingDriver == "" {
235
+ i .loggingDriver = i .getDaemonLoggingDriver (ctx , client )
236
+ }
237
+
228
238
res , err := client .ContainerCreate (ctx ,
229
239
& container.Config {
230
240
Image : i .image ,
@@ -250,6 +260,10 @@ poller:
250
260
RestartPolicy : container.RestartPolicy {
251
261
Name : "always" ,
252
262
},
263
+ LogConfig : container.LogConfig {
264
+ Type : i .loggingDriver ,
265
+ Config : i .loggingOptions ,
266
+ },
253
267
}, nil , "agent" )
254
268
255
269
if err != nil {
@@ -314,6 +328,11 @@ poller:
314
328
315
329
func (i * installer ) setupWatchtower (ctx context.Context , client docker.APIClient ) error {
316
330
vols := []string {"/var/run/docker.sock:/var/run/docker.sock" }
331
+
332
+ if i .watchtowerLoggingDriver == "" {
333
+ i .watchtowerLoggingDriver = i .getDaemonLoggingDriver (ctx , client )
334
+ }
335
+
317
336
res , err := client .ContainerCreate (ctx ,
318
337
& container.Config {
319
338
Image : i .watchtowerImage ,
@@ -332,6 +351,10 @@ func (i *installer) setupWatchtower(ctx context.Context, client docker.APIClient
332
351
RestartPolicy : container.RestartPolicy {
333
352
Name : "always" ,
334
353
},
354
+ LogConfig : container.LogConfig {
355
+ Type : i .watchtowerLoggingDriver ,
356
+ Config : i .watchtowerLoggingOptions ,
357
+ },
335
358
}, nil , "watchtower" )
336
359
if err != nil {
337
360
return err
@@ -366,6 +389,10 @@ func (i *installer) setupGarbageCollector(ctx context.Context, client docker.API
366
389
io .Copy (ioutil .Discard , rc )
367
390
rc .Close ()
368
391
392
+ if i .gcLoggingDriver == "" {
393
+ i .gcLoggingDriver = i .getDaemonLoggingDriver (ctx , client )
394
+ }
395
+
369
396
res , err := client .ContainerCreate (ctx ,
370
397
& container.Config {
371
398
Image : i .gcImage ,
@@ -382,13 +409,28 @@ func (i *installer) setupGarbageCollector(ctx context.Context, client docker.API
382
409
RestartPolicy : container.RestartPolicy {
383
410
Name : "always" ,
384
411
},
412
+ LogConfig : container.LogConfig {
413
+ Type : i .gcLoggingDriver ,
414
+ Config : i .gcLoggingOptions ,
415
+ },
385
416
}, nil , "drone-gc" )
386
417
if err != nil {
387
418
return err
388
419
}
389
420
return client .ContainerStart (ctx , res .ID , types.ContainerStartOptions {})
390
421
}
391
422
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
+
392
434
func (i * installer ) errorUpdate (ctx context.Context , server * autoscaler.Server , err error ) error {
393
435
if err != nil {
394
436
server .State = autoscaler .StateError
0 commit comments