diff --git a/Cargo.lock b/Cargo.lock index 7b807bc8e..f8721219d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4656,6 +4656,7 @@ dependencies = [ "semver 1.0.16", "serde", "sha2 0.10.6", + "spin-loader", "tempfile", "tokio", "toml 0.5.11", diff --git a/crates/templates/Cargo.toml b/crates/templates/Cargo.toml index 518377b55..d6c57bf28 100644 --- a/crates/templates/Cargo.toml +++ b/crates/templates/Cargo.toml @@ -26,6 +26,7 @@ regex = "1.5.4" semver = "1.0" serde = { version = "1.0", features = [ "derive" ] } sha2 = "0.10.1" +spin-loader = { path = "../loader" } tempfile = "3.3.0" tokio = { version = "1.23", features = [ "fs", "process", "rt", "macros" ] } toml = "0.5" diff --git a/crates/templates/src/app_info.rs b/crates/templates/src/app_info.rs index ba6d0aca7..57a22d4e5 100644 --- a/crates/templates/src/app_info.rs +++ b/crates/templates/src/app_info.rs @@ -2,18 +2,36 @@ // interest to the template system. spin_loader does too // much processing to fit our needs here. -use std::path::{Path, PathBuf}; - use anyhow::Context; +use spin_loader::local::config::FixedStringVersion; +use std::path::{Path, PathBuf}; use crate::store::TemplateLayout; #[derive(Debug, serde::Deserialize)] -#[serde(tag = "spin_version")] +#[serde(untagged)] pub(crate) enum AppInfo { - /// A manifest with API version 1. - #[serde(rename = "1")] - V1(AppInfoV1), + V1Old { + #[allow(dead_code)] + spin_version: FixedStringVersion<1>, + #[serde(flatten)] + manifest: AppInfoV1, + }, + V1New { + #[allow(dead_code)] + spin_manifest_version: FixedStringVersion<1>, + #[serde(flatten)] + manifest: AppInfoV1, + }, +} + +impl AppInfo { + pub fn as_v1(&self) -> &AppInfoV1 { + match self { + AppInfo::V1New { manifest, .. } => manifest, + AppInfo::V1Old { manifest, .. } => manifest, + } + } } #[derive(Debug, serde::Deserialize)] @@ -28,12 +46,12 @@ pub(crate) struct TriggerInfo { } impl AppInfo { - pub(crate) fn from_layout(layout: &TemplateLayout) -> Option> { + pub fn from_layout(layout: &TemplateLayout) -> Option> { Self::layout_manifest_path(layout) .map(|manifest_path| Self::from_existent_file(&manifest_path)) } - pub(crate) fn from_file(manifest_path: &Path) -> Option> { + pub fn from_file(manifest_path: &Path) -> Option> { if manifest_path.exists() { Some(Self::from_existent_file(manifest_path)) } else { @@ -56,9 +74,7 @@ impl AppInfo { toml::from_str(&manifest_text).context("Can't parse manifest file") } - pub(crate) fn trigger_type(&self) -> &str { - match self { - Self::V1(info) => &info.trigger.trigger_type, - } + pub fn trigger_type(&self) -> &str { + &self.as_v1().trigger.trigger_type } } diff --git a/examples/config-rust/spin.toml b/examples/config-rust/spin.toml index 7b41ae80b..114b1c2d3 100644 --- a/examples/config-rust/spin.toml +++ b/examples/config-rust/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["Fermyon Engineering "] description = "A Spin Rust application demonstrating the config sdk." name = "spin-config-rust" diff --git a/examples/config-tinygo/spin.toml b/examples/config-tinygo/spin.toml index 29a4a520c..67516b824 100644 --- a/examples/config-tinygo/spin.toml +++ b/examples/config-tinygo/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["Fermyon Engineering "] description = "A simple Spin application written in (Tiny)Go." name = "spin-config-tinygo" diff --git a/examples/http-cpp/spin.toml b/examples/http-cpp/spin.toml index 2aebb4dd4..9dc85cacb 100644 --- a/examples/http-cpp/spin.toml +++ b/examples/http-cpp/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["Fermyon Engineering "] description = "A simple application that returns hello." name = "spin-hello-world" diff --git a/examples/http-rust-outbound-http/spin.toml b/examples/http-rust-outbound-http/spin.toml index ceb8c7907..0fde469be 100644 --- a/examples/http-rust-outbound-http/spin.toml +++ b/examples/http-rust-outbound-http/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["Fermyon Engineering "] description = "A simple application that makes an outbound http call." name = "spin-outbound-http" diff --git a/examples/http-rust/spin.toml b/examples/http-rust/spin.toml index 2950d7db9..49af10478 100644 --- a/examples/http-rust/spin.toml +++ b/examples/http-rust/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["Fermyon Engineering "] description = "A simple application that returns hello." name = "spin-hello-world" diff --git a/examples/http-tinygo-outbound-http/spin.toml b/examples/http-tinygo-outbound-http/spin.toml index 12c5e579d..42872ee4e 100644 --- a/examples/http-tinygo-outbound-http/spin.toml +++ b/examples/http-tinygo-outbound-http/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["Fermyon Engineering "] description = "A simple Spin application written in (Tiny)Go that performs outbound HTTP requests." name = "spin-tinygo-outbound-http" diff --git a/examples/http-tinygo/spin.toml b/examples/http-tinygo/spin.toml index cb4dc3b6c..7e4dd2c76 100644 --- a/examples/http-tinygo/spin.toml +++ b/examples/http-tinygo/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["Fermyon Engineering "] description = "A simple Spin application written in (Tiny)Go." name = "spin-hello-tinygo" diff --git a/examples/redis-rust/spin.toml b/examples/redis-rust/spin.toml index 4fd04f364..fbb69e4d7 100644 --- a/examples/redis-rust/spin.toml +++ b/examples/redis-rust/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["Fermyon Engineering "] description = "A redis application." name = "spin-redis" diff --git a/examples/rust-key-value/spin.toml b/examples/rust-key-value/spin.toml index 676631b2a..ffad4089b 100644 --- a/examples/rust-key-value/spin.toml +++ b/examples/rust-key-value/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["Fermyon Engineering "] description = "A simple application that exercises key-value storage." name = "spin-key-value" diff --git a/examples/rust-outbound-mysql/spin.toml b/examples/rust-outbound-mysql/spin.toml index 86f2efc10..2c3eb9b7b 100644 --- a/examples/rust-outbound-mysql/spin.toml +++ b/examples/rust-outbound-mysql/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["itowlson "] description = "Demo of calling MySQL from a Spin application" name = "rust-outbound-mysql" diff --git a/examples/rust-outbound-pg/spin.toml b/examples/rust-outbound-pg/spin.toml index e8da1acd0..11d090371 100644 --- a/examples/rust-outbound-pg/spin.toml +++ b/examples/rust-outbound-pg/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["Fermyon Engineering "] name = "rust-outbound-pg-example" trigger = { type = "http", base = "/" } diff --git a/examples/rust-outbound-redis/spin.toml b/examples/rust-outbound-redis/spin.toml index dc56e573f..589a4b296 100644 --- a/examples/rust-outbound-redis/spin.toml +++ b/examples/rust-outbound-redis/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["Fermyon Engineering "] name = "rust-outbound-redis-example" trigger = { type = "http", base = "/" } diff --git a/examples/spin-timer/app-example/spin.toml b/examples/spin-timer/app-example/spin.toml index 0a1e4b39a..5d88d7c77 100644 --- a/examples/spin-timer/app-example/spin.toml +++ b/examples/spin-timer/app-example/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["itowlson "] description = "" name = "goodbye" diff --git a/examples/spin-wagi-http/spin.toml b/examples/spin-wagi-http/spin.toml index bbc55b6ae..758191967 100644 --- a/examples/spin-wagi-http/spin.toml +++ b/examples/spin-wagi-http/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["Fermyon Engineering "] description = "A hello world application that serves content from a C++ program and a Rust program" name = "spin-wagi-hello" diff --git a/examples/tinygo-key-value/spin.toml b/examples/tinygo-key-value/spin.toml index f9ff42398..f029718b3 100644 --- a/examples/tinygo-key-value/spin.toml +++ b/examples/tinygo-key-value/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["Fermyon Engineering "] name = "tinygo-key-value-example" trigger = { type = "http", base = "/" } diff --git a/examples/tinygo-outbound-redis/spin.toml b/examples/tinygo-outbound-redis/spin.toml index 671ddebaa..91be113db 100644 --- a/examples/tinygo-outbound-redis/spin.toml +++ b/examples/tinygo-outbound-redis/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["Fermyon Engineering "] name = "tinygo-outbound-redis-example" trigger = { type = "http", base = "/" } diff --git a/examples/tinygo-redis/spin.toml b/examples/tinygo-redis/spin.toml index 2889bf8ff..9761277da 100644 --- a/examples/tinygo-redis/spin.toml +++ b/examples/tinygo-redis/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["Fermyon Engineering "] description = "A redis application." name = "spin-redis" diff --git a/examples/wagi-http-rust/spin.toml b/examples/wagi-http-rust/spin.toml index 3063ba65b..07b18bb83 100644 --- a/examples/wagi-http-rust/spin.toml +++ b/examples/wagi-http-rust/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["Fermyon Engineering "] description = "An application that returns the arguments the program started with, the environment variables set, and current time" name = "wagi-hello-world" diff --git a/templates/http-c/content/spin.toml b/templates/http-c/content/spin.toml index 1a17a1431..78b4f9b72 100644 --- a/templates/http-c/content/spin.toml +++ b/templates/http-c/content/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["{{authors}}"] description = "{{project-description}}" name = "{{project-name}}" diff --git a/templates/http-empty/content/spin.toml b/templates/http-empty/content/spin.toml index 77a4f9d73..379358a81 100644 --- a/templates/http-empty/content/spin.toml +++ b/templates/http-empty/content/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["{{authors}}"] description = "{{project-description}}" name = "{{project-name}}" diff --git a/templates/http-go/content/spin.toml b/templates/http-go/content/spin.toml index 6c56cb69f..ce227c995 100644 --- a/templates/http-go/content/spin.toml +++ b/templates/http-go/content/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["{{authors}}"] description = "{{project-description}}" name = "{{project-name}}" diff --git a/templates/http-grain/content/spin.toml b/templates/http-grain/content/spin.toml index c2464533a..88c639896 100644 --- a/templates/http-grain/content/spin.toml +++ b/templates/http-grain/content/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["{{authors}}"] description = "{{project-description}}" name = "{{project-name}}" diff --git a/templates/http-php/content/spin.toml b/templates/http-php/content/spin.toml index 4c5172c64..6e101e1a2 100644 --- a/templates/http-php/content/spin.toml +++ b/templates/http-php/content/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["{{authors}}"] description = "{{project-description}}" name = "{{project-name}}" diff --git a/templates/http-rust/content/spin.toml b/templates/http-rust/content/spin.toml index a78b4981a..99ef63aa4 100644 --- a/templates/http-rust/content/spin.toml +++ b/templates/http-rust/content/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["{{authors}}"] description = "{{project-description}}" name = "{{project-name}}" diff --git a/templates/http-swift/content/spin.toml b/templates/http-swift/content/spin.toml index e4a9e9d1f..cffd70180 100644 --- a/templates/http-swift/content/spin.toml +++ b/templates/http-swift/content/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["{{authors}}"] description = "{{project-description}}" name = "{{project-name}}" diff --git a/templates/http-zig/content/spin.toml b/templates/http-zig/content/spin.toml index 8b67dcaa0..bd64fb68a 100644 --- a/templates/http-zig/content/spin.toml +++ b/templates/http-zig/content/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["{{authors}}"] description = "{{project-description}}" name = "{{project-name}}" diff --git a/templates/redis-go/content/spin.toml b/templates/redis-go/content/spin.toml index e2faa4e39..5a1d80d1c 100644 --- a/templates/redis-go/content/spin.toml +++ b/templates/redis-go/content/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["{{authors}}"] description = "{{project-description}}" name = "{{project-name}}" diff --git a/templates/redis-rust/content/spin.toml b/templates/redis-rust/content/spin.toml index 844e9e5e0..c38227dab 100644 --- a/templates/redis-rust/content/spin.toml +++ b/templates/redis-rust/content/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["{{authors}}"] description = "{{project-description}}" name = "{{project-name}}" diff --git a/templates/static-fileserver/content/spin.toml b/templates/static-fileserver/content/spin.toml index a4fe049df..8e2e10b5d 100644 --- a/templates/static-fileserver/content/spin.toml +++ b/templates/static-fileserver/content/spin.toml @@ -1,4 +1,4 @@ -spin_version = "1" +spin_manifest_version = "1" authors = ["{{authors}}"] description = "{{project-description}}" name = "{{project-name}}"