Skip to content

Commit 2f75c29

Browse files
authored
Merge pull request #85 from cpuguy83/docs
Fix code docs
2 parents e251de3 + f8b8470 commit 2f75c29

File tree

21 files changed

+222
-17
lines changed

21 files changed

+222
-17
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ jobs:
3232
with:
3333
command: build
3434
args: --all --verbose
35+
- name: Validate docs
36+
run: ./scripts/validate-docs.sh
3537
- name: Run tests
3638
uses: actions-rs/cargo@v1
3739
with:

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/containerd-shim-wasm/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description = "Library for building containerd shims for wasm"
44
version = "0.1.1"
55
edition.workspace = true
66
license.workspace = true
7-
readme.workspace = true
7+
readme = "README.md"
88
homepage.workspace = true
99
repository.workspace = true
1010

@@ -42,3 +42,4 @@ rand = "0.8"
4242
[features]
4343
default = []
4444
generate_bindings = ["ttrpc-codegen"]
45+
generate_doc = []
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
![runwasi logo](../../art/logo/runwasi_logo_icon.svg)
2+
3+
# containerd-shim-wasm
4+
5+
A library to help build containerd shims for wasm workloads.
6+
7+
## Usage
8+
9+
```rust
10+
use containerd_shim as shim;
11+
use containerd_shim_wasm::sandbox::{ShimCli, Instance, Nop}
12+
13+
fn main() {
14+
shim::run::<ShimCli<Nop>>("io.containerd.nop.v1", opts);
15+
}
16+
```
17+
18+
The above example uses the built-in `Nop` instance which does nothing.
19+
You can build your own instance by implementing the `Instance` trait.
20+
21+
```rust
22+
use containerd_shim as shim;
23+
use containerd_shim_wasm::sandbox::{ShimCli, Instance}
24+
25+
struct MyInstance {
26+
// ...
27+
}
28+
29+
impl Instance for MyInstance {
30+
// ...
31+
}
32+
33+
fn main() {
34+
shim::run::<ShimCli<MyInstance>>("io.containerd.myshim.v1", opts);
35+
}
36+
```
37+
38+
containerd expects the shim binary to be installed into `$PATH` (as seen by the containerd process) with a binary name like `containerd-shim-myshim-v1` which maps to the `io.containerd.myshim.v1` runtime which would need to be configured in containerd. It (containerd) also supports specifying a path to the shim binary but needs to be configured to do so.
39+
40+
This crate is not tied to any specific wasm engine.

crates/containerd-shim-wasm/build.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,19 @@ use std::fs;
55
use ttrpc_codegen::{Codegen, ProtobufCustomize};
66

77
#[cfg(not(feature = "generate_bindings"))]
8+
#[cfg(not(feature = "generate_doc"))]
89
fn main() {}
910

11+
#[cfg(feature = "generate_doc")]
12+
fn main() {
13+
use std::io::Write;
14+
println!("cargo:rerun-if-changed=doc");
15+
println!("cargo:rerun-if-missing=README.md");
16+
let mut f = std::fs::File::create("README.md").unwrap();
17+
f.write_all(include_bytes!("doc/header.md")).unwrap();
18+
f.write_all(include_bytes!("doc/doc.md")).unwrap();
19+
}
20+
1021
#[cfg(feature = "generate_bindings")]
1122
fn main() {
1223
println!("cargo:rerun-if-changed=protos");
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
A library to help build containerd shims for wasm workloads.
2+
3+
## Usage
4+
5+
```rust
6+
use containerd_shim as shim;
7+
use containerd_shim_wasm::sandbox::{ShimCli, Instance, Nop}
8+
9+
fn main() {
10+
shim::run::<ShimCli<Nop>>("io.containerd.nop.v1", opts);
11+
}
12+
```
13+
14+
The above example uses the built-in `Nop` instance which does nothing.
15+
You can build your own instance by implementing the `Instance` trait.
16+
17+
```rust
18+
use containerd_shim as shim;
19+
use containerd_shim_wasm::sandbox::{ShimCli, Instance}
20+
21+
struct MyInstance {
22+
// ...
23+
}
24+
25+
impl Instance for MyInstance {
26+
// ...
27+
}
28+
29+
fn main() {
30+
shim::run::<ShimCli<MyInstance>>("io.containerd.myshim.v1", opts);
31+
}
32+
```
33+
34+
containerd expects the shim binary to be installed into `$PATH` (as seen by the containerd process) with a binary name like `containerd-shim-myshim-v1` which maps to the `io.containerd.myshim.v1` runtime which would need to be configured in containerd. It (containerd) also supports specifying a path to the shim binary but needs to be configured to do so.
35+
36+
This crate is not tied to any specific wasm engine.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
![runwasi logo](../../art/logo/runwasi_logo_icon.svg)
2+
3+
# containerd-shim-wasm
4+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1+
#![doc = include_str!("../doc/doc.md")]
2+
#![doc(
3+
html_logo_url = "https://raw.githubusercontent.com/containerd/runwasi/e251de3307bbdc8bf3229020ea2ae2711f31aafa/art/logo/runwasi_logo_icon.svg"
4+
)]
5+
16
pub mod sandbox;
7+
28
pub mod services;

crates/containerd-shim-wasm/src/sandbox/cgroups/cgroupv1.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Module for interacting with and applying OCI specs for cgroups v1.
2+
13
use super::super::{Error, Result};
24
use super::{
35
ensure_write_file, find_cgroup_mounts, list_cgroup_controllers, new_mount_iter, safe_join,
@@ -11,6 +13,7 @@ use std::io::prelude::Write;
1113
use std::ops::Not;
1214
use std::path::PathBuf;
1315

16+
// Manager for a cgroup v1 hierarchy.
1417
pub struct CgroupV1 {
1518
path: PathBuf,
1619
controllers: HashMap<String, PathBuf>,

crates/containerd-shim-wasm/src/sandbox/cgroups/cgroupv2.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Module for interacting with and applying OCI specs for cgroups v2.
2+
13
use super::super::{Error, Result};
24
use super::RawFD;
35
use super::{
@@ -11,6 +13,7 @@ use std::fs;
1113
use std::ops::Not;
1214
use std::path::PathBuf;
1315

16+
/// Manages a cgroup v2 heirarchy.
1417
pub struct CgroupV2 {
1518
base: PathBuf,
1619
path: PathBuf,

0 commit comments

Comments
 (0)