EggShell

Struct EggShell 

Source
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

Source

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?
examples/basic.rs (line 9)
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}
Source

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.

Source

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?
examples/basic.rs (lines 25-33)
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}
Source

pub async fn teardown(&self) -> Result<(), Error>

teardown is what reaps the launch()’d containers. It is called as a part of drop() as well.

Trait Implementations§

Source§

impl Clone for EggShell

Source§

fn clone(&self) -> EggShell

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EggShell

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for EggShell

Source§

fn drop(&mut self)

Reaps all containers registered with launch().

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.