Go to file
Radu Matei 75608446bc
fix(tests): fix wrong timeout in integration test
This commit fixes a wrong timeout in the integration test logic that
added a 120-second sleep cycle for tests when a particular server
(Bindle or Spin) wasn't ready, as opposed to waiting for one second,
for a total of 120 times when needed.

This commit also temporarily removes the unused release CI workflow
altogether.

Signed-off-by: Radu Matei <radu.matei@fermyon.com>
2022-03-05 17:11:51 +02:00
.cargo chore: rename fermyon-* to spin-* 2021-11-29 19:12:45 -08:00
.github/workflows fix(tests): fix wrong timeout in integration test 2022-03-05 17:11:51 +02:00
.vscode chore: enable Cargo Clippy and address issues 2022-02-11 02:14:15 +02:00
crates add support for argv in Wagi executor (#127) 2022-03-04 17:01:25 -07:00
docs add support for argv in Wagi executor (#127) 2022-03-04 17:01:25 -07:00
src ref(feat-33): TLS support for Spin. 2022-03-02 09:52:28 -07:00
templates/spin-http tests: add integration tests 2022-03-01 17:22:02 +02:00
tests fix(tests): fix wrong timeout in integration test 2022-03-05 17:11:51 +02:00
wit/ephemeral Add interfaces for triggers and the WASI toolkit in wasi/ephemeral 2022-01-26 05:16:57 +02:00
.gitignore chore: update the Spin CLI to work with new HTTP engine 2022-02-06 00:29:58 +02:00
Cargo.lock Mount directory at specific guest path 2022-03-04 12:53:09 +13:00
Cargo.toml tests: add integration tests 2022-03-01 17:22:02 +02:00
LICENSE Add Apache2 license 2021-11-01 19:16:52 -07:00
Makefile ref(feat-33): TLS support for Spin. 2022-03-02 09:52:28 -07:00
build.rs tests: add integration tests 2022-03-01 17:22:02 +02:00
readme.md Build spin-http templated projects to Wasm by default 2022-02-08 09:17:51 +13:00

readme.md

Project Spin

Spin is a tool that allows developers to build, publish, and deploy WebAssembly workloads. It is the next version of the Fermyon runtime.

Take Spin for a spin

Build Spin CLI

Clone this repository and build the Spin CLI:

$ git clone https://github.com/fermyon/spin
$ cd spin && cargo build --release

Build and Run an HTTP Application with Spin

Generate an HTTP Application Using a Spin Template

Add a new Spin template based on the templates/spin-http directory from this repo:

$ spin templates add --local templates/spin-http --name spin-http
$ spin templates list
+---------------------------------------+
| Name        Repository   URL   Branch |
+=======================================+
| spin-http   local                     |
+---------------------------------------+

Create the application:

$ mkdir helloworld
# TODO: the name and path where the app is generated is wrong.
$ spin new --repo local --template spin-http --path .

Build the Application

In the application directory:

$ cargo build --release

Run the Application Locally

The configuration file spin.toml contains the information required for Spin to run the application locally:

$ export RUST_LOG=spin_engine=info,spin_http,wact=info
$ spin up --app spin.toml

2022-02-06T02:44:08.810806Z  INFO spin_http_engine: Processing request for application spin-hello-world on path /hello
2022-02-06T02:44:08.810897Z  INFO execute{component="hello"}: spin_http_engine: Executing request for component hello
2022-02-06T02:44:08.810918Z  INFO execute{component="hello"}: prepare_component{component="hello"}: spin_engine: Preparing component hello
2022-02-06T02:44:08.810936Z  INFO execute{component="hello"}: prepare_component{component="hello"}: store: spin_engine: Creating store.
2022-02-06T02:44:08.811318Z  INFO execute{component="hello"}: spin_http_engine: Request URI: "/hello"
2022-02-06T02:44:08.811553Z  INFO execute{component="hello"}: spin_http_engine: Response status code: 200
2022-02-06T02:44:08.811715Z  INFO execute{component="hello"}: spin_http_engine: Request finished, sending response.

The application is now ready, after starting, send a request using curl -i localhost:3000/hello:

$ curl -i localhost:3000/hello
HTTP/1.1 200 OK
content-length: 12
date: Sun, 06 Feb 2022 02:44:08 GMT

I'm a teapot

Publishing Interfaces

In the example above, the interface (.wit file) was copied over to the local HTTP application directory. You can also publish interfaces to a bindle registry for others to consume as well as pull interfaces from a bindle registry to use. The example below creates and publishes the spin http interface and then walks through how to consume it in the HTTP application from the previous example.

Publish the Spin HTTP Interface

Push the Spin HTTP interface to the registry (from the root of this repository). This step, together with starting the registry, will not be required once we set up a canonical registry instance:

$ wact interface publish --name fermyon/http --version 0.1.0 wit/ephemeral/spin-http.wit

Use Interface in HTTP Application

  1. Update Cargo.toml to include the following dependency, component and interface information:
[...]
[dependencies]
    # The Wact dependency generates bindings that simplify working with interfaces.
    wact = { git = "https://github.com/fermyon/wact", rev = "93a9eaeba9205918dc214a6310c0bb6e33c0e3c8" }

[workspace]

# Metadata about this component.
[package.metadata.component]
    name = "spinhelloworld"

# This component implements the fermyon/http interface.
[package.metadata.component.exports]
    fermyon-http = { name = "fermyon/http", version = "0.1.0" }
  1. Update the application to use wact to generate and use rust bindings. In src/lib.rs:
// Import the HTTP objects from the generated bindings.
use fermyon_http::{Request, Response};

// Generate Rust bindings for all interfaces in Cargo.toml.
wact::component!();

struct FermyonHttp {}
impl fermyon_http::FermyonHttp for FermyonHttp {
    // Implement the `handler` entrypoint for Spin HTTP components.
    fn handler(req: Request) -> Response {
        println!("Request: {:?}", req);
        Response {
            status: 418,
            headers: None,
            body: Some("I'm a teapot".as_bytes().to_vec()),
        }
    }
}
  1. Remove *.wit files from local HTTP application directory

  2. In the application directory, build the component:

$ cargo build --target wasm32-wasi --release
# OR
$ cargo component build --release

Run the application locally to test.