Git Product home page Git Product logo

eggshell's Introduction

EggShell (for rust): automatically destroy containers you create

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(())
}

Author

Erik Hollensbe [email protected]

License

BSD 3-Clause

eggshell's People

Contributors

erikh avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.