@@ -20,6 +20,7 @@ import (
20
20
"bufio"
21
21
"bytes"
22
22
"context"
23
+ "crypto/sha1"
23
24
"encoding/json"
24
25
"errors"
25
26
"fmt"
@@ -290,6 +291,9 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
290
291
291
292
logrus .Debugf ("Executing bake with args: %v" , args )
292
293
294
+ if s .dryRun {
295
+ return dryRunBake (ctx , cfg ), nil
296
+ }
293
297
cmd := exec .CommandContext (ctx , buildx .Path , args ... )
294
298
295
299
err = s .prepareShellOut (ctx , project , cmd )
@@ -443,3 +447,30 @@ func dockerFilePath(ctxName string, dockerfile string) string {
443
447
}
444
448
return dockerfile
445
449
}
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
+ }
0 commit comments