rust-extensions/crates/shim
Maksym Pavlenko d3852a5fcd Implement remote publisher
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2021-07-26 16:59:21 -07:00
..
examples Implement remote publisher 2021-07-26 16:59:21 -07:00
src Implement remote publisher 2021-07-26 16:59:21 -07:00
Cargo.toml Rename crates 2021-07-22 12:29:58 -07:00
README.md Update shim README 2021-07-24 11:04:19 -07:00

README.md

containerd shim

Rust crate to ease runtime v2 shim implementation.

It replicates same shim.Run API offered by containerd's shim v2 runtime implementation written in Go.

Look and feel

The API is very similar to the one offered by Go version:

struct Service;

impl shim::Shim for Service {
    fn new(_id: &str, _namespace: &str, _config: &mut shim::Config) -> Self {
        Service {}
    }

    fn start_shim(&mut self, opts: StartOpts) -> Result<String, Box<dyn Error>> {
        let address = shim::spawn(opts)?;
        Ok(address)
    }

    fn delete_shim(&mut self) -> Result<api::DeleteResponse, Box<dyn Error>> {
        todo!()
    }
}

impl shim::Task for Service {
    fn create(
        &self,
        ctx: &TtrpcContext,
        req: api::CreateTaskRequest,
    ) -> ::ttrpc::Result<api::CreateTaskResponse> {
        debug!("Create");
        Ok(api::CreateTaskResponse::default())
    }
}

fn main() {
    shim::run::<Service>("io.containerd.empty.v1")
}

How to use

Runtime binary has to be named in a special way to be recognized by containerd:

$ cargo build --example empty-shim
$ sudo cp ./target/debug/examples/empty-shim /usr/local/bin/containerd-shim-empty-v2
$ sudo ctr run --rm --runtime io.containerd.empty.v2 -t docker.io/library/hello-world:latest hello