diff --git a/Cargo.lock b/Cargo.lock index e773786f20..666c856059 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7491,9 +7491,6 @@ dependencies = [ "levenshtein", "nix 0.24.3", "openssl", - "outbound-http", - "outbound-mqtt", - "outbound-redis", "path-absolutize", "rand 0.8.5", "redis 0.24.0", @@ -7520,10 +7517,8 @@ dependencies = [ "spin-plugins", "spin-telemetry", "spin-templates", - "spin-trigger", - "spin-trigger-http", - "spin-trigger-redis", - "spin-variables", + "spin-trigger-http2", + "spin-trigger2", "subprocess", "tempfile", "terminal", @@ -8027,7 +8022,6 @@ dependencies = [ "itertools 0.10.5", "lazy_static 1.4.0", "mime_guess", - "outbound-http", "path-absolutize", "regex", "reqwest 0.11.27", @@ -8165,6 +8159,7 @@ dependencies = [ "spin-factor-outbound-http", "spin-factor-outbound-networking", "spin-factor-sqlite", + "spin-factor-variables", "spin-factor-wasi", "spin-factors", "toml 0.8.14", @@ -8468,11 +8463,13 @@ dependencies = [ "serde_json", "spin-app", "spin-common", + "spin-componentize", "spin-core", "spin-factor-key-value", "spin-factor-outbound-http", "spin-factor-outbound-networking", "spin-factor-sqlite", + "spin-factor-variables", "spin-factor-wasi", "spin-factors", "spin-factors-executor", diff --git a/Cargo.toml b/Cargo.toml index 8497b1e1c3..b69d2c0a3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,9 +35,6 @@ itertools = "0.11.0" lazy_static = "1.4.0" levenshtein = "1.0.5" nix = { version = "0.24", features = ["signal"] } -outbound-http = { path = "crates/outbound-http" } -outbound-redis = { path = "crates/outbound-redis" } -outbound-mqtt = { path = "crates/outbound-mqtt" } spin-key-value = { path = "crates/key-value" } spin-key-value-sqlite = { path = "crates/key-value-sqlite" } path-absolutize = "3.0.11" @@ -65,10 +62,9 @@ spin-telemetry = { path = "crates/telemetry", features = [ "tracing-log-compat", ] } spin-templates = { path = "crates/templates" } -spin-trigger = { path = "crates/trigger" } -spin-trigger-http = { path = "crates/trigger-http" } -spin-trigger-redis = { path = "crates/trigger-redis" } -spin-variables = { path = "crates/variables" } +spin-trigger2 = { path = "crates/trigger2" } +spin-trigger-http2 = { path = "crates/trigger-http2" } +# TODO: spin-trigger-redis = { path = "crates/trigger-redis" } tempfile = "3.8.0" tokio = { version = "1.23", features = ["full"] } @@ -114,12 +110,13 @@ vergen = { version = "^8.2.1", default-features = false, features = [ wit-component = "0.19.0" [features] -default = ["llm"] +# TODO(factors): default = ["llm"] all-tests = ["extern-dependencies-tests"] extern-dependencies-tests = [] -llm = ["spin-trigger-http/llm"] -llm-metal = ["llm", "spin-trigger-http/llm-metal"] -llm-cublas = ["llm", "spin-trigger-http/llm-cublas"] +# TODO(factors): +# llm = ["spin-trigger-http/llm"] +# llm-metal = ["llm", "spin-trigger-http/llm-metal"] +# llm-cublas = ["llm", "spin-trigger-http/llm-cublas"] [workspace] members = [ diff --git a/crates/loader/Cargo.toml b/crates/loader/Cargo.toml index 9173ec0eb9..74680ca8d7 100644 --- a/crates/loader/Cargo.toml +++ b/crates/loader/Cargo.toml @@ -16,7 +16,6 @@ indexmap = { version = "1" } itertools = "0.10.3" lazy_static = "1.4.0" mime_guess = { version = "2.0" } -outbound-http = { path = "../outbound-http", default-features = false } spin-outbound-networking = { path = "../outbound-networking" } path-absolutize = { version = "3.0.11", features = ["use_unix_paths_on_wasm"] } regex = "1.5.4" diff --git a/crates/oci/Cargo.toml b/crates/oci/Cargo.toml index 54e3e03e10..8dcbd55b76 100644 --- a/crates/oci/Cargo.toml +++ b/crates/oci/Cargo.toml @@ -6,7 +6,7 @@ edition = { workspace = true } [dependencies] anyhow = "1.0" -async-compression = "0.4.3" +async-compression = { version = "0.4.3", features = ["gzip", "tokio"] } # Fork with nested async-std dependency bumped to satisfy Windows build; branch/revision is protected async-tar = { git = "https://github.com/vdice/async-tar", rev = "71e037f9652971e7a55b412a8e47a37b06f9c29d" } base64 = "0.21" diff --git a/crates/runtime-config/Cargo.toml b/crates/runtime-config/Cargo.toml index 7a52c51280..989793a877 100644 --- a/crates/runtime-config/Cargo.toml +++ b/crates/runtime-config/Cargo.toml @@ -18,6 +18,7 @@ spin-factor-key-value-azure = { path = "../factor-key-value-azure" } spin-factor-outbound-http = { path = "../factor-outbound-http" } spin-factor-outbound-networking = { path = "../factor-outbound-networking" } spin-factor-sqlite = { path = "../factor-sqlite" } +spin-factor-variables = { path = "../factor-variables" } spin-factor-wasi = { path = "../factor-wasi" } toml = "0.8" diff --git a/crates/runtime-config/src/lib.rs b/crates/runtime-config/src/lib.rs index 12f40c7505..61624133b6 100644 --- a/crates/runtime-config/src/lib.rs +++ b/crates/runtime-config/src/lib.rs @@ -7,6 +7,7 @@ use spin_factor_outbound_http::OutboundHttpFactor; use spin_factor_outbound_networking::runtime_config::spin::SpinTlsRuntimeConfig; use spin_factor_outbound_networking::OutboundNetworkingFactor; use spin_factor_sqlite::runtime_config::spin as sqlite; +use spin_factor_variables::{spin_cli as variables, VariablesFactor}; use spin_factor_sqlite::SqliteFactor; use spin_factor_wasi::WasiFactor; use spin_factors::{ @@ -97,7 +98,9 @@ impl ResolvedRuntimeConfig { Self { sqlite_resolver: sqlite_config_resolver(state_dir) .expect("failed to resolve sqlite runtime config"), - key_value_resolver: Default::default(), + key_value_resolver: key_value_config_resolver(PathBuf::from( + state_dir.unwrap_or(DEFAULT_STATE_DIR), + )), runtime_config: Default::default(), } } @@ -144,6 +147,12 @@ impl FactorRuntimeConfigSource for TomlRuntimeConfigSo } } +impl FactorRuntimeConfigSource for TomlRuntimeConfigSource<'_> { + fn get_runtime_config(&mut self) -> anyhow::Result::RuntimeConfig>> { + Ok(Some(variables::runtime_config_from_toml(self.table.as_ref())?)) + } +} + impl FactorRuntimeConfigSource for TomlRuntimeConfigSource<'_> { fn get_runtime_config(&mut self) -> anyhow::Result> { Ok(None) diff --git a/crates/trigger2/Cargo.toml b/crates/trigger2/Cargo.toml index 656f510354..ab955f5d51 100644 --- a/crates/trigger2/Cargo.toml +++ b/crates/trigger2/Cargo.toml @@ -19,9 +19,11 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" spin-app = { path = "../app" } spin-common = { path = "../common" } +spin-componentize = { path = "../componentize" } spin-core = { path = "../core" } spin-factor-outbound-http = { path = "../factor-outbound-http" } spin-factor-outbound-networking = { path = "../factor-outbound-networking" } +spin-factor-variables = { path = "../factor-variables" } spin-factor-wasi = { path = "../factor-wasi" } spin-factor-key-value = { path = "../factor-key-value" } spin-factor-sqlite = { path = "../factor-sqlite" } diff --git a/crates/trigger2/src/cli.rs b/crates/trigger2/src/cli.rs index 321f1d56dd..db095fd458 100644 --- a/crates/trigger2/src/cli.rs +++ b/crates/trigger2/src/cli.rs @@ -220,15 +220,30 @@ impl FactorsTriggerCommand { // LLmOptions { use_gpu: true }, // ); - // TODO: component loader - struct TodoComponentLoader; - impl ComponentLoader for TodoComponentLoader { + // TODO: port the rest of the component loader logic + struct SimpleComponentLoader; + impl ComponentLoader for SimpleComponentLoader { fn load_component( &mut self, - _engine: &spin_core::wasmtime::Engine, - _component: &spin_factors::AppComponent, + engine: &spin_core::wasmtime::Engine, + component: &spin_factors::AppComponent, ) -> anyhow::Result { - todo!() + let source = component + .source() + .content + .source + .as_ref() + .context("LockedComponentSource missing source field")?; + let path = parse_file_url(source)?; + let bytes = std::fs::read(&path).with_context(|| { + format!( + "failed to read component source from disk at path {}", + quoted_path(&path) + ) + })?; + let component = spin_componentize::componentize_if_necessary(&bytes)?; + spin_core::Component::new(engine, component.as_ref()) + .with_context(|| format!("loading module {}", quoted_path(&path))) } } @@ -243,7 +258,7 @@ impl FactorsTriggerCommand { let configured_app = { let _sloth_guard = warn_if_wasm_build_slothful(); - executor.load_app(app, runtime_config.runtime_config, TodoComponentLoader)? + executor.load_app(app, runtime_config.runtime_config, SimpleComponentLoader)? }; let run_fut = trigger.run(configured_app); diff --git a/crates/trigger2/src/factors.rs b/crates/trigger2/src/factors.rs index 9734718948..c1bd26a39f 100644 --- a/crates/trigger2/src/factors.rs +++ b/crates/trigger2/src/factors.rs @@ -4,6 +4,7 @@ use spin_factor_key_value::KeyValueFactor; use spin_factor_outbound_http::OutboundHttpFactor; use spin_factor_outbound_networking::OutboundNetworkingFactor; use spin_factor_sqlite::SqliteFactor; +use spin_factor_variables::VariablesFactor; use spin_factor_wasi::{spin::SpinFilesMounter, WasiFactor}; use spin_factors::RuntimeFactors; use spin_runtime_config::TomlRuntimeConfigSource; @@ -11,6 +12,7 @@ use spin_runtime_config::TomlRuntimeConfigSource; #[derive(RuntimeFactors)] pub struct TriggerFactors { pub wasi: WasiFactor, + pub variables: VariablesFactor, pub key_value: KeyValueFactor, pub outbound_networking: OutboundNetworkingFactor, pub outbound_http: OutboundHttpFactor, @@ -27,6 +29,7 @@ impl TriggerFactors { let files_mounter = SpinFilesMounter::new(working_dir, allow_transient_writes); Self { wasi: WasiFactor::new(files_mounter), + variables: VariablesFactor::default(), key_value: KeyValueFactor::new(default_key_value_label_resolver), outbound_networking: OutboundNetworkingFactor, outbound_http: OutboundHttpFactor, diff --git a/src/bin/spin.rs b/src/bin/spin.rs index 481f48d0c3..42e6539dcb 100644 --- a/src/bin/spin.rs +++ b/src/bin/spin.rs @@ -15,10 +15,10 @@ use spin_cli::commands::{ watch::WatchCommand, }; use spin_cli::{build_info::*, subprocess::ExitStatusError}; -use spin_trigger::cli::help::HelpArgsOnlyTrigger; -use spin_trigger::cli::TriggerExecutorCommand; -use spin_trigger_http::HttpTrigger; -use spin_trigger_redis::RedisTrigger; +use spin_trigger2::cli::help::HelpArgsOnlyTrigger; +use spin_trigger2::cli::FactorsTriggerCommand; +use spin_trigger_http2::HttpTrigger; +// TODO(factors): use spin_trigger_redis::RedisTrigger; #[tokio::main] async fn main() { @@ -136,10 +136,10 @@ enum SpinApp { #[derive(Subcommand)] enum TriggerCommands { - Http(TriggerExecutorCommand), - Redis(TriggerExecutorCommand), + Http(FactorsTriggerCommand), + // TODO(factors): Redis(TriggerExecutorCommand), #[clap(name = spin_cli::HELP_ARGS_ONLY_TRIGGER_TYPE, hide = true)] - HelpArgsOnly(TriggerExecutorCommand), + HelpArgsOnly(FactorsTriggerCommand), } impl SpinApp { @@ -155,7 +155,7 @@ impl SpinApp { Self::Registry(cmd) => cmd.run().await, Self::Build(cmd) => cmd.run().await, Self::Trigger(TriggerCommands::Http(cmd)) => cmd.run().await, - Self::Trigger(TriggerCommands::Redis(cmd)) => cmd.run().await, + // TODO(factors): Self::Trigger(TriggerCommands::Redis(cmd)) => cmd.run().await, Self::Trigger(TriggerCommands::HelpArgsOnly(cmd)) => cmd.run().await, Self::Plugins(cmd) => cmd.run().await, Self::External(cmd) => execute_external_subcommand(cmd, app).await, diff --git a/src/commands/up.rs b/src/commands/up.rs index 87f5d61cf3..1b8afd1068 100644 --- a/src/commands/up.rs +++ b/src/commands/up.rs @@ -15,7 +15,7 @@ use spin_app::locked::LockedApp; use spin_common::ui::quoted_path; use spin_loader::FilesMountStrategy; use spin_oci::OciLoader; -use spin_trigger::cli::{LaunchMetadata, SPIN_LOCAL_APP_DIR, SPIN_LOCKED_URL, SPIN_WORKING_DIR}; +use spin_trigger2::cli::{LaunchMetadata, SPIN_LOCAL_APP_DIR, SPIN_LOCKED_URL, SPIN_WORKING_DIR}; use tempfile::TempDir; use crate::opts::*;