Skip to content

Commit 44df406

Browse files
committed
Keep specific homeserver from blueprint
Split off from #443
1 parent 53024b2 commit 44df406

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

cmd/account-snapshot/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Then run Homerunner in single-shot mode: (this will take hours or days depending
2323
```
2424
HOMERUNNER_SNAPSHOT_BLUEPRINT=blueprint.json ./homerunner
2525
```
26-
This will execute the blueprint and commit the resulting images so you can push them to docker hub/gitlab. IMPORTANT: Make sure to set `HOMERUNNER_KEEP_BLUEPRINTS=your-blueprint-name` when running homerunner subsequently or **it will clean up the image**.
26+
This will execute the blueprint and commit the resulting images so you can push them to docker hub/gitlab. IMPORTANT: Make sure to set `HOMERUNNER_KEEP_BLUEPRINTS=your-blueprint-name` (TODO: Update) when running homerunner subsequently or **it will clean up the image**.
2727

2828
#### Limitations
2929

internal/docker/builder.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,16 @@ func (d *Builder) removeImages() error {
124124
d.log("Not cleaning up image with tags: %v", img.RepoTags)
125125
continue
126126
}
127-
bprintName := img.Labels["complement_blueprint"]
127+
contextStr := img.Labels[complementLabel]
128128
keep := false
129129
for _, keepBprint := range d.Config.KeepBlueprints {
130-
if bprintName == keepBprint {
130+
if contextStr == keepBprint {
131131
keep = true
132132
break
133133
}
134134
}
135135
if keep {
136-
d.log("Keeping image created from blueprint %s", bprintName)
136+
d.log("Keeping image created from blueprint %s", contextStr)
137137
continue
138138
}
139139
_, err = d.Docker.ImageRemove(context.Background(), img.ID, types.ImageRemoveOptions{
@@ -180,17 +180,32 @@ func (d *Builder) ConstructBlueprintIfNotExist(bprint b.Blueprint) error {
180180
if err != nil {
181181
return fmt.Errorf("ConstructBlueprintIfNotExist(%s): failed to ImageList: %w", bprint.Name, err)
182182
}
183-
if len(images) == 0 {
184-
err = d.ConstructBlueprint(bprint)
183+
var missingHomeservers []b.Homeserver
184+
for _, homeserver := range bprint.Homeservers {
185+
found := false
186+
for _, image := range images {
187+
if image.Labels["complement_hs_name"] == homeserver.Name {
188+
found = true
189+
break
190+
}
191+
}
192+
193+
if !found {
194+
missingHomeservers = append(missingHomeservers, homeserver)
195+
}
196+
}
197+
198+
if len(images) < len(bprint.Homeservers) {
199+
err = d.ConstructBlueprint(bprint, missingHomeservers)
185200
if err != nil {
186201
return fmt.Errorf("ConstructBlueprintIfNotExist(%s): failed to ConstructBlueprint: %w", bprint.Name, err)
187202
}
188203
}
189204
return nil
190205
}
191206

192-
func (d *Builder) ConstructBlueprint(bprint b.Blueprint) error {
193-
errs := d.construct(bprint)
207+
func (d *Builder) ConstructBlueprint(bprint b.Blueprint, homeserversToConstruct []b.Homeserver) error {
208+
errs := d.construct(bprint, homeserversToConstruct)
194209
if len(errs) > 0 {
195210
for _, err := range errs {
196211
d.log("could not construct blueprint: %s", err)
@@ -237,7 +252,7 @@ func (d *Builder) ConstructBlueprint(bprint b.Blueprint) error {
237252
}
238253

239254
// construct all Homeservers sequentially then commits them
240-
func (d *Builder) construct(bprint b.Blueprint) (errs []error) {
255+
func (d *Builder) construct(bprint b.Blueprint, homeserversToConstruct []b.Homeserver) (errs []error) {
241256
d.log("Constructing blueprint '%s'", bprint.Name)
242257

243258
networkID, err := createNetworkIfNotExists(d.Docker, d.Config.PackageNamespace, bprint.Name)
@@ -246,8 +261,8 @@ func (d *Builder) construct(bprint b.Blueprint) (errs []error) {
246261
}
247262

248263
runner := instruction.NewRunner(bprint.Name, d.Config.BestEffort, d.Config.DebugLoggingEnabled)
249-
results := make([]result, len(bprint.Homeservers))
250-
for i, hs := range bprint.Homeservers {
264+
results := make([]result, len(homeserversToConstruct))
265+
for i, hs := range homeserversToConstruct {
251266
res := d.constructHomeserver(bprint.Name, runner, hs, networkID)
252267
if res.err != nil {
253268
errs = append(errs, res.err)

0 commit comments

Comments
 (0)