-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Populate the repository with the template
- Loading branch information
0 parents
commit 3ad6af5
Showing
8 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: Continuous Integration | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build_and_deploy_wasmer_axum_starter: | ||
name: Build and Deploy Wasmer Axum Starter to Wasmer Edge | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install cargo-wasix | ||
uses: taiki-e/install-action@v2 | ||
with: | ||
tool: cargo-wasix | ||
- name: Cargo Wasix Update Check | ||
run: cargo wasix self update-check | ||
- name: Setup Wasmer | ||
uses: wasmerio/setup-wasmer@v2 | ||
- name: Rust Cache | ||
uses: Swatinem/rust-cache@v2 | ||
# - name: Type Checking | ||
# run: cargo wasix check --verbose --locked --release | ||
# continue-on-error: false | ||
- name: Build | ||
run: cargo wasix build --verbose --locked --release | ||
continue-on-error: false | ||
# - name: Deploy app to wasmer.wtf | ||
# run: wasmer deploy --registry="https://registry.wasmer.wtf/graphql" --token=${{ secrets.WASMER_CIUSER_DEV_TOKEN }} --publish-package --non-interactive --no-wait --no-persist-id --owner wasmer-tests | ||
# continue-on-error: true | ||
- name: Deploy app to wasmer.io | ||
run: wasmer deploy --token=${{ secrets.WASMER_CIUSER_PROD_TOKEN }} --publish-package --non-interactive --no-wait --no-persist-id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
debug/ | ||
target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
# MSVC Windows builds of rustc generate these, which store debugging information | ||
*.pdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "wasix-axum" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
axum = { version = "=0.6.9", features = ["tokio", "json"] } | ||
serde = { version = "1.0.160", features = ["derive"] } | ||
tracing = "0.1.37" | ||
tracing-subscriber = { version = "0.3.16", features = ["fmt"] } | ||
|
||
# NOTE: We need to pin and replace some dependencies to achieve wasix compatibility. | ||
tokio = { version = "=1.24.2", default-features = false, features = ["full"] } | ||
parking_lot = { version = "=0.12.1", features = ["nightly"] } | ||
|
||
[patch.crates-io] | ||
tokio = { git = "https://github.com/wasix-org/tokio.git", branch = "wasix-1.24.2" } | ||
socket2 = { git = "https://github.com/wasix-org/socket2.git", branch = "v0.4.9" } | ||
libc = { git = "https://github.com/wasix-org/libc.git", branch = "master" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 wasmer-examples | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
This is an [Axum](https://github.com/tokio-rs/axum) Web Server starter template that compiles to [WASIX](https://wasix.org). | ||
|
||
> Checkout the full tutorial [here](http://wasix.org/docs/language-guide/rust/tutorials/wasix-axum) | ||
|
||
## Getting started | ||
|
||
First, build the project using [`cargo-wasix`](https://crates.io/crates/cargo-wasix): | ||
|
||
```bash | ||
$ cargo wasix build | ||
``` | ||
|
||
Then, you can run the server easily using Wasmer: | ||
|
||
```bash | ||
$ wasmer run . --net --env PORT=8080 | ||
Listening on http://127.0.0.1:8080 | ||
``` | ||
|
||
> [!NOTE] | ||
> You will need to have Wasmer installed (check out [the docs to install the Wasmer CLI](https://docs.wasmer.io/install)!). | ||
> The `--net` flag is required to enable networking support in Wasmer. The `PORT` environment variable is required to run the server locally. | ||
## Deploy on Wasmer Edge | ||
|
||
The easiest way to deploy your WCGI Rust app is to use the [Wasmer Edge](https://wasmer.io/products/edge). | ||
|
||
Live example: https://wasix-axum-example.wasmer.app | ||
|
||
```bash | ||
wasmer deploy | ||
``` | ||
|
||
> [!NOTE] | ||
> You will need to change the namespace in `wasmer.toml` to your own namespace and app name in `app.yaml` to your own app name. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
kind: wasmer.io/App.v0 | ||
name: thibaultleouay-axum-wasmer | ||
package: thibaultleouay/axum-wasmer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use axum::{routing::get, Router}; | ||
use std::net::SocketAddr; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
// Building our application with a single Route | ||
let app = Router::new().route("/", get(handler)); | ||
|
||
let port = std::env::var("PORT").unwrap_or("80".to_string()); | ||
let port = port.parse::<u16>().unwrap_or_else(|_| { | ||
eprintln!("Invalid port number: {}", port); | ||
std::process::exit(1); | ||
}); | ||
// Run the server with hyper on http://127.0.0.1:3000 | ||
let addr = SocketAddr::from(([127, 0, 0, 1], port)); | ||
eprintln!("Listening on http://{}", addr); | ||
axum::Server::bind(&addr) | ||
.serve(app.into_make_service()) | ||
.await | ||
.unwrap(); | ||
} | ||
|
||
async fn handler() -> &'static str { | ||
"Hello, Axum ❤️ WASIX!" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[[module]] | ||
name = "wasix-axum" | ||
source = "target/wasm32-wasmer-wasi/release/wasix-axum.wasm" | ||
|
||
[[command]] | ||
name = "wasix-axum" | ||
module = "wasix-axum" | ||
runner = "wasi@unstable_" | ||
|
||
[package] | ||
name = "thibaultleouay/axum-wasmer" | ||
version = "0.1.3" | ||
description = "Package for wasmer axum starter" | ||
wasmer-extra-flags = "--net --enable-threads --enable-bulk-memory" | ||
repository = "https://github.com/openstatusHQ/axum-wasmer" | ||
|
||
[dependencies] |