Crates.io | eggshell |
lib.rs | eggshell |
version | 0.1.3 |
source | src |
created_at | 2021-08-29 23:30:15.279586 |
updated_at | 2022-02-10 10:29:26.082346 |
description | Remove testing docker containers after this object goes away |
homepage | https://github.com/zerotier/eggshell |
repository | https://github.com/zerotier/eggshell |
max_upload_size | |
id | 443929 |
size | 40,828 |
EggShell automatically cleans up all the containers it creates when the struct is dropped. It uses the bollard docker toolkit, and tokio internally to manage the containers.
To utilize, simply create containers through it and wait for EggShell to go away. It will automatically trigger its Drop
implementation which will destroy the containers.
Example that shows off counting (from the examples/basic.rs
source):
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), eggshell::Error> {
let docker = Arc::new(tokio::sync::Mutex::new(
bollard::Docker::connect_with_unix_defaults().unwrap(),
));
let mut gs = eggshell::EggShell::new(docker.clone()).await?;
let count = docker
.lock()
.await
.list_containers::<String>(None)
.await
.unwrap()
.len();
println!(
"before: {} containers -- starting 10 postgres containers",
count
);
for num in 0..10 {
gs.launch(
&format!("test-{}", num),
bollard::container::Config {
image: Some("postgres:latest".to_string()),
env: Some(vec!["POSTGRES_HOST_AUTH_METHOD=trust".to_string()]),
..Default::default()
},
None,
)
.await?;
}
let newcount = docker
.lock()
.await
.list_containers::<String>(None)
.await
.unwrap()
.len();
println!(
"before: {} containers, after: {} containers -- now dropping",
count, newcount
);
drop(gs);
let newcount = docker
.lock()
.await
.list_containers::<String>(None)
.await
.unwrap()
.len();
println!(
"after dropping: orig: {} containers, after: {} containers",
count, newcount
);
Ok(())
}
Erik Hollensbe erik.hollensbe@zerotier.com
BSD 3-Clause