Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix annotation deserializing for the Wasi and Wcgi runners #3715

Merged
merged 4 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

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

13 changes: 10 additions & 3 deletions lib/wasi/src/runners/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,17 @@ impl crate::runners::Runner for WasiRunner {
.starts_with(webc::metadata::annotations::WASI_RUNNER_URI))
}

#[tracing::instrument(skip(self, command, container))]
fn run_command(
&mut self,
command_name: &str,
command: &Command,
container: &WapmContainer,
) -> Result<Self::Output, Error> {
let wasi = command
.get_annotation("wasi")?
.unwrap_or_else(|| Wasi::new(command_name));
let Annotations { wasi } = command
.get_annotation(webc::metadata::annotations::WASI_RUNNER_URI)?
.unwrap_or_default();
let wasi = wasi.unwrap_or_else(|| Wasi::new(command_name));
let atom_name = &wasi.atom;
let atom = container
.get_atom(atom_name)
Expand All @@ -167,3 +169,8 @@ impl crate::runners::Runner for WasiRunner {
Ok(())
}
}

#[derive(Default, Debug, serde::Deserialize)]
struct Annotations {
wasi: Option<Wasi>,
}
10 changes: 9 additions & 1 deletion lib/wasi/src/runners/wcgi/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ impl Handler {
tracing::debug!("Creating the WebAssembly instance");

let mut request_specific_env = HashMap::new();

if self.dialect == CgiDialect::Rfc3875 {
// HACK(Michael-F-Bryan): this belongs in the wcgi-host crate
request_specific_env.insert("SCRIPT_NAME".to_string(), parts.uri.to_string());
}
self.dialect
.prepare_environment_variables(parts, &mut request_specific_env);

Expand All @@ -59,7 +64,10 @@ impl Handler {

let module = self.module.clone();

tracing::debug!("Calling into the WCGI executable");
tracing::debug!(
dialect=%self.dialect,
"Calling into the WCGI executable",
);

let done = self
.task_manager
Expand Down
25 changes: 17 additions & 8 deletions lib/wasi/src/runners/wcgi/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,20 @@ impl WcgiRunner {

#[tracing::instrument(skip(self, ctx))]
fn run(&mut self, command_name: &str, ctx: &RunnerContext<'_>) -> Result<(), Error> {
let wasi: Wasi = ctx
let key = webc::metadata::annotations::WCGI_RUNNER_URI;
let Annotations { wasi, wcgi } = ctx
.command()
.get_annotation("wasi")
.context("Unable to retrieve the WASI metadata")?
.unwrap_or_else(|| Wasi::new(command_name));
.get_annotation(key)
.with_context(|| format!("Unable to deserialize the \"{key}\" annotations"))?
.unwrap_or_default();

let wasi = wasi.unwrap_or_else(|| Wasi::new(command_name));

let module = self
.load_module(&wasi, ctx)
.context("Couldn't load the module")?;

let handler = self.create_handler(module, &wasi, ctx)?;
let handler = self.create_handler(module, &wasi, &wcgi, ctx)?;
let task_manager = Arc::clone(&handler.task_manager);
let callbacks = Arc::clone(&self.config.callbacks);

Expand Down Expand Up @@ -126,11 +129,10 @@ impl WcgiRunner {
&self,
module: Module,
wasi: &Wasi,
wcgi: &Wcgi,
ctx: &RunnerContext<'_>,
) -> Result<Handler, Error> {
let Wcgi { dialect, .. } = ctx.command().get_annotation("wcgi")?.unwrap_or_default();

let dialect = match dialect {
let dialect = match &wcgi.dialect {
Some(d) => d.parse().context("Unable to parse the CGI dialect")?,
None => CgiDialect::Wcgi,
};
Expand Down Expand Up @@ -343,6 +345,13 @@ impl Default for Config {
}
}

#[derive(Debug, Default, serde::Deserialize)]
struct Annotations {
wasi: Option<Wasi>,
#[serde(default)]
wcgi: Wcgi,
}

/// Callbacks that are triggered at various points in the lifecycle of a runner
/// and any WebAssembly instances it may start.
pub trait Callbacks: Send + Sync + 'static {
Expand Down