pub struct EggShell { /* private fields */ }Expand description
EggShell is basically a container for containers. When provided a docker client, it funnels all container create operations through it, allowing it to track what needs to be cleaned up. At drop() time (or when teardown() is called), these containers are cleaned up.
Implementations§
Source§impl EggShell
impl EggShell
Sourcepub async fn new(docker: Arc<Mutex<Docker>>) -> Result<Self, Error>
pub async fn new(docker: Arc<Mutex<Docker>>) -> Result<Self, Error>
Construct a new EggShell. When dropped or when teardown() is called, all containers launched through it will be reaped.
Examples found in repository?
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}Sourcepub fn set_debug(&mut self, debug: bool)
pub fn set_debug(&mut self, debug: bool)
set_debug turns off the teardown functionality for this EggShell, allowing you to debug its behavior. This disables the teardown() call which drop() relies on, so you must be ready to clean up your own containers before enabling this.
Sourcepub async fn launch(
&mut self,
name: &str,
container: Config<String>,
start_options: Option<StartContainerOptions<String>>,
) -> Result<(), Error>
pub async fn launch( &mut self, name: &str, container: Config<String>, start_options: Option<StartContainerOptions<String>>, ) -> Result<(), Error>
launch is the meat of EggShell and is how most of the work gets done. When provided with a name and container options, it will create and start that container, adding it to a registry of containers it is tracking. When drop() happens on the EggShell this container will be removed.
Examples found in repository?
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}