1
1
use super :: Container ;
2
2
3
3
use anyhow:: { ensure, Context , Result } ;
4
- use bollard:: service:: EventMessage ;
5
- use futures:: {
6
- future:: { BoxFuture , Shared } ,
7
- FutureExt , StreamExt ,
8
- } ;
9
4
10
5
pub struct Docker ( bollard:: Docker ) ;
11
6
@@ -14,14 +9,10 @@ impl Docker {
14
9
Ok ( Docker ( bollard:: Docker :: connect_with_local_defaults ( ) ?) )
15
10
}
16
11
17
- pub async fn get_container < T : AsRef < str > > ( & self , name : T ) -> Result < Container > {
12
+ pub async fn get < T : AsRef < str > > ( & self , name : T ) -> Result < Container > {
18
13
let response = self . 0 . inspect_container ( name. as_ref ( ) , None ) . await ?;
19
14
let id = response. id . context ( "Failed to obtain container ID" ) ?;
20
- Ok ( Container {
21
- id : id. clone ( ) ,
22
- docker : self . 0 . clone ( ) ,
23
- remove_event : container_removed_future ( & self . 0 , id. clone ( ) ) ,
24
- } )
15
+ Container :: new ( & id, & self . 0 )
25
16
}
26
17
27
18
pub async fn run < U : AsRef < str > , T : AsRef < [ U ] > > ( & self , args : T ) -> Result < Container > {
@@ -44,29 +35,6 @@ impl Docker {
44
35
) ;
45
36
46
37
let id = String :: from_utf8 ( output. stdout ) ?;
47
- self . get_container ( id. trim ( ) ) . await
38
+ self . get ( id. trim ( ) ) . await
48
39
}
49
40
}
50
-
51
- fn container_removed_future (
52
- docker : & bollard:: Docker ,
53
- id : String ,
54
- ) -> Shared < BoxFuture < ' static , Option < EventMessage > > > {
55
- let options = bollard:: system:: EventsOptions {
56
- filters : [
57
- ( String :: from ( "container" ) , vec ! [ id. clone( ) ] ) ,
58
- ( String :: from ( "type" ) , vec ! [ String :: from( "container" ) ] ) ,
59
- ( String :: from ( "event" ) , vec ! [ String :: from( "destroy" ) ] ) ,
60
- ]
61
- . into ( ) ,
62
- ..Default :: default ( )
63
- } ;
64
-
65
- let mut events = docker. events ( Some ( options) ) ;
66
-
67
- // Spawn the future to start listening event.
68
- tokio:: spawn ( async move { events. next ( ) . await ?. ok ( ) } )
69
- . map ( |x| x. ok ( ) . flatten ( ) )
70
- . boxed ( )
71
- . shared ( )
72
- }
0 commit comments