• Stars
    star
    1,917
  • Rank 24,183 (Top 0.5 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created almost 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

All-in-one, multi-tenant serverless JavaScript runtime.

Blueboat

CI

Blueboat is an all-in-one, multi-tenant serverless JavaScript runtime. See the site for a brief introduction on features.

A simple Blueboat application looks like:

Router.get("/", req => new Response("hello world"));

Router.get("/example", req => {
  return fetch("https://example.com");
});

Router.get("/yaml", req => {
  const res = TextUtil.Yaml.stringify({
    hello: "world",
  });
  return new Response(res);
});

Quickstart (single-tenant mode)

This pulls, builds, and runs the hello-world example.

Prerequisites: cargo, npm, git, docker

cargo install boatctl
git clone https://github.com/losfair/blueboat-examples
cd blueboat-examples/hello-world
npm i && boat pack -o build.json
docker run --rm -d -p 127.0.0.1:3001:3001 \
  -v "$PWD:/app" \
  --entrypoint /usr/bin/blueboat_server \
  -e RUST_LOG=info \
  -e SMRAPP_BLUEBOAT_DISABLE_SECCOMP=1 \
  ghcr.io/losfair/blueboat:v0.3.1-alpha.5 \
  -l "0.0.0.0:3001" \
  --single-tenant "/app/build.json"
curl http://localhost:3001 # "hello world"

The JavaScript API

Web API compatibility

Blueboat prefers to keep compatibility with the Web API when doing so is reasonable.

  • Things like fetch, Request, Response and URL are built-in.

No local resources

Blueboat is a โ€œdistributed-system-nativeโ€ runtime and prioritizes frictionless scalability over single-node performance. Local resources are abstracted out and replaced with their equivalents in a distributed system:

  • Files โ†’ Key-value store
  • Sockets โ†’ Event stream
  • Single-file databases โ†’ Key-value store, App.mysql and App.postgresql object families
  • FFI โ†’ WebAssembly

Read and write files

// Don't: The filesystem is a local resource
import { writeFileSync } from "fs"
writeFileSync("hello.txt", "Hello from Node")

// Do: Use the key-value store
const ns = new KV.Namespace("files")
await ns.set("hello.txt", "Hello from Blueboat")

Stream data to client

// Don't: Sockets are a local resource
import { WebSocketServer } from "ws";
const wss = new WebSocketServer({ port: 8080 });
wss.on("connection", (ws) => {
  ws.on("message", (data) => {
    console.log("received: %s", data);
  });
  ws.send("something");
});

// Do: Use the PubSub API
Router.post("/send_to_group", async req => {
  const { groupId, message } = await req.json();
  await App.pubsub.myChannel.publish(groupId, message)
  return new Response("ok");
});

Use SQL databases

// Don't: SQLite databases are stored on the local filesystem
import { DB } from "https://deno.land/x/sqlite/mod.ts";
const db = new DB("test.db");
const people = db.query("SELECT name FROM people");

// Do: Use `App.mysql` or `App.postgresql`
const people = App.mysql.myDatabase.exec("SELECT name FROM people", {}, "s");

Developing on Blueboat

You can use your favorite JS/TS bundler to build your project for Blueboat. webpack works, and other bundlers like esbuild and bun should work too.

You can package and run your apps with single-tenant mode as described in the Quickstart section, or deploy it on a multi-tenant service like MagicBoat.

TypeScript type definitions

Pull in the blueboat-types package in your TypeScript project, and add it to your tsconfig.json:

{
  "compilerOptions": {
    "types": [
      "blueboat-types"
    ]
  }
}

API documentation

While there isn't a lot of documentation on Blueboat's API yet, the global object declared in jsland can be seen as the source-of-truth of the public API.

Meanwhile, refer to the tracking issue for a high-level overview of the API.

Deploying Blueboat

There are two options for deploying Blueboat apps.

Single-tenant

This mode works well for local development and private self-hosting. The steps are described in quickstart.

Multi-tenant

This is a fully optimized mode for multi-tenant operation. See the guide to deploy a multi-tenant environment yourself, or request access to our hosted environment, MagicBoat.

Frameworks

Simple web backends with JSON API and template-based rendering can be built without requiring any third-party frameworks. If you have more complex needs like server-side rendering React or just prefer a different style of router API, third-party frameworks are also available.

Flareact

Flareact is an edge-rendered React framework built for Cloudflare Workers. Since Blueboat and Workers both implement a large (and mostly overlapping) subset of the Web API, Flareact also works on Blueboat with some modifications in the entry script.

See the source code of my blog as an example of using Flareact with Blueboat.

Contributing

Build locally

Clone the repository, and run ./build.sh.

Build process internals

Normally the build process is handled automatically by build.sh. Here are some internals, in case you need it.

Blueboat is built in three stages: jsland build, rust prebuild and rust final build. The jsland build stage bundles /jsland/; the rust prebuild stage generates a blueboat_mkimage binary that is used to generate JSLAND_SNAPSHOT from /jsland/; and the rust final build stage generates the final blueboat_server binary.

Please refer to the CI script for a reproducible set of steps.

License

Apache-2.0

More Repositories

1

mvsqlite

Distributed, MVCC SQLite that runs on FoundationDB.
Rust
1,399
star
2

RefineDB

A strongly-typed document database that runs on any transactional key-value store.
Rust
387
star
3

IceCore

Application container built for WebAssembly
Rust
111
star
4

wasm-core

Portable WebAssembly implementation intended to run everywhere
Rust
81
star
5

dlock

Distributed-Lock-as-a-Service implemented on Cloudflare Durable Objects.
TypeScript
63
star
6

rust-coroutines

Stackful coroutine library for Rust that "just works"
C
49
star
7

Violet

Superscalar RISC-V processor written in Clash.
Haskell
34
star
8

v8-serde

[WIP] Pure-JavaScript implementation of the V8 value serializer
TypeScript
32
star
9

vmesh

VMesh is a decentralized Layer 3 mesh router and protocol designed for open network interconnection.
Go
30
star
10

AlphaBoard

An HTML5 web app for teaching
JavaScript
25
star
11

hexagon-e

The HexagonE VM
Rust
24
star
12

sqlite-cache

SQLite-based on-disk cache for Rust.
Rust
23
star
13

FlatRv

A cross-platform RISC-V interpreter that implements the RV32IMA instruction set.
Rust
19
star
14

MagiCore

An out-of-order processor that supports multiple instruction sets.
Scala
18
star
15

ice-node

Node bindings for the Ice Web Framework
C++
16
star
16

AlphaTrans

An extremely fast accelerator for block transfer in unstable networks
C++
13
star
17

notion-fetch

A Cloudflare Workers service that fetches and renders Notion pages as HTML, Markdown, or JSON.
TypeScript
13
star
18

minichat

Distributed real-time chat demo on Blueboat in 15 lines of JavaScript
JavaScript
10
star
19

unproxy

Map TCP services behind an HTTP(S) proxy to local ports.
Rust
10
star
20

rm-protection-c

rm-protection implemented in C
C
10
star
21

caddy-watch

Watch for interesting patterns in Caddy logs and send a Telegram notification.
Go
9
star
22

pbft-rs

Practical Byzantine Fault Tolerance implemented in Rust.
Rust
8
star
23

bsync

Incremental, multi-version remote backup tool for block devices.
Rust
8
star
24

b6t

Minimal containerized Blueboat suitable for self-hosting.
Shell
8
star
25

lambda-box

ฮป-box ๆ˜ฏไธ€ไธช่ฟ่กŒๅœจ Blueboat ไธŠ็š„ๅŒฟๅๆ้—ฎ็ฎฑ app.
TypeScript
8
star
26

mvps

Log-structured, transactional virtual block device backed by S3
Rust
8
star
27

kvm-sandbox

Sandbox for trustless execution, implemented with KVM.
C++
7
star
28

wstunnel

IP over WebSocket.
Rust
7
star
29

edp

An implementation of the Erlang Distribution Protocol in Rust.
Rust
7
star
30

ssci

Server Side Code Integrity
Rust
7
star
31

avalanche-demo

Demos of how the Avalanche family consensus protocols (Slush, Snowflake, Snowball and Avalanche) work.
TypeScript
6
star
32

supernova

A control plane for the Nebula overlay networking system.
TypeScript
6
star
33

liquid-layout

A layout engine that solves UI constraints using the Z3 prover.
Rust
6
star
34

fdb2kafka

Ship consistent logs from FoundationDB to Kafka.
Go
6
star
35

bsdloader

Minimal (~103KB) x86_64 FreeBSD UEFI loader
Rust
6
star
36

blog

Source code for my personal site.
TypeScript
6
star
37

metamachine

Experimental CPU with software-defined instruction set.
VHDL
5
star
38

FlatMk-v0

The FlatMk Microkernel.
Rust
5
star
39

NextHDL

symbolic evaluation == circuit synthesis
Rust
5
star
40

smr

Multi-process scheduler for managed runtimes.
Rust
5
star
41

hexagon

Rust
5
star
42

elfpromote

A small utility for modifying ELF shared library loading order.
Rust
5
star
43

gkv

Geo-replicated eventually-consistent KV store
Scala
5
star
44

jslinux-wstunnel

JSLinux (https://bellard.org/jslinux/) ported to use wstunnel (https://github.com/losfair/wstunnel) for networking.
JavaScript
5
star
45

lazyproxy

A TCP proxy that is so lazy that shuts down itself after a period of inactivity.
Rust
5
star
46

luax

A Lua 5.3 implementation in Rust (work in progress)
Rust
4
star
47

tsotest

Test Total Store Ordering status on your CPU.
Rust
4
star
48

bbcp

Multi-user control plane service for Blueboat.
TypeScript
4
star
49

blueboat-mds

Blueboat Metadata Service is a distributed metadata manager for Blueboat.
JavaScript
4
star
50

fediblog

Personal site (v2)
TypeScript
4
star
51

liblightning

High-performance general-purpose stackful coroutine library
Rust
4
star
52

violet-cosim

Cosimulator for the Violet core: https://github.com/losfair/Violet
Rust
4
star
53

bbcli

Command line tool for deploying and managing apps on Blueboat.
Rust
4
star
54

blueboat-examples

Example apps running on Blueboat.
JavaScript
4
star
55

rCore-SoC-2020

Code and documentation for rCore "OS Tutorial Summer of Code 2020".
Rust
4
star
56

mips

Single-cycle and pipelined MIPS CPUs written for learning purpose. Written in 12 hours.
Verilog
4
star
57

boat

[WIP] CLI for MagicBoat.
Rust
3
star
58

cloudkernel

Distributed usermode hypervisor for modern workloads.
C++
3
star
59

bluesched

Blueboat cluster scheduler.
Elixir
3
star
60

ops

My collection of scripts for operating services, databases and systems.
Shell
3
star
61

hgw

A "secure enclave" I run at home
Go
3
star
62

gluon

[WIP] Launch selfhosted apps in one click with mvSQLite and Fly.io
TypeScript
3
star
63

awesome-blueboat

A curated collection of web apps on the Blueboat engine.
3
star
64

jftp

Just Forward The Port
Rust
3
star
65

OxygenMark

C++
3
star
66

particles-rs

Particles effects implemented in Rust and running on the WebAssembly platform
Rust
3
star
67

node-multithread

Multithread for Node.js
C++
3
star
68

rekor-evm

Sigstore Rekor log rollup to EVMs
Rust
2
star
69

Presenter.js

Present your slides easily, with remote control.
JavaScript
2
star
70

morf

MoRF is a mutually-authenticated, encrypted communication protocol over lossy packet links with small MTUs
Rust
2
star
71

notion-blueboat

Notion website on Blueboat.
2
star
72

caddy-log-kafka

A Caddy log writer that writes logs to Kafka.
Go
2
star
73

tunnelme

A selfhosted tunnel service.
Haskell
2
star
74

mips-x

Another MIPS32 CPU. My course design for Computer Organization @ NUAA, 2020 Spring.
Verilog
2
star
75

bfjit-osr

Brainfuck JIT for demonstrating On-Stack Replacement technology.
Rust
2
star
76

naptd

Rust
2
star
77

caddy-log-to-mysql

Import Caddy logs to MySQL for analysis.
Rust
2
star
78

pl0-jit

JIT compiler targeting x86-64 for PL/0. Homework.
Rust
2
star
79

DeepDark

Process manager for Linux servers
C++
2
star
80

rvjit-aa64

RISC-V static binary translator targeting AArch64.
Rust
2
star
81

acquire

Digital remake of the "Acquire" board game
Gleam
2
star
82

blueanalytics

Self-hosted web analytics for Caddy + Blueboat.
TypeScript
1
star
83

TextSharing

Text Sharing
1
star
84

retls

Re-encrypt TLS connection with a different certificate
Rust
1
star
85

CloudEdu

A light web app for education.
JavaScript
1
star
86

bdtts-go

Unofficial Baidu TTS API for Golang
Go
1
star
87

SharpIce

C# web framework based on Ice Core
C#
1
star
88

OxygenMark-PageEngine

OxygenMark PageEngine
JavaScript
1
star
89

html2md

A fork of https://gitlab.com/Kanedias/html2md .
Rust
1
star
90

wavebpf-hw

Haskell
1
star
91

orange-rs

Hardware support crate for OrangeSoC.
Rust
1
star
92

FutureCore-Terminal

Terminal control & VM for FutureCore
C
1
star
93

pyice_base

C++
1
star
94

losfair

1
star
95

magicore-aas

MagiCore as a Service (https://github.com/losfair/MagiCore)
Rust
1
star
96

dockerfiles

My collection of dockerfiles.
Dockerfile
1
star
97

virtual-dom-rs

Rust
1
star
98

blurry

[WIP] Toy GPT frontend written in Haskell that runs on Deno
1
star
99

UniMessTunnel

Go
1
star