Skip to content

Commit

Permalink
Respond to feedback
Browse files Browse the repository at this point in the history
Signed-off-by: James Sturtevant <[email protected]>
  • Loading branch information
jsturtevant committed Nov 27, 2023
1 parent 1f5d6f3 commit 7244408
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
17 changes: 11 additions & 6 deletions crates/containerd-shim-wasm/src/container/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions crates/containerd-shim-wasmtime/src/instance.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")?;
Expand Down

0 comments on commit 7244408

Please sign in to comment.