Skip to content

Commit

Permalink
Command trigger with arguments
Browse files Browse the repository at this point in the history
Signed-off-by: Radu Matei <[email protected]>
  • Loading branch information
radu-matei committed Apr 5, 2024
1 parent 07c6662 commit 98b7d1e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
19 changes: 19 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions containerd-shim-spin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ spin-trigger-http = { git = "https://github.com/fermyon/spin", tag = "v2.4.0" }
spin-trigger-redis = { git = "https://github.com/fermyon/spin", tag = "v2.4.0" }
# TODO: change to the original repo once https://github.com/fermyon/spin-trigger-sqs/pull/19 is merged.
trigger-sqs = { git = "https://github.com/radu-matei/spin-trigger-sqs", rev = "8e173e5c7023415cd6b29d1f0a37296d2861d5a2" }
trigger-command = { git = "https://github.com/fermyon/spin-trigger-command" , rev = "47ab3d6da7c577cac722b300b8db29c85f80a80f" }
spin-manifest = { git = "https://github.com/fermyon/spin", tag = "v2.4.0" }
spin-loader = { git = "https://github.com/fermyon/spin", tag = "v2.4.0" }
spin-oci = { git = "https://github.com/fermyon/spin", tag = "v2.4.0" }
Expand Down
23 changes: 19 additions & 4 deletions containerd-shim-spin/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::net::SocketAddr;
use std::net::ToSocketAddrs;
use std::path::{Path, PathBuf};
use tokio::runtime::Runtime;
use trigger_command::CommandTrigger;
use trigger_sqs::SqsTrigger;
use url::Url;

Expand Down Expand Up @@ -190,11 +191,13 @@ impl SpinEngine {
let trigger_cmd = trigger_command_for_resolved_app_source(&resolved_app_source)
.with_context(|| format!("Couldn't find trigger executor for {app_source:?}"))?;
let locked_app = self.load_resolved_app_source(resolved_app_source).await?;
self.run_trigger(&trigger_cmd, locked_app, app_source).await
self.run_trigger(ctx, &trigger_cmd, locked_app, app_source)
.await
}

async fn run_trigger(
&self,
ctx: &impl RuntimeContext,
trigger_type: &str,
app: LockedApp,
app_source: AppSource,
Expand Down Expand Up @@ -232,6 +235,17 @@ impl SpinEngine {
info!(" >>> running spin trigger");
sqs_trigger.run(spin_trigger::cli::NoArgs)
}
CommandTrigger::TRIGGER_TYPE => {
let command_trigger: CommandTrigger = self
.build_spin_trigger(working_dir, app, app_source)
.await
.context("failed to build spin trigger")?;

info!(" >>> running spin trigger");
command_trigger.run(trigger_command::CliArgs {
guest_args: ctx.args().to_vec(),
})
}
_ => {
todo!("Only Http, Redis and SQS triggers are currently supported.")
}
Expand Down Expand Up @@ -442,9 +456,10 @@ fn trigger_command_for_resolved_app_source(resolved: &ResolvedAppSource) -> Resu
let trigger_type = resolved.trigger_type()?;

match trigger_type {
RedisTrigger::TRIGGER_TYPE | HttpTrigger::TRIGGER_TYPE | SqsTrigger::TRIGGER_TYPE => {
Ok(trigger_type.to_owned())
}
RedisTrigger::TRIGGER_TYPE
| HttpTrigger::TRIGGER_TYPE
| SqsTrigger::TRIGGER_TYPE
| CommandTrigger::TRIGGER_TYPE => Ok(trigger_type.to_owned()),
_ => {
todo!("Only Http, Redis and SQS triggers are currently supported.")
}
Expand Down

0 comments on commit 98b7d1e

Please sign in to comment.