diff --git a/Makefile b/Makefile index c78c10c08..52e08462b 100644 --- a/Makefile +++ b/Makefile @@ -120,6 +120,7 @@ test/k3s: target/wasm32-wasi/$(TARGET)/img.tar bin/wasmedge bin/k3s sudo bin/k3s kubectl apply -f test/k8s/deploy.yaml sudo bin/k3s kubectl wait deployment wasi-demo --for condition=Available=True --timeout=90s && \ sudo bin/k3s kubectl get pods -o wide + sudo bin/k3s kubectl logs deployments/wasi-demo .PHONY: test/k3s/clean test/k3s/clean: bin/wasmedge/clean bin/k3s/clean diff --git a/crates/containerd-shim-wasmedge/src/executor.rs b/crates/containerd-shim-wasmedge/src/executor.rs index fbfd06b34..ce38d62f8 100644 --- a/crates/containerd-shim-wasmedge/src/executor.rs +++ b/crates/containerd-shim-wasmedge/src/executor.rs @@ -5,8 +5,8 @@ use oci_spec::runtime::Spec; use libc::{STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO}; use libcontainer::workload::{Executor, ExecutorError}; +use log::debug; use std::os::unix::io::RawFd; - use wasmedge_sdk::{ config::{CommonConfigOptions, ConfigBuilder, HostRegistrationConfigOptions}, params, VmBuilder, @@ -42,9 +42,15 @@ impl Executor for WasmEdgeExecutor { .ok_or_else(|| anyhow::Error::msg("Not found wasi module")) .map_err(|err| ExecutorError::Execution(err.into()))?; - let module_args = oci::get_module_args(spec); + let args = oci::get_module_args(spec); + let mut module_args = None; + if !args.is_empty() { + module_args = Some(args.iter().map(|s| s as &str).collect()) + } + + debug!("module args: {:?}", module_args); wasi_module.initialize( - Some(module_args.iter().map(|s| s as &str).collect()), + module_args, Some(envs.iter().map(|s| s as &str).collect()), None, ); @@ -63,7 +69,7 @@ impl Executor for WasmEdgeExecutor { }; let vm = vm - .register_module_from_file("main", module_name) + .register_module_from_file("main", module_name.clone()) .map_err(|err| ExecutorError::Execution(err))?; if let Some(stdin) = self.stdin { @@ -79,6 +85,7 @@ impl Executor for WasmEdgeExecutor { let _ = dup2(stderr, STDERR_FILENO); } + debug!("running {:?} with method {}", module_name, method); match vm.run_func(Some("main"), method, params!()) { Ok(_) => std::process::exit(0), Err(_) => std::process::exit(137), diff --git a/crates/wasi-demo-app/src/main.rs b/crates/wasi-demo-app/src/main.rs index 36c5e2730..d3d0151d0 100644 --- a/crates/wasi-demo-app/src/main.rs +++ b/crates/wasi-demo-app/src/main.rs @@ -4,7 +4,11 @@ fn main() { let args: Vec<_> = env::args().collect(); let mut cmd = "daemon"; if !args.is_empty() { - cmd = &args[0]; + // temporary work around for wasmedge bug + // https://github.com/WasmEdge/wasmedge-rust-sdk/issues/10 + if !(args.len() == 1 && args[0].is_empty()) { + cmd = &args[0]; + } } match cmd {