1use std::sync::Arc;
2
3#[tokio::main]
4async fn main() -> Result<(), eggshell::Error> {
5 let docker = Arc::new(tokio::sync::Mutex::new(
6 bollard::Docker::connect_with_unix_defaults().unwrap(),
7 ));
8
9 let mut gs = eggshell::EggShell::new(docker.clone()).await?;
10
11 let count = docker
12 .lock()
13 .await
14 .list_containers::<String>(None)
15 .await
16 .unwrap()
17 .len();
18
19 println!(
20 "before: {} containers -- starting 10 postgres containers",
21 count
22 );
23
24 for num in 0..10 {
25 gs.launch(
26 &format!("test-{}", num),
27 bollard::container::Config {
28 image: Some("postgres:latest".to_string()),
29 env: Some(vec!["POSTGRES_HOST_AUTH_METHOD=trust".to_string()]),
30 ..Default::default()
31 },
32 None,
33 )
34 .await?;
35 }
36
37 let newcount = docker
38 .lock()
39 .await
40 .list_containers::<String>(None)
41 .await
42 .unwrap()
43 .len();
44
45 println!(
46 "before: {} containers, after: {} containers -- now dropping",
47 count, newcount
48 );
49
50 drop(gs);
51
52 let newcount = docker
53 .lock()
54 .await
55 .list_containers::<String>(None)
56 .await
57 .unwrap()
58 .len();
59
60 println!(
61 "after dropping: orig: {} containers, after: {} containers",
62 count, newcount
63 );
64
65 Ok(())
66}