@@ -5,7 +5,7 @@ use crate::network;
55use serde:: de:: { DeserializeOwned , Deserializer } ;
66use serde:: { Deserialize , Serialize } ;
77
8- use std:: collections:: { HashMap , HashSet } ;
8+ use std:: collections:: HashMap ;
99use std:: path:: PathBuf ;
1010use std:: str:: FromStr ;
1111use std:: time:: Duration ;
@@ -591,6 +591,37 @@ impl Default for ContainerLogOptions {
591591 }
592592}
593593
594+ #[ derive( Debug , Clone , Deserialize , Serialize ) ]
595+ pub enum ContainerBuildVersionOption {
596+ Classic ,
597+ BuildKit ,
598+ }
599+
600+ #[ derive( Debug , PartialEq , Eq ) ]
601+ pub struct ParseContainerBuildVersionOptionError ;
602+
603+ impl FromStr for ContainerBuildVersionOption {
604+ type Err = ParseContainerBuildVersionOptionError ;
605+
606+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
607+ match s {
608+ "1" => Ok ( ContainerBuildVersionOption :: Classic ) ,
609+ "2" => Ok ( ContainerBuildVersionOption :: BuildKit ) ,
610+ _ => Err ( ParseContainerBuildVersionOptionError ) ,
611+ }
612+ }
613+ }
614+
615+ impl std:: fmt:: Display for ContainerBuildVersionOption {
616+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
617+ let s = match self {
618+ ContainerBuildVersionOption :: Classic => "1" ,
619+ ContainerBuildVersionOption :: BuildKit => "2" ,
620+ } ;
621+ write ! ( f, "{s}" )
622+ }
623+ }
624+
594625#[ derive( Debug , Clone , Deserialize , Serialize ) ]
595626pub struct ContainerBuildOptions {
596627 /// Path within the build context to the Dockerfile.
@@ -663,6 +694,9 @@ pub struct ContainerBuildOptions {
663694
664695 /// Platform in the format os[/arch[/variant]]
665696 pub platform : String ,
697+
698+ /// Version of the builder backend to use
699+ pub version : ContainerBuildVersionOption ,
666700}
667701
668702impl ContainerBuildOptions {
@@ -737,6 +771,7 @@ impl ContainerBuildOptions {
737771 params. append_pair ( "networkmode" , networkmode) ;
738772 }
739773 params. append_pair ( "platform" , & self . platform ) ;
774+ params. append_pair ( "version" , & self . version . to_string ( ) ) ;
740775 params. finish ( )
741776 }
742777}
@@ -766,6 +801,7 @@ impl Default for ContainerBuildOptions {
766801 labels : None ,
767802 networkmode : None ,
768803 platform : String :: new ( ) ,
804+ version : ContainerBuildVersionOption :: Classic ,
769805 }
770806 }
771807}
0 commit comments