Skip to content

Commit

Permalink
factors: Get spin up working
Browse files Browse the repository at this point in the history
Signed-off-by: Lann Martin <lann.martin@fermyon.com>
  • Loading branch information
lann committed Aug 19, 2024
1 parent acaac05 commit d0f1873
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 38 deletions.
13 changes: 5 additions & 8 deletions Cargo.lock

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

19 changes: 8 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"] }
Expand Down Expand Up @@ -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 = [
Expand Down
1 change: 0 additions & 1 deletion crates/loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion crates/oci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions crates/runtime-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
11 changes: 10 additions & 1 deletion crates/runtime-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -97,7 +98,9 @@ impl<T: Default> ResolvedRuntimeConfig<T> {
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(),
}
}
Expand Down Expand Up @@ -144,6 +147,12 @@ impl FactorRuntimeConfigSource<OutboundNetworkingFactor> for TomlRuntimeConfigSo
}
}

impl FactorRuntimeConfigSource<VariablesFactor> for TomlRuntimeConfigSource<'_> {
fn get_runtime_config(&mut self) -> anyhow::Result<Option<<VariablesFactor as spin_factors::Factor>::RuntimeConfig>> {
Ok(Some(variables::runtime_config_from_toml(self.table.as_ref())?))
}
}

impl FactorRuntimeConfigSource<WasiFactor> for TomlRuntimeConfigSource<'_> {
fn get_runtime_config(&mut self) -> anyhow::Result<Option<()>> {
Ok(None)
Expand Down
2 changes: 2 additions & 0 deletions crates/trigger2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
29 changes: 22 additions & 7 deletions crates/trigger2/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,30 @@ impl<T: Trigger> FactorsTriggerCommand<T> {
// 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<spin_core::Component> {
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)))
}
}

Expand All @@ -243,7 +258,7 @@ impl<T: Trigger> FactorsTriggerCommand<T> {

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);
Expand Down
3 changes: 3 additions & 0 deletions crates/trigger2/src/factors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ 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;

#[derive(RuntimeFactors)]
pub struct TriggerFactors {
pub wasi: WasiFactor,
pub variables: VariablesFactor,
pub key_value: KeyValueFactor,
pub outbound_networking: OutboundNetworkingFactor,
pub outbound_http: OutboundHttpFactor,
Expand All @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions src/bin/spin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -136,10 +136,10 @@ enum SpinApp {

#[derive(Subcommand)]
enum TriggerCommands {
Http(TriggerExecutorCommand<HttpTrigger>),
Redis(TriggerExecutorCommand<RedisTrigger>),
Http(FactorsTriggerCommand<HttpTrigger>),
// TODO(factors): Redis(TriggerExecutorCommand<RedisTrigger>),
#[clap(name = spin_cli::HELP_ARGS_ONLY_TRIGGER_TYPE, hide = true)]
HelpArgsOnly(TriggerExecutorCommand<HelpArgsOnlyTrigger>),
HelpArgsOnly(FactorsTriggerCommand<HelpArgsOnlyTrigger>),
}

impl SpinApp {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down

0 comments on commit d0f1873

Please sign in to comment.