From 724440848ca6697b91120feb15fee291eac0ac09 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Mon, 27 Nov 2023 19:37:59 +0000 Subject: [PATCH] Respond to feedback Signed-off-by: James Sturtevant --- .../src/container/context.rs | 17 +++++++++++------ crates/containerd-shim-wasmtime/src/instance.rs | 12 +++++++++--- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/crates/containerd-shim-wasm/src/container/context.rs b/crates/containerd-shim-wasm/src/container/context.rs index 69f0e472a..ae6c5cc47 100644 --- a/crates/containerd-shim-wasm/src/container/context.rs +++ b/crates/containerd-shim-wasm/src/container/context.rs @@ -10,14 +10,19 @@ pub trait RuntimeContext { // path to the entrypoint executable. fn args(&self) -> &[String]; - // ctx.wasi_entrypoint() returns a `WasiEntrypoint` with the path to the module to use - // as an entrypoint and the name of the exported function to call, obtained from the + // ctx.entrypoint() returns a `Entrypoint` with the following fields obtained from the first argument in the OCI spec for entrypoint: + // - `arg0` - raw entrypoint from the OCI spec + // - `name` - provided as the file name of the module in the entrypoint without the extension + // - `func` - name of the exported function to call, obtained from the // arguments on process OCI spec. - // The girst argument in the spec is specified as `path#func` where `func` is optional + // - `Source` - either a `File(PathBuf)` or `Oci(WasmLayer)`. When a `File` source the `PathBuf`` is provided by entrypoint in OCI spec. + // If the image contains custom OCI Wasm layers, the source is provided as an array of `WasmLayer` structs. + // + // The first argument in the OCI spec for entrypoint is specified as `path#func` where `func` is optional // and defaults to _start, e.g.: - // "/app/app.wasm#entry" -> { path: "/app/app.wasm", func: "entry" } - // "my_module.wat" -> { path: "my_module.wat", func: "_start" } - // "#init" -> { path: "", func: "init" } + // "/app/app.wasm#entry" -> { source: File("/app/app.wasm"), func: "entry", name: "Some(app)", arg0: "/app/app.wasm#entry" } + // "my_module.wat" -> { source: File("my_module.wat"), func: "_start", name: "Some(my_module)", arg0: "my_module.wat" } + // "#init" -> { source: File(""), func: "init", name: None, arg0: "#init" } fn entrypoint(&self) -> Entrypoint; // the platform for the container using the struct defined on the OCI spec definition diff --git a/crates/containerd-shim-wasmtime/src/instance.rs b/crates/containerd-shim-wasmtime/src/instance.rs index ec05b7443..9e0bd9bc9 100644 --- a/crates/containerd-shim-wasmtime/src/instance.rs +++ b/crates/containerd-shim-wasmtime/src/instance.rs @@ -1,6 +1,6 @@ use anyhow::{bail, Context, Result}; use containerd_shim_wasm::container::{ - Engine, Instance, PathResolve, RuntimeContext, Source, Stdio, + Engine, Entrypoint, Instance, PathResolve, RuntimeContext, Source, Stdio, }; use wasi_common::I32Exit; use wasmtime::{Linker, Module, Store}; @@ -34,8 +34,15 @@ impl Engine for WasmtimeEngine { log::info!("building wasi context"); let wctx = wasi_builder.build(); + let Entrypoint { + source, + func, + arg0: _, + name: _, + } = ctx.entrypoint(); + log::info!("wasi context ready"); - let module = match ctx.entrypoint().source { + let module = match source { Source::File(path) => { log::info!("loading module from path {path:?}"); let path = path @@ -63,7 +70,6 @@ impl Engine for WasmtimeEngine { let instance: wasmtime::Instance = linker.instantiate(&mut store, &module)?; log::info!("getting start function"); - let func = ctx.entrypoint().func; let start_func = instance .get_func(&mut store, &func) .context("module does not have a WASI start function")?;