@@ -600,32 +600,34 @@ func (b *executor) buildStage(ctx context.Context, cleanupStages map[int]*stageE
600600 // processed like regular steps, and if no modification is done to
601601 // layers, its easier to reuse cached layers.
602602 if len (b .labels ) > 0 {
603- labelLine := "LABEL"
603+ var labelLine strings.Builder
604+ labelLine .WriteString ("LABEL" )
604605 for _ , labelSpec := range b .labels {
605606 key , value , _ := strings .Cut (labelSpec , "=" )
606607 // check only for an empty key since docker allows empty values
607608 if key != "" {
608- labelLine += fmt .Sprintf ( " %q=%q" , key , value )
609+ fmt .Fprintf ( & labelLine , " %q=%q" , key , value )
609610 }
610611 }
611- appendInstructions = slices .Concat (appendInstructions , []string {labelLine })
612+ appendInstructions = slices .Concat (appendInstructions , []string {labelLine . String () })
612613 }
613614 }
614615
615616 // If we were given environment variables to set via the API, add them as instructions
616617 // at the beginning of the stage so that they affect subsequent RUN instructions and
617618 // factor into the image history.
618619 if len (b .envs ) > 0 {
619- envLine := "ENV"
620+ var envLine strings.Builder
621+ envLine .WriteString ("ENV" )
620622 for _ , envSpec := range b .envs {
621623 key , value , hasValue := strings .Cut (envSpec , "=" )
622624 if hasValue {
623- envLine += fmt .Sprintf ( " %q=%q" , key , value )
625+ fmt .Fprintf ( & envLine , " %q=%q" , key , value )
624626 } else {
625627 return "" , nil , false , fmt .Errorf ("BUG: unresolved environment variable: %q" , key )
626628 }
627629 }
628- prependInstructions = slices .Concat ([]string {envLine }, prependInstructions )
630+ prependInstructions = slices .Concat ([]string {envLine . String () }, prependInstructions )
629631 }
630632
631633 // Create stage labels for all stage images including final stage
0 commit comments