Skip to content

Commit 0b0242d

Browse files
gloursndeloof
authored andcommitted
add dry-run support to bake build
Signed-off-by: Guillaume Lours <[email protected]>
1 parent 5a70400 commit 0b0242d

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

pkg/compose/build_bake.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"bufio"
2121
"bytes"
2222
"context"
23+
"crypto/sha1"
2324
"encoding/json"
2425
"errors"
2526
"fmt"
@@ -290,6 +291,9 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
290291

291292
logrus.Debugf("Executing bake with args: %v", args)
292293

294+
if s.dryRun {
295+
return dryRunBake(ctx, cfg), nil
296+
}
293297
cmd := exec.CommandContext(ctx, buildx.Path, args...)
294298

295299
err = s.prepareShellOut(ctx, project, cmd)
@@ -443,3 +447,30 @@ func dockerFilePath(ctxName string, dockerfile string) string {
443447
}
444448
return dockerfile
445449
}
450+
451+
func dryRunBake(ctx context.Context, cfg bakeConfig) map[string]string {
452+
w := progress.ContextWriter(ctx)
453+
bakeResponse := map[string]string{}
454+
for name, target := range cfg.Targets {
455+
dryRunUUID := fmt.Sprintf("dryRun-%x", sha1.Sum([]byte(name)))
456+
displayDryRunBuildEvent(w, name, dryRunUUID, target.Tags[0])
457+
bakeResponse[name] = dryRunUUID
458+
}
459+
for name := range bakeResponse {
460+
w.Event(progress.BuiltEvent(name))
461+
}
462+
return bakeResponse
463+
}
464+
465+
func displayDryRunBuildEvent(w progress.Writer, name string, dryRunUUID, tag string) {
466+
w.Event(progress.Event{
467+
ID: name + " ==>",
468+
Status: progress.Done,
469+
Text: fmt.Sprintf("==> writing image %s", dryRunUUID),
470+
})
471+
w.Event(progress.Event{
472+
ID: name + " ==> ==>",
473+
Status: progress.Done,
474+
Text: fmt.Sprintf(`naming to %s`, tag),
475+
})
476+
}

pkg/compose/build_buildkit.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,7 @@ func (s composeService) dryRunBuildResponse(ctx context.Context, name string, op
7070
w := progress.ContextWriter(ctx)
7171
buildResponse := map[string]*client.SolveResponse{}
7272
dryRunUUID := fmt.Sprintf("dryRun-%x", sha1.Sum([]byte(name)))
73-
w.Event(progress.Event{
74-
ID: "==>",
75-
Status: progress.Done,
76-
Text: fmt.Sprintf("==> writing image %s", dryRunUUID),
77-
})
78-
w.Event(progress.Event{
79-
ID: "==> ==>",
80-
Status: progress.Done,
81-
Text: fmt.Sprintf(`naming to %s`, options.Tags[0]),
82-
})
73+
displayDryRunBuildEvent(w, name, dryRunUUID, options.Tags[0])
8374
buildResponse[name] = &client.SolveResponse{ExporterResponse: map[string]string{
8475
"containerimage.digest": dryRunUUID,
8576
}}

0 commit comments

Comments
 (0)