@@ -347,29 +347,27 @@ func (d *Builder) deployBaseImage(blueprintName string, hs b.Homeserver, context
347
347
}
348
348
349
349
// getCaVolume returns the correct mounts and volumes for providing a CA to homeserver containers.
350
- func getCaVolume (docker * client.Client , ctx context.Context ) (string , mount.Mount , error ) {
351
- var caVolume string
352
- var caMount mount.Mount
353
-
350
+ // Returns the
351
+ func getCaVolume (ctx context.Context , docker * client.Client ) (caMount mount.Mount , err error ) {
354
352
if os .Getenv ("CI" ) == "true" {
355
353
// When in CI, Complement itself is a container with the CA volume mounted at /ca.
356
354
// We need to mount this volume to all homeserver containers to synchronize the CA cert.
357
355
// This is needed to establish trust among all containers.
358
356
359
357
// Get volume mounted at /ca. First we get the container ID
360
- // /proc/1/cpuset should be /docker/<containerId >
358
+ // /proc/1/cpuset should be /docker/<containerID >
361
359
cpuset , err := ioutil .ReadFile ("/proc/1/cpuset" )
362
360
if err != nil {
363
- return caVolume , caMount , err
361
+ return caMount , err
364
362
}
365
363
if ! strings .Contains (string (cpuset ), "docker" ) {
366
- return caVolume , caMount , errors .New ("Could not identify container ID using /proc/1/cpuset" )
364
+ return caMount , errors .New ("Could not identify container ID using /proc/1/cpuset" )
367
365
}
368
366
cpusetList := strings .Split (strings .TrimSpace (string (cpuset )), "/" )
369
- containerId := cpusetList [len (cpusetList )- 1 ]
370
- container , err := docker .ContainerInspect (ctx , containerId )
367
+ containerID := cpusetList [len (cpusetList )- 1 ]
368
+ container , err := docker .ContainerInspect (ctx , containerID )
371
369
if err != nil {
372
- return caVolume , caMount , err
370
+ return caMount , err
373
371
}
374
372
// Get the volume that matches the destination in our complement container
375
373
var volumeName string
@@ -382,27 +380,26 @@ func getCaVolume(docker *client.Client, ctx context.Context) (string, mount.Moun
382
380
// We did not find a volume. This container might be created without a volume,
383
381
// or CI=true is passed but we are not running in a container.
384
382
// todo: log that we do not provide a CA volume mount?
385
- return caVolume , caMount , nil
386
- } else {
387
- caVolume = "/ca"
388
- caMount = mount.Mount {
389
- Type : mount .TypeVolume ,
390
- Source : volumeName ,
391
- Target : "/ca" ,
392
- }
383
+ return caMount , nil
384
+ }
385
+
386
+ caMount = mount.Mount {
387
+ Type : mount .TypeVolume ,
388
+ Source : volumeName ,
389
+ Target : "/ca" ,
393
390
}
394
391
} else {
395
392
// When not in CI, our CA cert is placed in the current working dir.
396
393
// We bind mount this directory to all homeserver containers.
397
394
cwd , err := os .Getwd ()
398
395
if err != nil {
399
- return caVolume , caMount , err
396
+ return caMount , err
400
397
}
401
398
caCertificateDirHost := path .Join (cwd , "ca" )
402
399
if _ , err := os .Stat (caCertificateDirHost ); os .IsNotExist (err ) {
403
400
err = os .Mkdir (caCertificateDirHost , 0770 )
404
401
if err != nil {
405
- return caVolume , caMount , err
402
+ return caMount , err
406
403
}
407
404
}
408
405
@@ -412,25 +409,23 @@ func getCaVolume(docker *client.Client, ctx context.Context) (string, mount.Moun
412
409
Target : "/ca" ,
413
410
}
414
411
}
415
- return caVolume , caMount , nil
412
+ return caMount , nil
416
413
}
417
414
418
415
// getAppServiceVolume returns the correct mounts and volumes for providing the `/appservice` directory to homeserver containers
419
416
// containing application service registration files to be used by the homeserver
420
- func getAppServiceVolume (docker * client. Client , ctx context. Context ) (string , mount.Mount , error ) {
417
+ func getAppServiceVolume (ctx context. Context , docker * client. Client ) (asMount mount.Mount , err error ) {
421
418
asVolume , err := docker .VolumeCreate (context .Background (), volume.VolumesCreateBody {
422
- //Driver: "overlay2",
423
- DriverOpts : map [string ]string {},
424
- Name : "appservices" ,
419
+ Name : "appservices" ,
425
420
})
426
421
427
- asMount : = mount.Mount {
422
+ asMount = mount.Mount {
428
423
Type : mount .TypeVolume ,
429
424
Source : asVolume .Name ,
430
425
Target : "/appservices" ,
431
426
}
432
427
433
- return "/appservices" , asMount , err
428
+ return asMount , err
434
429
}
435
430
436
431
func generateASRegistrationYaml (as b.ApplicationService ) string {
@@ -451,7 +446,6 @@ func deployImage(
451
446
) (* HomeserverDeployment , error ) {
452
447
ctx := context .Background ()
453
448
var extraHosts []string
454
- var volumes = make (map [string ]struct {})
455
449
var mounts []mount.Mount
456
450
var err error
457
451
@@ -463,22 +457,19 @@ func deployImage(
463
457
}
464
458
465
459
if os .Getenv ("COMPLEMENT_CA" ) == "true" {
466
- var caVolume string
467
460
var caMount mount.Mount
468
- caVolume , caMount , err = getCaVolume (docker , ctx )
461
+ caMount , err = getCaVolume (ctx , docker )
469
462
if err != nil {
470
463
return nil , err
471
464
}
472
465
473
- volumes [caVolume ] = struct {}{}
474
466
mounts = append (mounts , caMount )
475
467
}
476
468
477
- asVolume , asMount , err := getAppServiceVolume (docker , ctx )
469
+ asMount , err := getAppServiceVolume (ctx , docker )
478
470
if err != nil {
479
471
return nil , err
480
472
}
481
- volumes [asVolume ] = struct {}{}
482
473
mounts = append (mounts , asMount )
483
474
484
475
env := []string {
@@ -495,7 +486,6 @@ func deployImage(
495
486
"complement_blueprint" : blueprintName ,
496
487
"complement_hs_name" : hsName ,
497
488
},
498
- Volumes : volumes ,
499
489
}, & container.HostConfig {
500
490
PublishAllPorts : true ,
501
491
ExtraHosts : extraHosts ,
0 commit comments