@@ -576,25 +576,23 @@ func AuthConfig(creds string) (*types.DockerAuthConfig, error) {
576
576
577
577
// GetBuildOutput is responsible for parsing custom build output argument i.e `build --output` flag.
578
578
// Takes `buildOutput` as string and returns BuildOutputOption
579
- func GetBuildOutput (buildOutput string ) (define.BuildOutputOption , error ) {
579
+ func GetBuildOutput (buildOutput , image string ) (define.BuildOutputOption , error ) {
580
580
if len (buildOutput ) == 1 && buildOutput == "-" {
581
581
// Feature parity with buildkit, output tar to stdout
582
582
// Read more here: https://docs.docker.com/engine/reference/commandline/build/#custom-build-outputs
583
583
return define.BuildOutputOption {Path : "" ,
584
584
IsDir : false ,
585
585
IsStdout : true }, nil
586
586
}
587
- if ! strings .Contains (buildOutput , "," ) {
588
- // expect default --output <dirname>
589
- return define.BuildOutputOption {Path : buildOutput ,
590
- IsDir : true ,
591
- IsStdout : false }, nil
587
+
588
+ out := define.BuildOutputOption {
589
+ Attrs : map [string ]string {},
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,35 @@ 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 .Local .String ():
610
+ out .IsDir = true
611
+ case define .Tar .String ():
612
+ out .IsDir = false
613
+ case define .Registry .String ():
614
+ out .Type = define .Image
615
+ out .Attrs ["push" ] = "true"
616
+ out .Attrs ["name" ] = image
617
+ default :
615
618
return define.BuildOutputOption {}, fmt .Errorf ("invalid type %q selected for build output options %q" , arr [1 ], buildOutput )
616
619
}
617
620
case "dest" :
618
621
if pathSelected {
619
622
return define.BuildOutputOption {}, fmt .Errorf ("duplicate %q not supported" , arr [0 ])
620
623
}
621
624
pathSelected = true
622
- path = arr [1 ]
625
+ out . Path = arr [1 ]
623
626
default :
624
627
return define.BuildOutputOption {}, fmt .Errorf ("unrecognized key %q in build output option: %q" , arr [0 ], buildOutput )
625
628
}
626
629
}
627
630
628
- if ! typeSelected || ! pathSelected {
631
+ if ! typeSelected && ! pathSelected {
632
+ // TODO: update error message
629
633
return define.BuildOutputOption {}, fmt .Errorf ("invalid build output option %q, accepted keys are type and dest must be present" , buildOutput )
630
634
}
631
635
632
- if path == "-" {
636
+ if out . Path == "-" {
633
637
if isDir {
634
638
return define.BuildOutputOption {}, fmt .Errorf ("invalid build output option %q, type=local and dest=- is not supported" , buildOutput )
635
639
}
@@ -638,7 +642,7 @@ func GetBuildOutput(buildOutput string) (define.BuildOutputOption, error) {
638
642
IsStdout : true }, nil
639
643
}
640
644
641
- return define. BuildOutputOption { Path : path , IsDir : isDir , IsStdout : isStdout } , nil
645
+ return out , nil
642
646
}
643
647
644
648
// IDMappingOptions parses the build options related to user namespaces and ID mapping.
0 commit comments