@@ -139,23 +139,37 @@ impl Actor {
139
139
. await
140
140
. context ( "failed to create actor dir" ) ?;
141
141
142
- // Create fs mount
143
- self . make_fs ( & ctx) . await ?;
144
-
145
- // Download artifact
146
- self . download_image ( & ctx) . await ?;
147
-
148
- // Bind selected ports
149
- let ports = self . bind_ports ( ctx) . await ?;
142
+ // Determine ahead of time if we need to set up CNI network
143
+ let needs_cni_network = matches ! (
144
+ self . config. image. kind,
145
+ protocol:: ImageKind :: DockerImage | protocol:: ImageKind :: OciBundle
146
+ ) && matches ! ( self . config. network_mode, protocol:: NetworkMode :: Bridge ) ;
147
+
148
+ // Parallelize two independent jobs:
149
+ //
150
+ // - `download_image` takes a long time to download. `download_image` is dependent on
151
+ // `make_fs`
152
+ // - `setup_cni_network` takes a long time. `setup_cni_network` is dependent on
153
+ // `bind_ports`.
154
+ let ( _, ports) = tokio:: try_join!(
155
+ async {
156
+ self . make_fs( & ctx) . await ?;
157
+ self . download_image( & ctx) . await ?;
158
+ Result :: <( ) , anyhow:: Error >:: Ok ( ( ) )
159
+ } ,
160
+ async {
161
+ let ports = self . bind_ports( ctx) . await ?;
162
+ if needs_cni_network {
163
+ self . setup_cni_network( & ctx, & ports) . await ?;
164
+ }
165
+
166
+ Ok ( ports)
167
+ }
168
+ ) ?;
150
169
151
170
match self . config . image . kind {
152
171
protocol:: ImageKind :: DockerImage | protocol:: ImageKind :: OciBundle => {
153
172
self . setup_oci_bundle ( & ctx, & ports) . await ?;
154
-
155
- // Run CNI setup script
156
- if let protocol:: NetworkMode :: Bridge = self . config . network_mode {
157
- self . setup_cni_network ( & ctx, & ports) . await ?;
158
- }
159
173
}
160
174
protocol:: ImageKind :: JavaScript => self . setup_isolate ( & ctx, & ports) . await ?,
161
175
}
0 commit comments