From 4d48dd0d60e4db0411f3c990444c789c55baf84f Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Mon, 15 Apr 2024 06:49:15 +0000 Subject: [PATCH] feat: add wasm plugin feat: add wasm plugin feat: add wasm plugin feat: add wasm plugin --- .github/workflows/ci.yml | 12 +- .github/workflows/example.yml | 20 +- dagger.json | 6 +- example/.fluentci/plugin/.gitignore | 1 + example/.fluentci/plugin/Cargo.lock | 396 ++++++++++++++++++++++++ example/.fluentci/plugin/Cargo.toml | 14 + example/.fluentci/plugin/src/helpers.rs | 32 ++ example/.fluentci/plugin/src/lib.rs | 32 ++ example/Cargo.toml | 13 +- plugin/.gitignore | 1 + plugin/Cargo.lock | 396 ++++++++++++++++++++++++ plugin/Cargo.toml | 14 + plugin/src/helpers.rs | 32 ++ plugin/src/lib.rs | 32 ++ 14 files changed, 982 insertions(+), 19 deletions(-) create mode 100644 example/.fluentci/plugin/.gitignore create mode 100644 example/.fluentci/plugin/Cargo.lock create mode 100644 example/.fluentci/plugin/Cargo.toml create mode 100644 example/.fluentci/plugin/src/helpers.rs create mode 100644 example/.fluentci/plugin/src/lib.rs create mode 100644 plugin/.gitignore create mode 100644 plugin/Cargo.lock create mode 100644 plugin/Cargo.toml create mode 100644 plugin/src/helpers.rs create mode 100644 plugin/src/lib.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 381893e..14f5f12 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,13 +11,19 @@ jobs: steps: - uses: actions/checkout@v2 - name: Setup Fluent CI - uses: fluentci-io/setup-fluentci@v4 + uses: fluentci-io/setup-fluentci@v5 + with: + wasm: true + pipeline: deno + args: | + fmt + test + coverage - name: Run Dagger Pipelines run: | - fluentci run deno_pipeline fmt test dagger -m github.com/fluent-ci-templates/spin-pipeline@main functions - name: Upload to Codecov - run: fluentci run codecov_pipeline + run: fluentci run --wasm codecov upload env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} publish: diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml index 718e7df..6521692 100644 --- a/.github/workflows/example.yml +++ b/.github/workflows/example.yml @@ -13,16 +13,18 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: denoland/setup-deno@v1 - with: - deno-version: v1.41 - name: Setup Fluent CI CLI - run: deno install -A -r https://cli.fluentci.io -n fluentci - - name: Setup Dagger - run: | - curl -L https://dl.dagger.io/dagger/install.sh | DAGGER_VERSION=0.10.0 sh - sudo mv bin/dagger /usr/local/bin - dagger version + uses: fluentci-io/setup-fluentci@v5 + with: + wasm: true + pipeline: . + args: | + build + deploy + working-directory: example + env: + SPIN_AUTH_TOKEN: ${{ secrets.SPIN_AUTH_TOKEN }} + - name: Run Dagger Pipelines run: | dagger run deno run -A ../src/dagger/runner.ts build diff --git a/dagger.json b/dagger.json index 946eab2..14b03a2 100644 --- a/dagger.json +++ b/dagger.json @@ -1,4 +1,8 @@ { "name": "spin", - "sdk": "github.com/fluentci-io/daggerverse/deno-sdk@main" + "sdk": "github.com/fluentci-io/daggerverse/deno-sdk@main", + "version": "v0.10.0", + "description": "", + "author": "Tsiry Sandratraina", + "license": "MIT" } \ No newline at end of file diff --git a/example/.fluentci/plugin/.gitignore b/example/.fluentci/plugin/.gitignore new file mode 100644 index 0000000..9f97022 --- /dev/null +++ b/example/.fluentci/plugin/.gitignore @@ -0,0 +1 @@ +target/ \ No newline at end of file diff --git a/example/.fluentci/plugin/Cargo.lock b/example/.fluentci/plugin/Cargo.lock new file mode 100644 index 0000000..b14575d --- /dev/null +++ b/example/.fluentci/plugin/Cargo.lock @@ -0,0 +1,396 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.82" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" + +[[package]] +name = "autocfg" +version = "1.2.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "base64" +version = "0.22.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" + +[[package]] +name = "bytemuck" +version = "1.15.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "either" +version = "1.11.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "extism-convert" +version = "1.2.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "a63bfc6d371d3b51d6094fd96c4c32a084ceefece3b4f4b328f30067d29da064" +dependencies = [ + "anyhow", + "base64 0.22.0", + "bytemuck", + "extism-convert-macros", + "prost", + "rmp-serde", + "serde", + "serde_json", +] + +[[package]] +name = "extism-convert-macros" +version = "1.2.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "519ccf960500c87244bef99caf8e58222ac95bf1abb06a32f5217b4788857aa6" +dependencies = [ + "manyhow", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "extism-manifest" +version = "1.2.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "05c7d16695dc6b72418e23b58c943411a08264332af403ae9870997b4d495c3d" +dependencies = [ + "base64 0.22.0", + "serde", + "serde_json", +] + +[[package]] +name = "extism-pdk" +version = "1.1.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "1f9a87d636d30b75e697642dd4f6cff2054db5a7a5d69d6601041a76265bb681" +dependencies = [ + "anyhow", + "base64 0.21.7", + "extism-convert", + "extism-manifest", + "extism-pdk-derive", + "serde", + "serde_json", +] + +[[package]] +name = "extism-pdk-derive" +version = "1.1.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "d83995c2023720a0fd5ef2a349c89c1670efb37a979228b0218705f5ddb50d4b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "fluentci-pdk" +version = "0.1.9" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "4d8004273f0e173b96811a72cb742fc9010fc54fec89c59c2c4e7e159fc2bde7" +dependencies = [ + "extism-pdk", + "fluentci-types", + "serde", +] + +[[package]] +name = "fluentci-types" +version = "0.1.3" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "7592ba0dd1c48f06166fa485af48c8df942e7266c62216fe01360b33e33fe047" +dependencies = [ + "serde", +] + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "manyhow" +version = "0.11.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "02bc2a348104913df6d14170bedef54faf224a0970ec7b1f8750748ab94fcd52" +dependencies = [ + "manyhow-macros", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "manyhow-macros" +version = "0.11.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "532aa12d5846b38a524b3acd99fb74dc8a5f193b33e65dac142ef92bd60f9416" +dependencies = [ + "proc-macro-utils", + "proc-macro2", + "quote", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "num-traits" +version = "0.2.18" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + +[[package]] +name = "proc-macro-crate" +version = "3.1.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" +dependencies = [ + "toml_edit", +] + +[[package]] +name = "proc-macro-utils" +version = "0.8.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "3f59e109e2f795a5070e69578c4dc101068139f74616778025ae1011d4cd41a8" +dependencies = [ + "proc-macro2", + "quote", + "smallvec", +] + +[[package]] +name = "proc-macro2" +version = "1.0.80" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "prost" +version = "0.12.4" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "d0f5d036824e4761737860779c906171497f6d55681139d8312388f8fe398922" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.12.4" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "19de2de2a00075bf566bee3bd4db014b11587e84184d3f7a791bc17f1a8e9e48" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rmp" +version = "0.8.12" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "7f9860a6cc38ed1da53456442089b4dfa35e7cedaa326df63017af88385e6b20" +dependencies = [ + "byteorder", + "num-traits", + "paste", +] + +[[package]] +name = "rmp-serde" +version = "1.1.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "bffea85eea980d8a74453e5d02a8d93028f3c34725de143085a844ebe953258a" +dependencies = [ + "byteorder", + "rmp", + "serde", +] + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.115" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "spin" +version = "0.10.0" +dependencies = [ + "anyhow", + "extism-pdk", + "fluentci-pdk", +] + +[[package]] +name = "syn" +version = "2.0.59" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" + +[[package]] +name = "toml_edit" +version = "0.21.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "winnow" +version = "0.5.40" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] diff --git a/example/.fluentci/plugin/Cargo.toml b/example/.fluentci/plugin/Cargo.toml new file mode 100644 index 0000000..ac653b1 --- /dev/null +++ b/example/.fluentci/plugin/Cargo.toml @@ -0,0 +1,14 @@ +[package] +edition = "2021" +name = "spin" +version = "0.10.0" + +[lib] +crate-type = ["cdylib"] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +anyhow = "1.0.82" +extism-pdk = "1.1.0" +fluentci-pdk = "0.1.9" diff --git a/example/.fluentci/plugin/src/helpers.rs b/example/.fluentci/plugin/src/helpers.rs new file mode 100644 index 0000000..1f0f200 --- /dev/null +++ b/example/.fluentci/plugin/src/helpers.rs @@ -0,0 +1,32 @@ +use extism_pdk::FnResult; +use fluentci_pdk::dag; + +pub fn setup_rust() -> FnResult<()> { + dag().call( + "https://pkg.fluentci.io/rust@v0.10.2?wasm=1", + "target_add", + vec!["wasm32-wasi"], + )?; + Ok(()) +} + +pub fn setup_spin() -> FnResult<()> { + let path = dag().get_env("PATH")?; + let home = dag().get_env("HOME")?; + + dag().set_envs(vec![( + "PATH".into(), + format!("{}/.local/bin:{}", home, path), + )])?; + + dag() + .pkgx()? + .with_packages(vec!["curl"])? + .with_exec(vec!["type spin > /dev/null || curl -fsSL https://developer.fermyon.com/downloads/install.sh | bash"])? + .with_exec(vec!["chmod a+x spin"])? + .with_exec(vec!["mkdir", "-p", "$HOME/.local/bin"])? + .with_exec(vec!["mv", "spin", "$HOME/.local/bin"])? + .with_exec(vec!["spin --version"])? + .stdout()?; + Ok(()) +} diff --git a/example/.fluentci/plugin/src/lib.rs b/example/.fluentci/plugin/src/lib.rs new file mode 100644 index 0000000..83b4296 --- /dev/null +++ b/example/.fluentci/plugin/src/lib.rs @@ -0,0 +1,32 @@ +use crate::helpers::{setup_rust, setup_spin}; +use extism_pdk::*; +use fluentci_pdk::dag; + +pub mod helpers; + +#[plugin_fn] +pub fn build(args: String) -> FnResult { + setup_rust()?; + setup_spin()?; + + let stdout = dag() + .pipeline("build")? + .with_exec(vec!["PATH=$HOME/.cargo/bin:$PATH", "spin", "build", &args])? + .stdout()?; + + Ok(stdout) +} + +#[plugin_fn] +pub fn deploy(args: String) -> FnResult { + setup_rust()?; + setup_spin()?; + + let stdout = dag() + .pipeline("deploy")? + .with_exec(vec!["spin", "login", "--auth-token", "token"])? + .with_exec(vec!["PATH=$HOME/.cargo/bin:$PATH", "spin", "deploy", &args])? + .stdout()?; + + Ok(stdout) +} diff --git a/example/Cargo.toml b/example/Cargo.toml index 9950504..4addff1 100644 --- a/example/Cargo.toml +++ b/example/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "hello" authors = ["Tsiry Sandratraina "] description = "" -version = "0.1.0" edition = "2021" +name = "hello" +version = "0.1.0" [lib] -crate-type = [ "cdylib" ] +crate-type = ["cdylib"] [dependencies] # Useful crate to handle errors. @@ -16,8 +16,9 @@ bytes = "1" # General-purpose crate with common HTTP types. http = "0.2" # The Spin SDK. -spin-sdk = { git = "/~https://github.com/fermyon/spin", tag = "v1.2.1" } +spin-sdk = {git = "/~https://github.com/fermyon/spin", tag = "v1.2.1"} # Crate that generates Rust Wasm bindings from a WebAssembly interface. -wit-bindgen-rust = { git = "/~https://github.com/bytecodealliance/wit-bindgen", rev = "cb871cfa1ee460b51eb1d144b175b9aab9c50aba" } +wit-bindgen-rust = {git = "/~https://github.com/bytecodealliance/wit-bindgen", rev = "cb871cfa1ee460b51eb1d144b175b9aab9c50aba"} -[workspace] \ No newline at end of file +[workspace] +exclude = [".fluentci"] diff --git a/plugin/.gitignore b/plugin/.gitignore new file mode 100644 index 0000000..9f97022 --- /dev/null +++ b/plugin/.gitignore @@ -0,0 +1 @@ +target/ \ No newline at end of file diff --git a/plugin/Cargo.lock b/plugin/Cargo.lock new file mode 100644 index 0000000..b14575d --- /dev/null +++ b/plugin/Cargo.lock @@ -0,0 +1,396 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.82" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" + +[[package]] +name = "autocfg" +version = "1.2.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "base64" +version = "0.22.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" + +[[package]] +name = "bytemuck" +version = "1.15.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "either" +version = "1.11.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "extism-convert" +version = "1.2.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "a63bfc6d371d3b51d6094fd96c4c32a084ceefece3b4f4b328f30067d29da064" +dependencies = [ + "anyhow", + "base64 0.22.0", + "bytemuck", + "extism-convert-macros", + "prost", + "rmp-serde", + "serde", + "serde_json", +] + +[[package]] +name = "extism-convert-macros" +version = "1.2.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "519ccf960500c87244bef99caf8e58222ac95bf1abb06a32f5217b4788857aa6" +dependencies = [ + "manyhow", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "extism-manifest" +version = "1.2.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "05c7d16695dc6b72418e23b58c943411a08264332af403ae9870997b4d495c3d" +dependencies = [ + "base64 0.22.0", + "serde", + "serde_json", +] + +[[package]] +name = "extism-pdk" +version = "1.1.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "1f9a87d636d30b75e697642dd4f6cff2054db5a7a5d69d6601041a76265bb681" +dependencies = [ + "anyhow", + "base64 0.21.7", + "extism-convert", + "extism-manifest", + "extism-pdk-derive", + "serde", + "serde_json", +] + +[[package]] +name = "extism-pdk-derive" +version = "1.1.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "d83995c2023720a0fd5ef2a349c89c1670efb37a979228b0218705f5ddb50d4b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "fluentci-pdk" +version = "0.1.9" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "4d8004273f0e173b96811a72cb742fc9010fc54fec89c59c2c4e7e159fc2bde7" +dependencies = [ + "extism-pdk", + "fluentci-types", + "serde", +] + +[[package]] +name = "fluentci-types" +version = "0.1.3" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "7592ba0dd1c48f06166fa485af48c8df942e7266c62216fe01360b33e33fe047" +dependencies = [ + "serde", +] + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "manyhow" +version = "0.11.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "02bc2a348104913df6d14170bedef54faf224a0970ec7b1f8750748ab94fcd52" +dependencies = [ + "manyhow-macros", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "manyhow-macros" +version = "0.11.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "532aa12d5846b38a524b3acd99fb74dc8a5f193b33e65dac142ef92bd60f9416" +dependencies = [ + "proc-macro-utils", + "proc-macro2", + "quote", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "num-traits" +version = "0.2.18" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + +[[package]] +name = "proc-macro-crate" +version = "3.1.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" +dependencies = [ + "toml_edit", +] + +[[package]] +name = "proc-macro-utils" +version = "0.8.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "3f59e109e2f795a5070e69578c4dc101068139f74616778025ae1011d4cd41a8" +dependencies = [ + "proc-macro2", + "quote", + "smallvec", +] + +[[package]] +name = "proc-macro2" +version = "1.0.80" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "prost" +version = "0.12.4" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "d0f5d036824e4761737860779c906171497f6d55681139d8312388f8fe398922" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.12.4" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "19de2de2a00075bf566bee3bd4db014b11587e84184d3f7a791bc17f1a8e9e48" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rmp" +version = "0.8.12" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "7f9860a6cc38ed1da53456442089b4dfa35e7cedaa326df63017af88385e6b20" +dependencies = [ + "byteorder", + "num-traits", + "paste", +] + +[[package]] +name = "rmp-serde" +version = "1.1.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "bffea85eea980d8a74453e5d02a8d93028f3c34725de143085a844ebe953258a" +dependencies = [ + "byteorder", + "rmp", + "serde", +] + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.115" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "spin" +version = "0.10.0" +dependencies = [ + "anyhow", + "extism-pdk", + "fluentci-pdk", +] + +[[package]] +name = "syn" +version = "2.0.59" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" + +[[package]] +name = "toml_edit" +version = "0.21.1" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "winnow" +version = "0.5.40" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] diff --git a/plugin/Cargo.toml b/plugin/Cargo.toml new file mode 100644 index 0000000..ac653b1 --- /dev/null +++ b/plugin/Cargo.toml @@ -0,0 +1,14 @@ +[package] +edition = "2021" +name = "spin" +version = "0.10.0" + +[lib] +crate-type = ["cdylib"] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +anyhow = "1.0.82" +extism-pdk = "1.1.0" +fluentci-pdk = "0.1.9" diff --git a/plugin/src/helpers.rs b/plugin/src/helpers.rs new file mode 100644 index 0000000..1f0f200 --- /dev/null +++ b/plugin/src/helpers.rs @@ -0,0 +1,32 @@ +use extism_pdk::FnResult; +use fluentci_pdk::dag; + +pub fn setup_rust() -> FnResult<()> { + dag().call( + "https://pkg.fluentci.io/rust@v0.10.2?wasm=1", + "target_add", + vec!["wasm32-wasi"], + )?; + Ok(()) +} + +pub fn setup_spin() -> FnResult<()> { + let path = dag().get_env("PATH")?; + let home = dag().get_env("HOME")?; + + dag().set_envs(vec![( + "PATH".into(), + format!("{}/.local/bin:{}", home, path), + )])?; + + dag() + .pkgx()? + .with_packages(vec!["curl"])? + .with_exec(vec!["type spin > /dev/null || curl -fsSL https://developer.fermyon.com/downloads/install.sh | bash"])? + .with_exec(vec!["chmod a+x spin"])? + .with_exec(vec!["mkdir", "-p", "$HOME/.local/bin"])? + .with_exec(vec!["mv", "spin", "$HOME/.local/bin"])? + .with_exec(vec!["spin --version"])? + .stdout()?; + Ok(()) +} diff --git a/plugin/src/lib.rs b/plugin/src/lib.rs new file mode 100644 index 0000000..83b4296 --- /dev/null +++ b/plugin/src/lib.rs @@ -0,0 +1,32 @@ +use crate::helpers::{setup_rust, setup_spin}; +use extism_pdk::*; +use fluentci_pdk::dag; + +pub mod helpers; + +#[plugin_fn] +pub fn build(args: String) -> FnResult { + setup_rust()?; + setup_spin()?; + + let stdout = dag() + .pipeline("build")? + .with_exec(vec!["PATH=$HOME/.cargo/bin:$PATH", "spin", "build", &args])? + .stdout()?; + + Ok(stdout) +} + +#[plugin_fn] +pub fn deploy(args: String) -> FnResult { + setup_rust()?; + setup_spin()?; + + let stdout = dag() + .pipeline("deploy")? + .with_exec(vec!["spin", "login", "--auth-token", "token"])? + .with_exec(vec!["PATH=$HOME/.cargo/bin:$PATH", "spin", "deploy", &args])? + .stdout()?; + + Ok(stdout) +}