Skip to content

Commit

Permalink
Support for the wait command
Browse files Browse the repository at this point in the history
Signed-off-by: utam0k <[email protected]>
  • Loading branch information
utam0k committed Mar 1, 2023
1 parent a077453 commit ae4cd5c
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 87 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ jobs:
- name: "check cgroup version"
run: "mount | grep cgroup"
- uses: actions/checkout@v3
with:
submodules: true
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Setup OCI runtime build env
run: |
sudo apt -y update
sudo apt install -y pkg-config libsystemd-dev libdbus-glib-1-dev build-essential libelf-dev libseccomp-dev libclang-dev
- name: Setup WasmEdge build env
run: |
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- --version=0.11.2
Expand All @@ -32,10 +38,8 @@ jobs:
command: build
args: --all --verbose
- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
args: --all --verbose
run: |
sudo -E LD_LIBRARY_PATH=/home/runner/.wasmedge/lib /home/runner/.cargo/bin/cargo test --all --verbose
e2e:
needs: [build]
Expand Down
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "youki"]
path = youki
url = [email protected]:utam0k/youki.git
branch = runwasi
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ readme = "README.md"
repository = "https://github.com/containerd/runwasi"
homepage = "https://github.com/containerd/runwasi"


[workspace.dependencies]
anyhow = "1.0"
serde = "1.0"
Expand All @@ -32,7 +31,6 @@ thiserror = "1.0"
libc = "0.2.138"
oci-spec = { version = "^0.5.5", features = ["runtime"] }
sha256 = "1.1"
libcontainer = { path = "youki/crates/libcontainer" }

[profile.release]
panic = "abort"
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ENV WASMEDGE_INCLUDE_DIR=/root/.wasmedge/include
ENV WASMEDGE_LIB_DIR=/root/.wasmedge/lib
ENV LD_LIBRARY_PATH=/root/.wasmedge/lib
RUN xx-apt-get install -y gcc g++ libc++6-dev zlib1g
RUN xx-apt-get install -y pkg-config libsystemd-dev libdbus-glib-1-dev build-essential libelf-dev libseccomp-dev libclang-dev
RUN rustup target add $(xx-info march)-unknown-$(xx-info os)-$(xx-info libc)
RUN <<EOT
set -ex
Expand Down
14 changes: 7 additions & 7 deletions crates/containerd-shim-wasm/src/sandbox/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ where

pub trait Instance {
type E: Send + Sync + Clone;
fn new(id: String, cfg: Option<&InstanceConfig<Self::E>>) -> Self;
fn new(id: String, rootdir: String, cfg: Option<&InstanceConfig<Self::E>>) -> Self;
fn start(&self) -> Result<u32, Error>;
fn kill(&self, signal: u32) -> Result<(), Error>;
fn delete(&self) -> Result<(), Error>;
Expand All @@ -95,7 +95,7 @@ pub struct Nop {

impl Instance for Nop {
type E = ();
fn new(_id: String, _cfg: Option<&InstanceConfig<Self::E>>) -> Self {
fn new(_id: String, _rootdir: String, _cfg: Option<&InstanceConfig<Self::E>>) -> Self {
Nop {
exit_code: Arc::new((Mutex::new(None), Condvar::new())),
}
Expand Down Expand Up @@ -152,7 +152,7 @@ mod noptests {

#[test]
fn test_nop_kill_sigkill() -> Result<(), Error> {
let nop = Arc::new(Nop::new("".to_string(), None));
let nop = Arc::new(Nop::new("".to_string(), "".into(), None));
let (tx, rx) = channel();

let n = nop.clone();
Expand All @@ -169,7 +169,7 @@ mod noptests {

#[test]
fn test_nop_kill_sigterm() -> Result<(), Error> {
let nop = Arc::new(Nop::new("".to_string(), None));
let nop = Arc::new(Nop::new("".to_string(), "".into(), None));
let (tx, rx) = channel();

let n = nop.clone();
Expand All @@ -186,7 +186,7 @@ mod noptests {

#[test]
fn test_nop_kill_sigint() -> Result<(), Error> {
let nop = Arc::new(Nop::new("".to_string(), None));
let nop = Arc::new(Nop::new("".to_string(), "".into(), None));
let (tx, rx) = channel();

let n = nop.clone();
Expand All @@ -203,7 +203,7 @@ mod noptests {

#[test]
fn test_op_kill_other() -> Result<(), Error> {
let nop = Nop::new("".to_string(), None);
let nop = Arc::new(Nop::new("".to_string(), "".into(), None));

let err = nop.kill(SIGHUP as u32).unwrap_err();
match err {
Expand All @@ -216,7 +216,7 @@ mod noptests {

#[test]
fn test_nop_delete_after_create() {
let nop = Nop::new("".to_string(), None);
let nop = Arc::new(Nop::new("".to_string(), "".into(), None));
nop.delete().unwrap();
}
}
Expand Down
10 changes: 8 additions & 2 deletions crates/containerd-shim-wasm/src/sandbox/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ use nix::unistd::mkdir;
use oci_spec::runtime;
use ttrpc::context::Context;

static CONTAINER_ROOT_DIR: &str = "/var/run/runwasi";

type InstanceDataStatus = (Mutex<Option<(u32, DateTime<Utc>)>>, Condvar);

struct InstanceData<T: Instance<E = E>, E>
Expand Down Expand Up @@ -732,7 +734,7 @@ where
let cfg = InstanceConfig::new(self.engine.clone());
InstanceData {
instance: None,
base: Some(Nop::new(id, None)),
base: Some(Nop::new(id, CONTAINER_ROOT_DIR.into(), None)),
cfg,
pid: RwLock::new(None),
status: Arc::new((Mutex::new(None), Condvar::new())),
Expand Down Expand Up @@ -929,7 +931,11 @@ where
self.instances.write().unwrap().insert(
req.get_id().to_string(),
Arc::new(InstanceData {
instance: Some(T::new(req.get_id().to_string(), Some(&builder))),
instance: Some(T::new(
req.get_id().to_string(),
CONTAINER_ROOT_DIR.into(),
Some(&builder),
)),
base: None,
cfg: builder,
pid: RwLock::new(None),
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmedge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ thiserror = { workspace = true }
serde_json = { workspace = true }
nix = { workspace = true }
libc = { workspace = true }
libcontainer = { workspace = true }
libcontainer = { path = "../../youki/crates/libcontainer" }

[dev-dependencies]
tempfile = "3.0"
Expand Down
14 changes: 10 additions & 4 deletions crates/wasmedge/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,17 @@ impl Executor for WasmEdgeExecutor {
}

let ins = vm.named_module("main")?;
ins.func("_start")
.expect("Not found '_start' func in the 'main' module instance")
.call(&mut vm, params!())?;

Ok(())
// TODO: How to get exit code?
// This was relatively straight forward in go, but wasi and wasmtime are totally separate things in rust
match ins
.func("_start")
.expect("Not found '_start' func in the 'main' module instance")
.call(&mut vm, params!())
{
Ok(_) => std::process::exit(0),
Err(_) => std::process::exit(137),
};
}

fn can_handle(&self, _spec: &Spec) -> Result<bool> {
Expand Down
Loading

0 comments on commit ae4cd5c

Please sign in to comment.