Skip to content

Commit 1b19990

Browse files
committed
Some nits and remove the volume paths
- Seems like the `Volumes` syntax is to create an anonymous volume, https://stackoverflow.com/a/58916037/796832 - And lots of people not knowing what `Volumes` syntax is or what to do. Seems like Mounts is the thing to use - fsouza/go-dockerclient#155 - https://stackoverflow.com/questions/55718603/golang-docker-library-mounting-host-directory-volumes - https://stackoverflow.com/questions/48470194/defining-a-mount-point-for-volumes-in-golang-docker-sdk
1 parent 12e6ec0 commit 1b19990

File tree

3 files changed

+28
-41
lines changed

3 files changed

+28
-41
lines changed

build/scripts/find-lint.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ if [ ${1:-""} = "fast" ]
1919
then args="--fast"
2020
fi
2121

22-
if [[ -v COMPLEMENT_LINT_CONCURRENCY ]]; then
22+
if [ -z ${COMPLEMENT_LINT_CONCURRENCY+x} ]; then
23+
# COMPLEMENT_LINT_CONCURRENCY was not set
24+
:
25+
else
2326
args="${args} --concurrency $COMPLEMENT_LINT_CONCURRENCY"
2427
fi
2528

internal/b/blueprints.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import (
2020
"fmt"
2121
"strconv"
2222
"strings"
23-
24-
"github.com/sirupsen/logrus"
2523
)
2624

2725
// KnownBlueprints lists static blueprints
@@ -133,10 +131,6 @@ func Validate(bp Blueprint) (Blueprint, error) {
133131
}
134132
}
135133

136-
logrus.WithFields(logrus.Fields{
137-
"bp": bp.Homeservers[0].ApplicationServices,
138-
}).Error("after modfiying bp")
139-
140134
return bp, nil
141135
}
142136

internal/docker/builder.go

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -347,29 +347,27 @@ func (d *Builder) deployBaseImage(blueprintName string, hs b.Homeserver, context
347347
}
348348

349349
// 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) {
354352
if os.Getenv("CI") == "true" {
355353
// When in CI, Complement itself is a container with the CA volume mounted at /ca.
356354
// We need to mount this volume to all homeserver containers to synchronize the CA cert.
357355
// This is needed to establish trust among all containers.
358356

359357
// 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>
361359
cpuset, err := ioutil.ReadFile("/proc/1/cpuset")
362360
if err != nil {
363-
return caVolume, caMount, err
361+
return caMount, err
364362
}
365363
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")
367365
}
368366
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)
371369
if err != nil {
372-
return caVolume, caMount, err
370+
return caMount, err
373371
}
374372
// Get the volume that matches the destination in our complement container
375373
var volumeName string
@@ -382,27 +380,26 @@ func getCaVolume(docker *client.Client, ctx context.Context) (string, mount.Moun
382380
// We did not find a volume. This container might be created without a volume,
383381
// or CI=true is passed but we are not running in a container.
384382
// 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",
393390
}
394391
} else {
395392
// When not in CI, our CA cert is placed in the current working dir.
396393
// We bind mount this directory to all homeserver containers.
397394
cwd, err := os.Getwd()
398395
if err != nil {
399-
return caVolume, caMount, err
396+
return caMount, err
400397
}
401398
caCertificateDirHost := path.Join(cwd, "ca")
402399
if _, err := os.Stat(caCertificateDirHost); os.IsNotExist(err) {
403400
err = os.Mkdir(caCertificateDirHost, 0770)
404401
if err != nil {
405-
return caVolume, caMount, err
402+
return caMount, err
406403
}
407404
}
408405

@@ -412,25 +409,23 @@ func getCaVolume(docker *client.Client, ctx context.Context) (string, mount.Moun
412409
Target: "/ca",
413410
}
414411
}
415-
return caVolume, caMount, nil
412+
return caMount, nil
416413
}
417414

418415
// getAppServiceVolume returns the correct mounts and volumes for providing the `/appservice` directory to homeserver containers
419416
// 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) {
421418
asVolume, err := docker.VolumeCreate(context.Background(), volume.VolumesCreateBody{
422-
//Driver: "overlay2",
423-
DriverOpts: map[string]string{},
424-
Name: "appservices",
419+
Name: "appservices",
425420
})
426421

427-
asMount := mount.Mount{
422+
asMount = mount.Mount{
428423
Type: mount.TypeVolume,
429424
Source: asVolume.Name,
430425
Target: "/appservices",
431426
}
432427

433-
return "/appservices", asMount, err
428+
return asMount, err
434429
}
435430

436431
func generateASRegistrationYaml(as b.ApplicationService) string {
@@ -451,7 +446,6 @@ func deployImage(
451446
) (*HomeserverDeployment, error) {
452447
ctx := context.Background()
453448
var extraHosts []string
454-
var volumes = make(map[string]struct{})
455449
var mounts []mount.Mount
456450
var err error
457451

@@ -463,22 +457,19 @@ func deployImage(
463457
}
464458

465459
if os.Getenv("COMPLEMENT_CA") == "true" {
466-
var caVolume string
467460
var caMount mount.Mount
468-
caVolume, caMount, err = getCaVolume(docker, ctx)
461+
caMount, err = getCaVolume(ctx, docker)
469462
if err != nil {
470463
return nil, err
471464
}
472465

473-
volumes[caVolume] = struct{}{}
474466
mounts = append(mounts, caMount)
475467
}
476468

477-
asVolume, asMount, err := getAppServiceVolume(docker, ctx)
469+
asMount, err := getAppServiceVolume(ctx, docker)
478470
if err != nil {
479471
return nil, err
480472
}
481-
volumes[asVolume] = struct{}{}
482473
mounts = append(mounts, asMount)
483474

484475
env := []string{
@@ -495,7 +486,6 @@ func deployImage(
495486
"complement_blueprint": blueprintName,
496487
"complement_hs_name": hsName,
497488
},
498-
Volumes: volumes,
499489
}, &container.HostConfig{
500490
PublishAllPorts: true,
501491
ExtraHosts: extraHosts,

0 commit comments

Comments
 (0)