@@ -47,19 +47,25 @@ pub enum TagWithSource {
4747}
4848
4949/// Build all enabled challenges for the given profile. Returns tags built
50- pub fn build_challenges (
50+ pub async fn build_challenges (
5151 profile_name : & str ,
5252 push : bool ,
5353 extract_artifacts : bool ,
5454) -> Result < Vec < ( & ChallengeConfig , BuildResult ) > > {
55- enabled_challenges ( profile_name) ?
56- . into_iter ( )
57- . map ( |chal| build_challenge ( profile_name, chal, push, extract_artifacts) . map ( |r| ( chal, r) ) )
58- . collect :: < Result < _ > > ( )
55+ try_join_all (
56+ enabled_challenges ( profile_name) ?
57+ . into_iter ( )
58+ . map ( |chal| async move {
59+ build_challenge ( profile_name, chal, push, extract_artifacts)
60+ . await
61+ . map ( |r| ( chal, r) )
62+ } ) ,
63+ )
64+ . await
5965}
6066
6167/// Build all images from given challenge, optionally pushing image or extracting artifacts
62- fn build_challenge (
68+ async fn build_challenge (
6369 profile_name : & str ,
6470 chal : & ChallengeConfig ,
6571 push : bool ,
@@ -73,27 +79,28 @@ fn build_challenge(
7379 assets : vec ! [ ] ,
7480 } ;
7581
76- built. tags = chal
77- . pods
78- . iter ( )
79- . map ( |p| match & p. image_source {
82+ built. tags = try_join_all ( chal. pods . iter ( ) . map ( |p| async {
83+ match & p. image_source {
8084 Image ( tag) => Ok ( TagWithSource :: Upstream ( tag. to_string ( ) ) ) ,
8185 // build any pods that need building
8286 Build ( build) => {
8387 let tag = chal. container_tag_for_pod ( profile_name, & p. name ) ?;
8488
85- let res = docker:: build_image ( & chal. directory , build, & tag) . with_context ( || {
86- format ! (
87- "error building image {} for chal {}" ,
88- p. name,
89- chal. directory. to_string_lossy( )
90- )
91- } ) ;
89+ let res = docker:: build_image ( & chal. directory , build, & tag)
90+ . await
91+ . with_context ( || {
92+ format ! (
93+ "error building image {} for chal {}" ,
94+ p. name,
95+ chal. directory. to_string_lossy( )
96+ )
97+ } ) ;
9298 // map result tag string into enum
9399 res. map ( TagWithSource :: Built )
94100 }
95- } )
96- . collect :: < Result < _ > > ( ) ?;
101+ }
102+ } ) )
103+ . await ?;
97104
98105 if push {
99106 // only need to push tags we actually built
@@ -112,13 +119,12 @@ fn build_challenge(
112119 chal. directory
113120 ) ;
114121
115- tags_to_push
116- . iter ( )
117- . map ( |tag| {
118- docker:: push_image ( tag, & config. registry . build )
119- . with_context ( || format ! ( "error pushing image {tag}" ) )
120- } )
121- . collect :: < Result < Vec < _ > > > ( ) ?;
122+ try_join_all ( tags_to_push. iter ( ) . map ( |tag| async move {
123+ docker:: push_image ( tag, & config. registry . build )
124+ . await
125+ . with_context ( || format ! ( "error pushing image {tag}" ) )
126+ } ) )
127+ . await ?;
122128 }
123129
124130 if extract_artifacts {
0 commit comments