@@ -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 )
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 , error ) {
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 , nil
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+ }
0 commit comments