@@ -18,6 +18,7 @@ import (
18
18
"github.com/containers/buildah/define"
19
19
internalParse "github.com/containers/buildah/internal/parse"
20
20
"github.com/containers/buildah/pkg/sshagent"
21
+ "github.com/containers/buildah/util"
21
22
"github.com/containers/common/pkg/config"
22
23
"github.com/containers/common/pkg/parse"
23
24
"github.com/containers/image/v5/docker/reference"
@@ -576,25 +577,23 @@ func AuthConfig(creds string) (*types.DockerAuthConfig, error) {
576
577
577
578
// GetBuildOutput is responsible for parsing custom build output argument i.e `build --output` flag.
578
579
// Takes `buildOutput` as string and returns BuildOutputOption
579
- func GetBuildOutput (buildOutput string ) (define.BuildOutputOption , error ) {
580
+ func GetBuildOutput (buildOutput , image string ) (define.BuildOutputOption , error ) {
580
581
if len (buildOutput ) == 1 && buildOutput == "-" {
581
582
// Feature parity with buildkit, output tar to stdout
582
583
// Read more here: https://docs.docker.com/engine/reference/commandline/build/#custom-build-outputs
583
- return define.BuildOutputOption {Path : "" ,
584
- IsDir : false ,
585
- IsStdout : true }, nil
584
+ return define.BuildOutputOption {
585
+ Path : "" ,
586
+ IsStdout : true ,
587
+ }, nil
586
588
}
587
- if ! strings .Contains (buildOutput , "," ) {
588
- // expect default --output <dirname>
589
- return define.BuildOutputOption {Path : buildOutput ,
590
- IsDir : true ,
591
- IsStdout : false }, nil
589
+
590
+ out := define.BuildOutputOption {
591
+ IsStdout : false ,
592
592
}
593
+
593
594
isDir := true
594
- isStdout := false
595
595
typeSelected := false
596
596
pathSelected := false
597
- path := ""
598
597
tokens := strings .Split (buildOutput , "," )
599
598
for _ , option := range tokens {
600
599
arr := strings .SplitN (option , "=" , 2 )
@@ -607,38 +606,52 @@ func GetBuildOutput(buildOutput string) (define.BuildOutputOption, error) {
607
606
return define.BuildOutputOption {}, fmt .Errorf ("duplicate %q not supported" , arr [0 ])
608
607
}
609
608
typeSelected = true
610
- if arr [1 ] == "local" {
611
- isDir = true
612
- } else if arr [1 ] == "tar" {
613
- isDir = false
614
- } else {
609
+ switch arr [1 ] {
610
+ case "local" :
611
+ out .Type = define .BuildOutputLocal
612
+ case "tar" :
613
+ out .Type = define .BuildOutputTar
614
+ case "registry" :
615
+ // --type=registry ==> --type=image,push=true
616
+ out .Type = define .BuildOutputImage
617
+ out .Push = true
618
+
619
+ out .Image = image
620
+ imageRef , err := util .ImageStringToImageReference (image )
621
+ if err != nil {
622
+ return define.BuildOutputOption {}, fmt .Errorf ("failed to convert image to ImageReference" )
623
+ }
624
+ out .ImageRef = imageRef
625
+ default :
615
626
return define.BuildOutputOption {}, fmt .Errorf ("invalid type %q selected for build output options %q" , arr [1 ], buildOutput )
616
627
}
617
628
case "dest" :
618
629
if pathSelected {
619
630
return define.BuildOutputOption {}, fmt .Errorf ("duplicate %q not supported" , arr [0 ])
620
631
}
621
632
pathSelected = true
622
- path = arr [1 ]
633
+ out . Path = arr [1 ]
623
634
default :
624
635
return define.BuildOutputOption {}, fmt .Errorf ("unrecognized key %q in build output option: %q" , arr [0 ], buildOutput )
625
636
}
626
637
}
627
638
628
- if ! typeSelected || ! pathSelected {
639
+ if ! typeSelected && ! pathSelected {
640
+ // TODO: update error message
629
641
return define.BuildOutputOption {}, fmt .Errorf ("invalid build output option %q, accepted keys are type and dest must be present" , buildOutput )
630
642
}
631
643
632
- if path == "-" {
644
+ if out . Path == "-" {
633
645
if isDir {
634
646
return define.BuildOutputOption {}, fmt .Errorf ("invalid build output option %q, type=local and dest=- is not supported" , buildOutput )
635
647
}
636
- return define.BuildOutputOption {Path : "" ,
637
- IsDir : false ,
638
- IsStdout : true }, nil
648
+ return define.BuildOutputOption {
649
+ Path : "" ,
650
+ IsStdout : true ,
651
+ }, nil
639
652
}
640
653
641
- return define. BuildOutputOption { Path : path , IsDir : isDir , IsStdout : isStdout } , nil
654
+ return out , nil
642
655
}
643
656
644
657
// IDMappingOptions parses the build options related to user namespaces and ID mapping.
0 commit comments