@@ -40,21 +40,27 @@ type installer struct {
40
40
keepaliveTimeout time.Duration
41
41
runner config.Runner
42
42
labels map [string ]string
43
+ loggingDriver string
44
+ loggingOptions map [string ]string
43
45
44
46
checkInterval time.Duration
45
47
checkDeadline time.Duration
46
48
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
58
64
59
65
servers autoscaler.ServerStore
60
66
metrics metrics.Collector
@@ -216,6 +222,10 @@ poller:
216
222
mounts = nil
217
223
}
218
224
225
+ if i .loggingDriver == "" {
226
+ i .loggingDriver = i .getDaemonLoggingDriver (ctx , client )
227
+ }
228
+
219
229
res , err := client .ContainerCreate (ctx ,
220
230
& container.Config {
221
231
Image : i .image ,
@@ -239,6 +249,10 @@ poller:
239
249
RestartPolicy : container.RestartPolicy {
240
250
Name : "always" ,
241
251
},
252
+ LogConfig : container.LogConfig {
253
+ Type : i .loggingDriver ,
254
+ Config : i .loggingOptions ,
255
+ },
242
256
}, nil , "agent" )
243
257
244
258
if err != nil {
@@ -303,6 +317,11 @@ poller:
303
317
304
318
func (i * installer ) setupWatchtower (ctx context.Context , client docker.APIClient ) error {
305
319
vols := []string {"/var/run/docker.sock:/var/run/docker.sock" }
320
+
321
+ if i .watchtowerLoggingDriver == "" {
322
+ i .watchtowerLoggingDriver = i .getDaemonLoggingDriver (ctx , client )
323
+ }
324
+
306
325
res , err := client .ContainerCreate (ctx ,
307
326
& container.Config {
308
327
Image : i .watchtowerImage ,
@@ -321,6 +340,10 @@ func (i *installer) setupWatchtower(ctx context.Context, client docker.APIClient
321
340
RestartPolicy : container.RestartPolicy {
322
341
Name : "always" ,
323
342
},
343
+ LogConfig : container.LogConfig {
344
+ Type : i .watchtowerLoggingDriver ,
345
+ Config : i .watchtowerLoggingOptions ,
346
+ },
324
347
}, nil , "watchtower" )
325
348
if err != nil {
326
349
return err
@@ -355,6 +378,10 @@ func (i *installer) setupGarbageCollector(ctx context.Context, client docker.API
355
378
io .Copy (ioutil .Discard , rc )
356
379
rc .Close ()
357
380
381
+ if i .gcLoggingDriver == "" {
382
+ i .gcLoggingDriver = i .getDaemonLoggingDriver (ctx , client )
383
+ }
384
+
358
385
res , err := client .ContainerCreate (ctx ,
359
386
& container.Config {
360
387
Image : i .gcImage ,
@@ -371,13 +398,28 @@ func (i *installer) setupGarbageCollector(ctx context.Context, client docker.API
371
398
RestartPolicy : container.RestartPolicy {
372
399
Name : "always" ,
373
400
},
401
+ LogConfig : container.LogConfig {
402
+ Type : i .gcLoggingDriver ,
403
+ Config : i .gcLoggingOptions ,
404
+ },
374
405
}, nil , "drone-gc" )
375
406
if err != nil {
376
407
return err
377
408
}
378
409
return client .ContainerStart (ctx , res .ID , types.ContainerStartOptions {})
379
410
}
380
411
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
+
381
423
func (i * installer ) errorUpdate (ctx context.Context , server * autoscaler.Server , err error ) error {
382
424
if err != nil {
383
425
server .State = autoscaler .StateError
0 commit comments