Skip to content

Commit 555f625

Browse files
use fastly compute@edge for website
1 parent 1e4751e commit 555f625

32 files changed

+174
-3
lines changed

.github/workflows/deploy.yml

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
on:
22
workflow_dispatch:
3+
inputs:
4+
tag:
5+
required: true
6+
type: string
7+
description: which tag (on the hyperquark/hyperquark repository) should we build from?
38

49
name: Deploy
510

611
jobs:
7-
deploy:
12+
build:
813
name: Build WASM & website
914
runs-on: ubuntu-latest
1015
permissions:
@@ -15,6 +20,7 @@ jobs:
1520
with:
1621
repository: hyperquark/hyperquark
1722
path: hyperquark
23+
ref: ${{ inputs.tag }}
1824

1925
- name: Install nightly toolchain
2026
uses: actions-rs/toolchain@v1
@@ -66,12 +72,68 @@ jobs:
6672

6773
- name: move file to website repo
6874
run: |
69-
cd $GITHUB_WORKSPACE/website
75+
cd $GITHUB_WORKSPACE/website/pages
7076
rm -rf assets index.html logo.png favicon.ico renderer.js
71-
mv /tmp/hq-dist/* $GITHUB_WORKSPACE/website/
77+
mv /tmp/hq-dist/* $GITHUB_WORKSPACE/website/pages/
7278
7379
- name: Commit changes
7480
uses: stefanzweifel/git-auto-commit-action@v5
7581
with:
7682
repository: ./website
7783
commit_message: Build website
84+
85+
pages:
86+
needs: build
87+
environment:
88+
name: github-pages
89+
url: ${{ steps.deployment.outputs.page_url }}
90+
runs-on: ubuntu-latest
91+
steps:
92+
- name: Checkout
93+
uses: actions/checkout@v4
94+
- name: Setup Pages
95+
uses: actions/configure-pages@v5
96+
- name: Upload artifact
97+
uses: actions/upload-pages-artifact@v3
98+
with:
99+
path: 'pages'
100+
- name: Deploy to GitHub Pages
101+
id: deployment
102+
uses: actions/deploy-pages@v4
103+
104+
compute:
105+
needs: [build, pages]
106+
runs-on: ubuntu-latest
107+
steps:
108+
- name: Checkout
109+
uses: actions/checkout@v4
110+
111+
- name: Setup rust
112+
uses: actions-rs/toolchain@v1
113+
with:
114+
profile: minimal
115+
toolchain: stable
116+
override: true
117+
target: wasm32-wasip1
118+
119+
- name: Setup node
120+
uses: actions/setup-node@v3
121+
with:
122+
node-version: "20.x"
123+
124+
- name: Install fastly CLI
125+
run: npm i -g fastly@latest
126+
127+
- name: Build compute
128+
run: fastly compute build
129+
130+
- name: Purge previous version & deploy
131+
env:
132+
FASTLY_API_TOKEN : ${{ secrets.FASTLY_API_TOKEN }}
133+
run: |
134+
fastly purge --all
135+
fastly compute deploy --domain=hyperquark.edgecompute.app --accept-defaults"
136+
137+
138+
139+

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pkg
2+
target
3+
bin
4+
hyperquark
5+
path-matcher.rs
6+
Cargo.lock

Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "hyperquark"
3+
version = "0.1.0"
4+
authors = []
5+
edition = "2018"
6+
# Remove this line if you want to be able to publish this crate as open source on crates.io.
7+
# Otherwise, `publish = false` prevents an accidental `cargo publish` from revealing private source.
8+
publish = false
9+
10+
[profile.release]
11+
debug = 1
12+
13+
[dependencies]
14+
fastly = "^0.9.2"
15+
regex = "1.11.1"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This repository contains the code which is used to build the HyperQuark website at [https://hyperquark.edgecompute.app](https://hyperquark.edgecompute.app). It also delpoys some pages to Github Pages but these are simply static files to back the compute@edge service.

build.mjs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { readdir, writeFile } from 'node:fs/promises';
2+
3+
const mimeType = (extension) => {
4+
switch (extension) {
5+
case 'js': return 'application/javascript';
6+
case 'css': return 'text/css';
7+
case 'wasm': return 'application/wasm';
8+
case 'png': return 'image/png';
9+
case 'ico': return 'image/x-icon';
10+
case 'html': return 'text/html';
11+
default: throw new Error('Unrecognised file extension: ${extension}');
12+
}
13+
}
14+
15+
const hqDistDir = await readdir('./pages', { encoding: 'utf8', recursive: true });
16+
const fileNames = hqDistDir.filter((name) => !['assets', 'index.html'].includes(name));
17+
const pathMatches = fileNames.map((name) => `"/${name}"`)
18+
19+
const pathMatcher = `match req.get_path() {
20+
${pathMatches.join(' | ')} => req.with_set_header("Host", "hyperquark.github.io").send(BACKEND)?,
21+
path @ _ => {
22+
let ok_path_re = Regex::new(r"^/(settings|about|projects/(file|test|\d+))?$").unwrap();
23+
if ok_path_re.is_match(path) {
24+
Request::get("https://hyperquark.github.io/").send(BACKEND)?
25+
} else {
26+
Request::get("https://hyperquark.github.io/").send(BACKEND)?.with_status(404)
27+
}
28+
}
29+
}`;
30+
31+
console.log(pathMatcher)
32+
33+
await writeFile('path-matcher.rs', pathMatcher, { encoding: 'utf8' });

fastly.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file describes a Fastly Compute@Edge package. To learn more visit:
2+
# https://developer.fastly.com/reference/fastly-toml/
3+
4+
authors = ["pufferfish101007"]
5+
language = "rust"
6+
manifest_version = 3
7+
description = "HyperQuark"
8+
service_id = "HjheuqHb4e2e2zURKwD436"
9+
name = "hyperquark"
10+
11+
[scripts]
12+
build = "node build.mjs && cargo build --target=wasm32-wasip1 --release"
13+
14+
[local_server.backends."github"]
15+
url = "https://hyperquark.github.io"
16+
cert_host = "hyperquark.github.io"
17+
override_host = "hyperquark.github.io"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)