Skip to content

Commit

Permalink
chore: use the Engine API from containerd-shim-wasm crate (#148)
Browse files Browse the repository at this point in the history
* chore: use the Engine API from containerd-shim-wasm crate

This commits updates to use the latest API from the `containerd-shim-wasm` crate.
It follows the PR containerd/runwasi#293

Signed-off-by: jiaxiao zhou <jiazho@microsoft.com>
Co-authored-by: Jorge Prendes <jorge.prendes@gmail.com>
  • Loading branch information
Mossaka and jprendes authored Sep 21, 2023
1 parent 6b343da commit ec90462
Show file tree
Hide file tree
Showing 22 changed files with 256 additions and 1,017 deletions.
88 changes: 0 additions & 88 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ homepage = "https://github.com/deislabs/containerd-wasm-shims"
[workspace]
resolver = "2"
members = [
"utils",
"tests"
]
29 changes: 8 additions & 21 deletions containerd-shim-lunatic-v1/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 2 additions & 9 deletions containerd-shim-lunatic-v1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@ edition = "2021"

[dependencies]
containerd-shim = "0.5.0"
containerd-shim-wasm = { git = "https://github.com/containerd/runwasi", rev = "7e978edeaf34b54efb895738357c805cf888b76d", features = ["cgroupsv2"] }
libcontainer = { git = "https://github.com/containers/youki", rev = "09e67372a892f22a89eeef62ff429c3cbcac6d41", features = ["v1","v2"], default-features = false }
nix = "0.26.2"
serde = "1.0.183"
serde_json = "1.0.104"
thiserror = "1.0.44"
containerd-shim-wasm = { git = "https://github.com/containerd/runwasi", rev = "4d212b968d24d42a27952e8b04979382b543a613", features = ["cgroupsv2"] }
log = "~0.4"
libc = "0.2.147"
anyhow = "1.0.72"
chrono = { version = "0.4.26", features = ["std"] }
lunatic-process = { git = "https://github.com/lunatic-solutions/lunatic", tag = "v0.13.2"}
Expand All @@ -23,8 +17,7 @@ lunatic-distributed = { git = "https://github.com/lunatic-solutions/lunatic", ta
lunatic-runtime = { git = "https://github.com/lunatic-solutions/lunatic", tag = "v0.13.2"}
clap = { version = "4.0", features = ["cargo", "derive"] }
tokio = "1.30.0"
oci-spec = "0.6.2"
utils = { path = "../utils" }


# https://github.com/sfackler/rust-openssl/issues/603#issuecomment-822619837
openssl = { version = "0.10", features = ["vendored"] }
Expand Down
68 changes: 68 additions & 0 deletions containerd-shim-lunatic-v1/src/engine.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use anyhow::{Context, Result};
use std::path::PathBuf;
use std::sync::Arc;
use tokio::runtime::Runtime;

use containerd_shim_wasm::container::{Engine, RuntimeContext, Stdio};
use lunatic_process::{
env::{Environments, LunaticEnvironments},
runtimes,
};

use crate::common::{run_wasm, RunWasm};

#[derive(Clone, Default)]
pub struct LunaticEngine;

impl Engine for LunaticEngine {
fn name() -> &'static str {
"lunatic"
}

fn run_wasi(&self, ctx: &impl RuntimeContext, stdio: Stdio) -> Result<i32> {
log::info!("setting up wasi");
stdio.redirect()?;
let cmd = ctx.entrypoint().context("no cmd provided")?;
let rt = Runtime::new().context("failed to create runtime")?;
rt.block_on(exec(cmd.to_owned()))?;
Ok(0)
}
}

async fn exec(cmd: PathBuf) -> Result<()> {
log::info!(" >>> lunatic wasm binary: {:?}", cmd);
// Create wasmtime runtime
let wasmtime_config = runtimes::wasmtime::default_config();
let runtime = runtimes::wasmtime::WasmtimeRuntime::new(&wasmtime_config)?;
let envs = Arc::new(LunaticEnvironments::default());

let env = envs.create(1).await;
run_wasm(RunWasm {
path: cmd,
wasm_args: vec![],
dir: vec![],
runtime,
envs,
env,
distributed: None,
})
.await
}

#[cfg(test)]
mod tests {
use crate::engine::exec;

#[tokio::test]
async fn test() {
if let Err(error) = exec(
"../images/lunatic/target/wasm32-wasi/release/wasi-hello-world.wasm"
.to_string()
.into(),
)
.await
{
panic!("Problem opening the file: {:?}", error)
}
}
}
93 changes: 0 additions & 93 deletions containerd-shim-lunatic-v1/src/executor.rs

This file was deleted.

Loading

0 comments on commit ec90462

Please sign in to comment.