From aed418cc4dc5cb733aa51e9f806846d609397e86 Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Thu, 11 Aug 2022 10:30:46 +0100 Subject: [PATCH] Extend Blueprints to permit baseImageURI to be optionally overridden for each Homeserver (#436) * Refactor method to permit baseImageURI to be passed in for each Homeserver. * Propigate error when images are unable to be constructed. This provides better messages when using homerunner API to generate new blueprints, otherwise the API only reports that no images exist. --- internal/b/blueprints.go | 2 ++ internal/docker/builder.go | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/internal/b/blueprints.go b/internal/b/blueprints.go index 365d419c..70976776 100644 --- a/internal/b/blueprints.go +++ b/internal/b/blueprints.go @@ -54,6 +54,8 @@ type Homeserver struct { Rooms []Room // The list of application services to create on the homeserver ApplicationServices []ApplicationService + // Optionally override the baseImageURI for blueprint creation + BaseImageURI *string } type User struct { diff --git a/internal/docker/builder.go b/internal/docker/builder.go index 28b5bde0..bb0c93c2 100644 --- a/internal/docker/builder.go +++ b/internal/docker/builder.go @@ -181,7 +181,10 @@ func (d *Builder) ConstructBlueprintIfNotExist(bprint b.Blueprint) error { return fmt.Errorf("ConstructBlueprintIfNotExist(%s): failed to ImageList: %w", bprint.Name, err) } if len(images) == 0 { - d.ConstructBlueprint(bprint) + err = d.ConstructBlueprint(bprint) + if err != nil { + return fmt.Errorf("ConstructBlueprintIfNotExist(%s): failed to ConstructBlueprint: %w", bprint.Name, err) + } } return nil } @@ -380,9 +383,15 @@ func (d *Builder) constructHomeserver(blueprintName string, runner *instruction. // deployBaseImage runs the base image and returns the baseURL, containerID or an error. func (d *Builder) deployBaseImage(blueprintName string, hs b.Homeserver, contextStr, networkID string) (*HomeserverDeployment, error) { asIDToRegistrationMap := asIDToRegistrationFromLabels(labelsForApplicationServices(hs)) + var baseImageURI string + if hs.BaseImageURI == nil { + baseImageURI = d.Config.BaseImageURI + } else { + baseImageURI = *hs.BaseImageURI + } return deployImage( - d.Docker, d.Config.BaseImageURI, fmt.Sprintf("complement_%s", contextStr), + d.Docker, baseImageURI, fmt.Sprintf("complement_%s", contextStr), d.Config.PackageNamespace, blueprintName, hs.Name, asIDToRegistrationMap, contextStr, networkID, d.Config, )