@@ -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,22 @@ 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
584
return define.BuildOutputOption {Path : "" ,
584
585
IsDir : false ,
585
586
IsStdout : true }, nil
586
587
}
587
- if ! strings .Contains (buildOutput , "," ) {
588
- // expect default --output <dirname>
589
- return define.BuildOutputOption {Path : buildOutput ,
590
- IsDir : true ,
591
- IsStdout : false }, nil
588
+
589
+ out := define.BuildOutputOption {
590
+ IsStdout : false ,
592
591
}
592
+
593
593
isDir := true
594
- isStdout := false
595
594
typeSelected := false
596
595
pathSelected := false
597
- path := ""
598
596
tokens := strings .Split (buildOutput , "," )
599
597
for _ , option := range tokens {
600
598
arr := strings .SplitN (option , "=" , 2 )
@@ -607,29 +605,42 @@ func GetBuildOutput(buildOutput string) (define.BuildOutputOption, error) {
607
605
return define.BuildOutputOption {}, fmt .Errorf ("duplicate %q not supported" , arr [0 ])
608
606
}
609
607
typeSelected = true
610
- if arr [1 ] == "local" {
611
- isDir = true
612
- } else if arr [1 ] == "tar" {
613
- isDir = false
614
- } else {
608
+ switch arr [1 ] {
609
+ case define .BuildOutputLocal .String ():
610
+ out .IsDir = true
611
+ case define .BuildOutputTar .String ():
612
+ out .IsDir = false
613
+ case define .BuildOutputRegistry .String ():
614
+ // --type=registry ==> --type=image,push=true
615
+ out .Type = define .BuildOutputImage
616
+ out .Push = true
617
+
618
+ out .Image = image
619
+ imageRef , err := util .ImageStringToImageReference (image )
620
+ if err != nil {
621
+ return define.BuildOutputOption {}, fmt .Errorf ("failed to convert image to ImageReference" )
622
+ }
623
+ out .ImageRef = imageRef
624
+ default :
615
625
return define.BuildOutputOption {}, fmt .Errorf ("invalid type %q selected for build output options %q" , arr [1 ], buildOutput )
616
626
}
617
627
case "dest" :
618
628
if pathSelected {
619
629
return define.BuildOutputOption {}, fmt .Errorf ("duplicate %q not supported" , arr [0 ])
620
630
}
621
631
pathSelected = true
622
- path = arr [1 ]
632
+ out . Path = arr [1 ]
623
633
default :
624
634
return define.BuildOutputOption {}, fmt .Errorf ("unrecognized key %q in build output option: %q" , arr [0 ], buildOutput )
625
635
}
626
636
}
627
637
628
- if ! typeSelected || ! pathSelected {
638
+ if ! typeSelected && ! pathSelected {
639
+ // TODO: update error message
629
640
return define.BuildOutputOption {}, fmt .Errorf ("invalid build output option %q, accepted keys are type and dest must be present" , buildOutput )
630
641
}
631
642
632
- if path == "-" {
643
+ if out . Path == "-" {
633
644
if isDir {
634
645
return define.BuildOutputOption {}, fmt .Errorf ("invalid build output option %q, type=local and dest=- is not supported" , buildOutput )
635
646
}
@@ -638,7 +649,7 @@ func GetBuildOutput(buildOutput string) (define.BuildOutputOption, error) {
638
649
IsStdout : true }, nil
639
650
}
640
651
641
- return define. BuildOutputOption { Path : path , IsDir : isDir , IsStdout : isStdout } , nil
652
+ return out , nil
642
653
}
643
654
644
655
// IDMappingOptions parses the build options related to user namespaces and ID mapping.
0 commit comments