@@ -92,6 +92,38 @@ impl Container {
9292 } )
9393 }
9494
95+ /// Convert the `Container` instance to a `ContainerConfig` for the Docker API.
96+ #[ must_use]
97+ pub fn to_container_config < ' a > ( & ' a self , full_image : & ' a str ) -> ContainerConfig < & ' a str > {
98+ ContainerConfig {
99+ image : Some ( full_image) ,
100+ tty : Some ( true ) ,
101+ cmd : self
102+ . args
103+ . as_ref ( )
104+ . map ( |args| args. iter ( ) . map ( String :: as_str) . collect ( ) ) ,
105+ env : self
106+ . env
107+ . as_ref ( )
108+ . map ( |env| env. iter ( ) . map ( String :: as_str) . collect ( ) ) ,
109+ labels : self . labels . as_ref ( ) . map ( |labels| {
110+ labels
111+ . iter ( )
112+ . map ( |( key, value) | ( key. as_str ( ) , value. as_str ( ) ) )
113+ . collect ( )
114+ } ) ,
115+ network_disabled : self . network_disabled ,
116+ #[ allow( clippy:: zero_sized_map_values) ]
117+ exposed_ports : self . exposed_ports . as_ref ( ) . map ( |ports| {
118+ ports
119+ . iter ( )
120+ . map ( |port| ( port. as_str ( ) , HashMap :: new ( ) ) )
121+ . collect ( )
122+ } ) ,
123+ ..Default :: default ( )
124+ }
125+ }
126+
95127 /// Run the `Container` generator.
96128 ///
97129 /// # Errors
@@ -149,33 +181,7 @@ impl Container {
149181 name : & container_name,
150182 platform : None ,
151183 } ) ,
152- ContainerConfig {
153- image : Some ( full_image. as_str ( ) ) ,
154- tty : Some ( true ) ,
155- cmd : self
156- . args
157- . as_ref ( )
158- . map ( |args| args. iter ( ) . map ( String :: as_str) . collect ( ) ) ,
159- env : self
160- . env
161- . as_ref ( )
162- . map ( |env| env. iter ( ) . map ( String :: as_str) . collect ( ) ) ,
163- labels : self . labels . as_ref ( ) . map ( |labels| {
164- labels
165- . iter ( )
166- . map ( |( key, value) | ( key. as_str ( ) , value. as_str ( ) ) )
167- . collect ( )
168- } ) ,
169- network_disabled : self . network_disabled ,
170- #[ allow( clippy:: zero_sized_map_values) ]
171- exposed_ports : self . exposed_ports . as_ref ( ) . map ( |ports| {
172- ports
173- . iter ( )
174- . map ( |port| ( port. as_str ( ) , HashMap :: new ( ) ) )
175- . collect ( )
176- } ) ,
177- ..Default :: default ( )
178- } ,
184+ self . to_container_config ( & full_image) ,
179185 )
180186 . await ?;
181187
@@ -198,14 +204,18 @@ impl Container {
198204 // Wait for shutdown signal
199205 let shutdown_wait = self . shutdown . recv ( ) ;
200206 tokio:: pin!( shutdown_wait) ;
207+ let mut interval = tokio:: time:: interval ( tokio:: time:: Duration :: from_secs ( 10 ) ) ;
201208 loop {
202209 tokio:: select! {
203210 // Check that containers are still running every 10 seconds
204- ( ) = tokio :: time :: sleep ( tokio :: time :: Duration :: from_secs ( 10 ) ) => {
211+ _ = interval . tick ( ) => {
205212 for container in & containers {
206213 if let Some ( state) = docker. inspect_container( & container. id, None ) . await ?. state {
207214 if !state. running. unwrap_or( false ) {
208- warn!( "Container {id} is not running anymore" , id = container. id) ;
215+ return Err ( Error :: Generic ( format!(
216+ "Container {id} is not running anymore" ,
217+ id = container. id
218+ ) ) ) ;
209219 }
210220 }
211221 }
0 commit comments