Skip to content

Commit 7364cc6

Browse files
committed
[chapter08] another spin example
Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent 8bb0b86 commit 7364cc6

File tree

9 files changed

+127
-3
lines changed

9 files changed

+127
-3
lines changed
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
# `hello-world-spin`
22

3-
- Assuming you have `spin` installed, run:
3+
- Pre-reqs:
4+
- K8s cluster w/ the container-spin-shim installed on every node.
5+
- cert-manager installed onto the cluster.
6+
- Spin's RuntimeClass applied.
7+
- Spin's CRDs applied.
8+
- Spin's operator installed.
9+
- Spin's executor created.
410

11+
12+
- Then, assuming you have `spin` installed, run:
513
```shell
614
spin build
7-
spin up
15+
spin registry push ghcr.io/<your GH username>/serverside-wasm-book-code/hello-world-spin:latest
16+
spin kube scaffold --from ghcr.io/danbugs/serverside-wasm-book-code/hello-world-spin:latest | kubectl create -f -
817
```
918

1019
- Then, you can test it with:
1120
```shell
12-
curl http://127.0.0.1:3000
21+
kubectl port-forward svc/hello-world-spin 8083:80
22+
curl localhost:8083/
1323
```

chapter08/scaling-spin/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
dist
3+
target
4+
.spin/
5+
build/

chapter08/scaling-spin/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
KNITWIT_SOURCE=./config/knitwit.json
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"version": 1,
3+
"project": {
4+
"worlds": [
5+
"spin-http"
6+
]
7+
},
8+
"packages": {}
9+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: Ingress
3+
metadata:
4+
name: nginx
5+
annotations:
6+
ingress.kubernetes.io/ssl-redirect: "false"
7+
spec:
8+
rules:
9+
- http:
10+
paths:
11+
- path: /
12+
pathType: Prefix
13+
backend:
14+
service:
15+
name: scaling-spin
16+
port:
17+
number: 80
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "scaling-spin",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"build": "knitwit --out-dir build/wit/knitwit --out-world combined && npx webpack --mode=production && npx mkdirp dist && npx j2w -i build/bundle.js -d build/wit/knitwit -n combined -o dist/scaling-spin.wasm",
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"devDependencies": {
14+
"mkdirp": "^3.0.1",
15+
"webpack": "^5.74.0",
16+
"webpack-cli": "^4.10.0",
17+
"@fermyon/knitwit": "0.3.0"
18+
},
19+
"dependencies": {
20+
"@fermyon/spin-sdk": "^3.0.0",
21+
"itty-router": "^5.0.18"
22+
}
23+
}

chapter08/scaling-spin/spin.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
spin_manifest_version = 2
2+
3+
[application]
4+
authors = ["danbugs <danilochiarlone@gmail.com>"]
5+
description = ""
6+
name = "scaling-spin"
7+
version = "0.1.0"
8+
9+
[[trigger.http]]
10+
route = "/..."
11+
component = "scaling-spin"
12+
13+
[component.scaling-spin]
14+
source = "dist/scaling-spin.wasm"
15+
exclude_files = ["**/node_modules"]
16+
[component.scaling-spin.build]
17+
command = ["npm install", "npm run build"]
18+
watch = ["src/**/*.js"]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// For AutoRouter documentation refer to https://itty.dev/itty-router/routers/autorouter
2+
import { AutoRouter } from 'itty-router';
3+
4+
let router = AutoRouter();
5+
6+
// Route ordering matters, the first route that matches will be used
7+
// Any route that does not return will be treated as a middleware
8+
// Any unmatched route will return a 404
9+
router
10+
.get("/", () => new Response("hello universe"))
11+
.get('/hello/:name', ({ name }) => `Hello, ${name}!`)
12+
13+
addEventListener('fetch', (event) => {
14+
event.respondWith(router.fetch(event.request));
15+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const path = require('path');
2+
const SpinSdkPlugin = require("@fermyon/spin-sdk/plugins/webpack")
3+
4+
module.exports = {
5+
entry: './src/index.js',
6+
experiments: {
7+
outputModule: true,
8+
},
9+
output: {
10+
path: path.resolve(__dirname, './build'),
11+
filename: 'bundle.js',
12+
module: true,
13+
library: {
14+
type: "module",
15+
}
16+
},
17+
plugins: [
18+
new SpinSdkPlugin()
19+
],
20+
optimization: {
21+
minimize: false
22+
},
23+
performance: {
24+
hints: false,
25+
}
26+
};

0 commit comments

Comments
 (0)