Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spin support #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ You have two options for running in Wagi:
1. Use [hippofactory](https://github.com/deislabs/hippofactory) to build and push a bindle, then use `wagi -b $YOUR_BINDLE`
2. Write a `modules.toml` file and use `wagi -c modules.toml`.

## Running in [Spin](https://spin.fermyon.dev)

You can build with `spin build`.

To run:
1. `spin up` or `spin build --up`
2. Point your browser to http://localhost:3000/index.html

Assuming your production target is set, you can deploy with `spin deploy`.

### Using `hippofactory`

Edit the `HIPPOFACTS` file to taste.
Expand Down Expand Up @@ -92,8 +102,9 @@ The above configures Wagi to map the path `/static/...` to the `fileserver.gr.wa

### Environment Variables

The following environment variables can be passed via Wagi's `-e` flag:
The following environment variables can be passed via Wagi's `-e` flag or in Spin's `[component.environment]`:

- `PATH_PREFIX`: The prefix that should be added before the query path. Example: `PATH_PREFIX = "static/"`
- `CACHE_CONTROL`: The string value of a cache-control header. If not specified, this will set cache-control to `no-cache`. Google recommends setting this value to `CACHE_CONTROL="max-age=31536000"` (cache for up to 1 year).
- Type-specific cache controls can be set using the following env vars (all of which default to `CACHE_CONTROL` if not set):
- `CSS_CACHE_CONTROL`
Expand Down Expand Up @@ -170,4 +181,4 @@ Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct
FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact
[[email protected]](mailto:[email protected]) with any additional
questions or comments.
questions or comments.
19 changes: 19 additions & 0 deletions spin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Define a basic HTTP app
spin_version = "1"
name = "wagi-fileserver"
trigger = { type = "http", base = "/" }
version = "1.0.3"

# Attach our `example.wasm` file to this app
[[component]]
id = "wagi-fileserver"
source = "fileserver.gr.wasm"
files = ["static/*"]
[component.environment]
PATH_PREFIX = "static/"
CACHE_CONTROL = "max-age=31536000"
[component.trigger]
route = "/..."
executor = { type = "wagi" }
[component.build]
command = "grain compile fileserver.gr"
11 changes: 11 additions & 0 deletions static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<html>

<head>
<title>My Dog</title>
</head>

<body>
<img src="puppy.jpg">
</body>

</html>
Binary file added static/puppy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.