mirror of
https://github.com/docker/compose.git
synced 2025-07-23 21:54:40 +02:00
add dry-run support to bake build
Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
parent
5a704004d3
commit
0b0242d0ac
@ -20,6 +20,7 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha1"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -290,6 +291,9 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
|
||||
|
||||
logrus.Debugf("Executing bake with args: %v", args)
|
||||
|
||||
if s.dryRun {
|
||||
return dryRunBake(ctx, cfg), nil
|
||||
}
|
||||
cmd := exec.CommandContext(ctx, buildx.Path, args...)
|
||||
|
||||
err = s.prepareShellOut(ctx, project, cmd)
|
||||
@ -443,3 +447,30 @@ func dockerFilePath(ctxName string, dockerfile string) string {
|
||||
}
|
||||
return dockerfile
|
||||
}
|
||||
|
||||
func dryRunBake(ctx context.Context, cfg bakeConfig) map[string]string {
|
||||
w := progress.ContextWriter(ctx)
|
||||
bakeResponse := map[string]string{}
|
||||
for name, target := range cfg.Targets {
|
||||
dryRunUUID := fmt.Sprintf("dryRun-%x", sha1.Sum([]byte(name)))
|
||||
displayDryRunBuildEvent(w, name, dryRunUUID, target.Tags[0])
|
||||
bakeResponse[name] = dryRunUUID
|
||||
}
|
||||
for name := range bakeResponse {
|
||||
w.Event(progress.BuiltEvent(name))
|
||||
}
|
||||
return bakeResponse
|
||||
}
|
||||
|
||||
func displayDryRunBuildEvent(w progress.Writer, name string, dryRunUUID, tag string) {
|
||||
w.Event(progress.Event{
|
||||
ID: name + " ==>",
|
||||
Status: progress.Done,
|
||||
Text: fmt.Sprintf("==> writing image %s", dryRunUUID),
|
||||
})
|
||||
w.Event(progress.Event{
|
||||
ID: name + " ==> ==>",
|
||||
Status: progress.Done,
|
||||
Text: fmt.Sprintf(`naming to %s`, tag),
|
||||
})
|
||||
}
|
||||
|
@ -70,16 +70,7 @@ func (s composeService) dryRunBuildResponse(ctx context.Context, name string, op
|
||||
w := progress.ContextWriter(ctx)
|
||||
buildResponse := map[string]*client.SolveResponse{}
|
||||
dryRunUUID := fmt.Sprintf("dryRun-%x", sha1.Sum([]byte(name)))
|
||||
w.Event(progress.Event{
|
||||
ID: "==>",
|
||||
Status: progress.Done,
|
||||
Text: fmt.Sprintf("==> writing image %s", dryRunUUID),
|
||||
})
|
||||
w.Event(progress.Event{
|
||||
ID: "==> ==>",
|
||||
Status: progress.Done,
|
||||
Text: fmt.Sprintf(`naming to %s`, options.Tags[0]),
|
||||
})
|
||||
displayDryRunBuildEvent(w, name, dryRunUUID, options.Tags[0])
|
||||
buildResponse[name] = &client.SolveResponse{ExporterResponse: map[string]string{
|
||||
"containerimage.digest": dryRunUUID,
|
||||
}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user