@@ -119,11 +119,11 @@ func Run(ctx context.Context, options Options) error {
119
119
options .WorkspaceFolder = f
120
120
}
121
121
122
- stageNumber := 1
122
+ stageNumber := 0
123
123
startStage := func (format string , args ... any ) func (format string , args ... any ) {
124
124
now := time .Now ()
125
- stageNum := stageNumber
126
125
stageNumber ++
126
+ stageNum := stageNumber
127
127
options .Logger (notcodersdk .LogLevelInfo , "#%d: %s" , stageNum , fmt .Sprintf (format , args ... ))
128
128
129
129
return func (format string , args ... any ) {
@@ -338,7 +338,7 @@ func Run(ctx context.Context, options Options) error {
338
338
339
339
HijackLogrus (func (entry * logrus.Entry ) {
340
340
for _ , line := range strings .Split (entry .Message , "\r " ) {
341
- options .Logger (notcodersdk .LogLevelInfo , "#2 : %s" , color .HiBlackString (line ))
341
+ options .Logger (notcodersdk .LogLevelInfo , "#%d : %s" , stageNumber , color .HiBlackString (line ))
342
342
}
343
343
})
344
344
@@ -474,7 +474,6 @@ func Run(ctx context.Context, options Options) error {
474
474
cacheTTL = time .Hour * 24 * time .Duration (options .CacheTTLDays )
475
475
}
476
476
477
- endStage := startStage ("🏗️ Building image..." )
478
477
// At this point we have all the context, we can now build!
479
478
registryMirror := []string {}
480
479
if val , ok := os .LookupEnv ("KANIKO_REGISTRY_MIRROR" ); ok {
@@ -492,7 +491,7 @@ func Run(ctx context.Context, options Options) error {
492
491
RunStdout : stdoutWriter ,
493
492
RunStderr : stderrWriter ,
494
493
Destinations : destinations ,
495
- NoPush : len (destinations ) == 0 ,
494
+ NoPush : ! options . PushImage || len (destinations ) == 0 ,
496
495
CacheRunLayers : true ,
497
496
CacheCopyLayers : true ,
498
497
CompressedCaching : true ,
@@ -523,15 +522,41 @@ func Run(ctx context.Context, options Options) error {
523
522
RegistryMirrors : registryMirror ,
524
523
},
525
524
SrcContext : buildParams .BuildContext ,
525
+
526
+ // For cached image utilization, produce reproducible builds.
527
+ Reproducible : options .PushImage ,
528
+ }
529
+
530
+ if options .GetCachedImage {
531
+ endStage := startStage ("🏗️ Building fake image..." )
532
+ image , err := executor .DoFakeBuild (opts )
533
+ if err != nil {
534
+ logrus .Infof ("unable to build fake image: %s" , err )
535
+ os .Exit (1 )
536
+ }
537
+ endStage ("🏗️ Built fake image!" )
538
+ digest , err := image .Digest ()
539
+ if err != nil {
540
+ return nil , xerrors .Errorf ("image digest: %w" , err )
541
+ }
542
+
543
+ _ , _ = fmt .Fprintf (os .Stdout , "%s@%s\n " , options .CacheRepo , digest .String ())
544
+ os .Exit (0 )
526
545
}
546
+
547
+ endStage := startStage ("🏗️ Building image..." )
527
548
image , err := executor .DoBuild (opts )
528
549
if err != nil {
529
550
return nil , xerrors .Errorf ("do build: %w" , err )
530
551
}
531
- if err := executor .DoPush (image , opts ); err != nil {
532
- return nil , xerrors .Errorf ("do push: %w" , err )
533
- }
534
552
endStage ("🏗️ Built image!" )
553
+ if options .PushImage {
554
+ endStage = startStage ("🏗️ Pushing image..." )
555
+ if err := executor .DoPush (image , opts ); err != nil {
556
+ return nil , xerrors .Errorf ("do push: %w" , err )
557
+ }
558
+ endStage ("🏗️ Pushed image!" )
559
+ }
535
560
536
561
return image , err
537
562
}
0 commit comments