11use std:: path:: PathBuf ;
22
3- use crate :: { core:: copy:: CopyToContainerCollection , BuildableImage , CopyToContainer , GenericImage } ;
3+ use crate :: {
4+ core:: { copy:: CopyToContainerCollection , BuildContextBuilder } ,
5+ BuildableImage , GenericImage ,
6+ } ;
47
58#[ derive( Debug ) ]
69pub struct GenericBuildableImage {
710 name : String ,
811 tag : String ,
9- build_context : CopyToContainerCollection ,
12+ build_context_builder : BuildContextBuilder ,
1013}
1114
1215impl GenericBuildableImage {
1316 pub fn new ( name : impl Into < String > , tag : impl Into < String > ) -> Self {
1417 Self {
1518 name : name. into ( ) ,
1619 tag : tag. into ( ) ,
17- build_context : CopyToContainerCollection :: new ( vec ! [ ] ) ,
20+ build_context_builder : BuildContextBuilder :: default ( ) ,
1821 }
1922 }
2023
21- pub fn with_dockerfile ( self , source : impl Into < PathBuf > ) -> Self {
22- self . with_file ( source. into ( ) , "Dockerfile" )
24+ pub fn with_dockerfile ( mut self , source : impl Into < PathBuf > ) -> Self {
25+ self . build_context_builder = self . build_context_builder . with_dockerfile ( source) ;
26+ self
2327 }
2428
25- pub fn with_dockerfile_string ( self , content : impl Into < String > ) -> Self {
26- self . with_data ( content. into ( ) , "Dockerfile" )
29+ pub fn with_dockerfile_string ( mut self , content : impl Into < String > ) -> Self {
30+ self . build_context_builder = self . build_context_builder . with_dockerfile_string ( content) ;
31+ self
2732 }
2833
2934 pub fn with_file ( mut self , source : impl Into < PathBuf > , target : impl Into < String > ) -> Self {
30- self . build_context
31- . add ( CopyToContainer :: new ( source. into ( ) , target) ) ;
35+ self . build_context_builder = self . build_context_builder . with_file ( source, target) ;
3236 self
3337 }
3438
3539 pub fn with_data ( mut self , data : impl Into < Vec < u8 > > , target : impl Into < String > ) -> Self {
36- self . build_context
37- . add ( CopyToContainer :: new ( data. into ( ) , target) ) ;
40+ self . build_context_builder = self . build_context_builder . with_data ( data, target) ;
3841 self
3942 }
4043}
@@ -43,7 +46,7 @@ impl BuildableImage for GenericBuildableImage {
4346 type Built = GenericImage ;
4447
4548 fn build_context ( & self ) -> CopyToContainerCollection {
46- self . build_context . clone ( )
49+ self . build_context_builder . as_copy_to_container_collection ( )
4750 }
4851
4952 fn descriptor ( & self ) -> String {
0 commit comments