Skip to content

Commit 36b2365

Browse files
committed
feat(trigger/command): implement trigger command
This commit implements support for running "command" triggers in the shim, based on https://github.com/fermyon/spin-trigger-command. Specifically, it runs a WASI command component to completion, with support for both classical WASI preview 1 core modules and WASI preview 2 CLI components. Finally, this supports passing Kubernetes arguments: ```yaml - name: spin-command image: <command-component-that-prints-args> args: ["these", "are", "some", "args"] ``` These arguments are passed in the component and can be read at runtime using WASI. Signed-off-by: Radu Matei <[email protected]>
1 parent 52fa96a commit 36b2365

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

Cargo.lock

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

containerd-shim-spin/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ spin-trigger = { git = "https://github.com/fermyon/spin", tag = "v2.4.2", featur
2222
spin-trigger-http = { git = "https://github.com/fermyon/spin", tag = "v2.4.2" }
2323
spin-trigger-redis = { git = "https://github.com/fermyon/spin", tag = "v2.4.2" }
2424
trigger-sqs = { git = "https://github.com/fermyon/spin-trigger-sqs", rev = "dbfc599560ab54e759bfa586fe7315848f00a7f6" }
25+
trigger-command = { git = "https://github.com/fermyon/spin-trigger-command" , rev = "af3cf1148573ab10e1e819b66cd920a04a789e50" }
2526
spin-manifest = { git = "https://github.com/fermyon/spin", tag = "v2.4.2" }
2627
spin-loader = { git = "https://github.com/fermyon/spin", tag = "v2.4.2" }
2728
spin-oci = { git = "https://github.com/fermyon/spin", tag = "v2.4.2" }

containerd-shim-spin/src/engine.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::net::SocketAddr;
2121
use std::net::ToSocketAddrs;
2222
use std::path::{Path, PathBuf};
2323
use tokio::runtime::Runtime;
24+
use trigger_command::CommandTrigger;
2425
use trigger_sqs::SqsTrigger;
2526
use url::Url;
2627

@@ -190,11 +191,13 @@ impl SpinEngine {
190191
let trigger_cmd = trigger_command_for_resolved_app_source(&resolved_app_source)
191192
.with_context(|| format!("Couldn't find trigger executor for {app_source:?}"))?;
192193
let locked_app = self.load_resolved_app_source(resolved_app_source).await?;
193-
self.run_trigger(&trigger_cmd, locked_app, app_source).await
194+
self.run_trigger(ctx, &trigger_cmd, locked_app, app_source)
195+
.await
194196
}
195197

196198
async fn run_trigger(
197199
&self,
200+
ctx: &impl RuntimeContext,
198201
trigger_type: &str,
199202
app: LockedApp,
200203
app_source: AppSource,
@@ -232,6 +235,17 @@ impl SpinEngine {
232235
info!(" >>> running spin trigger");
233236
sqs_trigger.run(spin_trigger::cli::NoArgs)
234237
}
238+
CommandTrigger::TRIGGER_TYPE => {
239+
let command_trigger: CommandTrigger = self
240+
.build_spin_trigger(working_dir, app, app_source)
241+
.await
242+
.context("failed to build spin trigger")?;
243+
244+
info!(" >>> running spin trigger");
245+
command_trigger.run(trigger_command::CliArgs {
246+
guest_args: ctx.args().to_vec(),
247+
})
248+
}
235249
_ => {
236250
todo!("Only Http, Redis and SQS triggers are currently supported.")
237251
}
@@ -442,11 +456,12 @@ fn trigger_command_for_resolved_app_source(resolved: &ResolvedAppSource) -> Resu
442456
let trigger_type = resolved.trigger_type()?;
443457

444458
match trigger_type {
445-
RedisTrigger::TRIGGER_TYPE | HttpTrigger::TRIGGER_TYPE | SqsTrigger::TRIGGER_TYPE => {
446-
Ok(trigger_type.to_owned())
447-
}
459+
RedisTrigger::TRIGGER_TYPE
460+
| HttpTrigger::TRIGGER_TYPE
461+
| SqsTrigger::TRIGGER_TYPE
462+
| CommandTrigger::TRIGGER_TYPE => Ok(trigger_type.to_owned()),
448463
_ => {
449-
todo!("Only Http, Redis and SQS triggers are currently supported.")
464+
todo!("Only Http, Redis, SQS, and command triggers are currently supported.")
450465
}
451466
}
452467
}

0 commit comments

Comments
 (0)