Skip to content

Commit

Permalink
Support Cloudflare Worker deployment (#1081)
Browse files Browse the repository at this point in the history
- Compile Exograph to WebAssembly with Cloudflare-specific platform APIs.
- Introduce a new `exo deploy cf-worker` command
- Introduce exo-env crate to abstract the concept of retrieving values from the system environment or a provided map (and may be extended to other sources in the future).
- Use DATABASE_URL as a fallback to EXO_POSTGRES_URL. 
- Drop the `EXO_POSTGRES_USER` and `EXO_POSTGRES_PASSWORD` environment (instead relying on the database URL to contain the user and password).
  • Loading branch information
ramnivas committed Jun 12, 2024
1 parent f08e1b0 commit 985216c
Show file tree
Hide file tree
Showing 30 changed files with 1,157 additions and 190 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/build-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:
branches: ["main"]
tags:
- "*"
pull_request: # temporary to test cf-worker build without merging

jobs:
# Build and package all the things
Expand Down Expand Up @@ -159,3 +160,41 @@ jobs:
asset_name: exograph-${{ env.ARCH }}.zip
tag: ${{ github.ref }}
prerelease: true

build-cf-worker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Clear up some disk space from the runner
run: |
bash ${PWD}/.github/workflows/clear-disk-space.sh
- name: Add target
run: rustup target add wasm32-unknown-unknown

- uses: Swatinem/rust-cache@v2
with:
key: wasm32-unknown-unknown
save-if: ${{ github.ref == 'refs/heads/main' }}

- name: Install wasm-pack
run: cargo install wasm-pack

- name: Build and package
run: sh ./build-cf-worker.sh

- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: exograph-cf-worker-wasm.zip
path: target/exograph-cf-worker-wasm.zip

- name: Upload zip to release
if: startsWith(github.ref, 'refs/tags/')
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: target/exograph-cf-worker-wasm.zip
asset_name: exograph-cf-worker-wasm.zip
tag: ${{ github.ref }}
prerelease: true
180 changes: 169 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = [
"crates/resolver",
"crates/server-actix",
"crates/server-aws-lambda",
"crates/server-cf-worker",
"crates/server-common",
"crates/testing",
"crates/core-subsystem/*",
Expand Down Expand Up @@ -74,13 +75,12 @@ heck = "0.4.0"
include_dir = "0.7.2"
indexmap = "2.0.1"
insta = { version = "1.31.0", features = ["redactions", "yaml"] }
jsonwebtoken = "9.2.0"
jsonwebtoken = "9.3.0"
lazy_static = "1.4.0"
maybe-owned = "0.3.4"
rand = "0.8"
regex = "1"
reqwest = { version = "0.11.4", default-features = false, features = [
"stream",
reqwest = { version = "0.11.20", default-features = false, features = [
"rustls-tls-native-roots",
] }
serde = { version = "1.0", features = ["derive"] }
Expand Down Expand Up @@ -117,6 +117,9 @@ postgres-types = { git = "https://github.com/exograph/rust-postgres", branch = "
debug = 1

[profile.release]
lto = "thin"
lto = true
codegen-units = 1
strip = true

[profile.release.package.server-cf-worker]
opt-level = "s" # optimize for size in release builds
10 changes: 10 additions & 0 deletions build-cf-worker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(cd crates/server-cf-worker && wasm-pack build --target bundler --out-name exograph_cf_worker)

mkdir -p target/cf-worker-dist
cp crates/server-cf-worker/pkg/*.wasm target/cf-worker-dist
cp crates/server-cf-worker/pkg/*.js target/cf-worker-dist
cp crates/server-cf-worker/js/exograph_cf_worker.js target/cf-worker-dist
cp crates/server-cf-worker/js/index.js target/cf-worker-dist
cp LICENSE target/cf-worker-dist
(cd target/cf-worker-dist/ && zip ../exograph-cf-worker-wasm.zip *)

0 comments on commit 985216c

Please sign in to comment.