Skip to content

Commit

Permalink
replace runc by runh
Browse files Browse the repository at this point in the history
  • Loading branch information
stlankes committed Oct 7, 2024
1 parent 083ed44 commit 526aa3e
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 106 deletions.
21 changes: 7 additions & 14 deletions crates/runh/README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
# Rust bindings for runc CLI
# Rust bindings for runh CLI

[![Crates.io](https://img.shields.io/crates/v/runc)](https://crates.io/crates/runc)
[![docs.rs](https://img.shields.io/docsrs/runc)](https://docs.rs/runc/latest/runc/)
[![Crates.io](https://img.shields.io/crates/l/containerd-shim)](https://github.com/containerd/rust-extensions/blob/main/LICENSE)
[![CI](https://github.com/containerd/rust-extensions/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/containerd/rust-extensions/actions/workflows/ci.yml)

A crate for consuming the runc binary in your Rust applications, similar to [go-runc](https://github.com/containerd/go-runc) for Go.
This crate is based on archived [rust-runc](https://github.com/pwFoo/rust-runc).
A crate for consuming the runh binary in your Rust applications.

## Usage
Both sync/async version is available.
You can build runc client with `RuncConfig` in method chaining style.
You can build runh client with `RunhConfig` in method chaining style.
Call `build()` or `build_async()` to get client.
Note that async client depends on [tokio](https://github.com/tokio-rs/tokio), then please use it on tokio runtime.

```rust,ignore
#[tokio::main]
async fn main() {
let config = runc::GlobalOpts::new()
let config = runh::GlobalOpts::new()
.root("./new_root")
.debug(false)
.log("/path/to/logfile.json")
.log_format(runc::LogFormat::Json)
.log_format(runh::LogFormat::Json)
.rootless(true);
let client = config.build_async().unwrap();
let opts = runc::options::CreateOpts::new()
let opts = runh::options::CreateOpts::new()
.pid_file("/path/to/pid/file")
.no_pivot(true);
Expand All @@ -41,6 +35,5 @@ async fn main() {
- state
- kill
- delete
- Exec is **not** available in `RuncAsyncClient` now.
- Exec is **not** available in `RunhAsyncClient` now.
- Console utilites are **not** available
- see [Go version](https://github.com/containerd/go-runc/blob/main/console.go)
2 changes: 1 addition & 1 deletion crates/runh/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use time::{serde::timestamp, OffsetDateTime};

/// Information for runc container
/// Information for runh container
#[derive(Debug, Serialize, Deserialize)]
pub struct Container {
pub id: String,
Expand Down
8 changes: 4 additions & 4 deletions crates/runh/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub enum Error {
#[error(transparent)]
ProcessSpawnFailed(io::Error),

#[error("Error occured in runc: {0}")]
#[error("Error occured in runh: {0}")]
InvalidCommand(io::Error),

#[error("Runh command failed: status={status}, stdout=\"{stdout}\", stderr=\"{stderr}\"")]
Expand All @@ -71,10 +71,10 @@ pub enum Error {
#[error("Runh command timed out: {0}")]
CommandTimeout(tokio::time::error::Elapsed),

#[error("Unable to parse runc version")]
#[error("Unable to parse runh version")]
InvalidVersion,

#[error("Unable to locate the runc")]
#[error("Unable to locate the runh")]
NotFound,

#[error("Error occurs with fs: {0}")]
Expand Down Expand Up @@ -113,7 +113,7 @@ pub enum Error {
#[error("Sorry, this part of api is not implemented: {0}")]
Unimplemented(String),

#[error("Error occured in runc client: {0}")]
#[error("Error occured in runh client: {0}")]
Other(Box<dyn std::error::Error + Send>),

#[error("Failed to set cmd io: {0}")]
Expand Down
2 changes: 1 addition & 1 deletion crates/runh/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use std::collections::HashMap;

use serde::{Deserialize, Serialize};

/// Event type generated by runc
/// Event type generated by runh
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all(serialize = "lowercase", deserialize = "lowercase"))]
pub enum EventType {
Expand Down
2 changes: 1 addition & 1 deletion crates/runh/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub trait Io: Debug + Send + Sync {
/// Read side of stdin, write side of stdout and write side of stderr should be provided to command.
fn set(&self, cmd: &mut Command) -> Result<()>;

/// Only close write side (should be stdout/err "from" runc process)
/// Only close write side (should be stdout/err "from" runh process)
fn close_after_start(&self);
}

Expand Down
Loading

0 comments on commit 526aa3e

Please sign in to comment.