-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use the Engine API from containerd-shim-wasm crate (#148)
* 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
Showing
22 changed files
with
256 additions
and
1,017 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.