Skip to content
This repository was archived by the owner on Dec 21, 2024. It is now read-only.

Commit b858aa1

Browse files
committed
chore: add support for tar images for js
1 parent e3842d5 commit b858aa1

20 files changed

+262
-212
lines changed

ACTOR_CRASH_COURSE.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Actor Crash Course
2+
3+
## Prerequisites
4+
5+
- Must have Rivet docker compose running
6+
- Must have hub running just for the device link
7+
8+
## Actor test
9+
10+
```bash
11+
cargo build
12+
cd examples/js-deno
13+
../../target/debug/rivet login --api-endpoint http://localhost:8080
14+
# copy the path to localhost:5080/device/link/... and finish linking
15+
../../target/debug/rivet deploy default
16+
# copy build id
17+
../../target/debug/rivet actor create default -t name=rng --build MY_BUILD_ID --region local --network-mode host --port protocol=tcp,name=http,host
18+
# copy public_hostname and public_port
19+
curl 127.0.0.1:20081
20+
../../target/debug/rivet actor destroy default --id MY_ACTOR_ID
21+
```
22+
23+
## Reference
24+
25+
- See `rivet --help` for more commands
26+
- rivet.jsonc config spec at `packages/toolchain/src/config/mod.rs`
27+
- WIP typedefs for actors [here](https://github.com/rivet-gg/rivet/blob/925b9b5c2f024f40615e910e9670655249eb2bc7/sdks/actor-types/src/internal/90_rivet_ns.ts)
28+
29+
## Known issues
30+
31+
- Only supports host networking
32+
- Networking is not working (afaik)
33+
- LZ4 compression for JS tars don't work (defaults to correct compression, no action needed)
34+
35+
## Troubleshooting
36+
37+
### `Error getting bootstrap: get project failed`
38+
39+
Make sure to run `rivet logout` if you reset the core cluster.
40+

examples/actor-layer/index.ts

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Without Rivet actor class
2+
3+
const portStr = Deno.env.get("PORT_http") ?? Deno.env.get("HTTP_PORT");
4+
if (!portStr) throw "Missing port";
5+
const port = parseInt(portStr);
6+
if (!isFinite(port)) throw "Invalid port";
7+
8+
const server = Deno.serve({
9+
handler,
10+
port,
11+
hostname: "0.0.0.0",
12+
});
13+
14+
await server.finished;
15+
16+
async function handler(req: Request) {
17+
console.log("Received request");
18+
19+
let newCount = (await Rivet.kv.get("count") ?? 0) + 1;
20+
await Rivet.kv.put("count", newCount);
21+
22+
return new Response(newCount.toString());
23+
}
24+
25+
// With Rivet actor class
26+
27+
import { Actor } from "@rivet-gg/rivet";
28+
29+
interface State {
30+
count: number;
31+
}
32+
33+
class Counter extends Actor<State> {
34+
initialize(): State {
35+
return { count: 0 };
36+
}
37+
38+
async onRequest(req) {
39+
this.count += 1;
40+
return new Response(this.count.toString());
41+
}
42+
}
43+
44+
Rivet.run(Counter);

examples/js-deno/rivet.jsonc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "2.0",
33
"builds": [
44
{
5-
"tags": { "name": "rng-http" },
5+
"tags": { "name": "rng" },
66
"runtime": "javascript",
77
"script": "rng_http.ts"
88
}

examples/js-deno/rng_http.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { randomIntegerBetween, randomSeeded } from "@std/random";
22

3+
console.log("Hello, world!");
34
console.log(Deno.env.toObject());
45

5-
const portStr = Deno.env.get("PORT_ds_http") ?? Deno.env.get("HTTP_PORT");
6+
const portStr = Deno.env.get("PORT_http") ?? Deno.env.get("HTTP_PORT");
67
if (!portStr) throw "Missing port";
78
const port = parseInt(portStr);
89
if (!isFinite(port)) throw "Invalid port";

examples/js-kv/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
await Rivet.kv.put("count", 0);
2+
3+
console.log('Started', Deno.env.toObject());
4+
setInterval(async () => {
5+
let x = await Rivet.kv.get("count");
6+
await Rivet.kv.put("count", x + 1);
7+
console.log('Count', x);
8+
}, 1000);

examples/js-kv/rivet.jsonc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": "2.0",
3+
"builds": [
4+
{
5+
"tags": { "name": "kv" },
6+
"runtime": "javascript",
7+
"bundler": "none",
8+
"script": "index.js"
9+
}
10+
]
11+
}

packages/toolchain/src/config/build/docker.rs

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub enum BuildMethod {
6666
}
6767

6868
#[derive(Debug, Copy, Clone, Serialize, Deserialize, strum::AsRefStr)]
69+
#[serde(rename_all = "snake_case")]
6970
pub enum BundleKind {
7071
/// Legacy option. Docker image archive output from `docker save`. Slower lobby start
7172
/// times.

packages/toolchain/src/config/build/javascript.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ pub struct Unstable {
4141
pub minify: Option<bool>,
4242
pub analyze_result: Option<bool>,
4343
pub esbuild_log_level: Option<String>,
44-
// TODO(RVT-4127): Add compression support
45-
// pub compression: Option<Compression>,
44+
pub compression: Option<Compression>,
4645
}
4746

4847
impl Unstable {
@@ -60,8 +59,8 @@ impl Unstable {
6059
.unwrap_or_else(|| "error".to_string())
6160
}
6261

63-
// TODO(RVT-4127): Add compression support
6462
pub fn compression(&self) -> Compression {
65-
Compression::None
63+
// TODO: Change back to Lz4 default
64+
self.compression.unwrap_or(Compression::None)
6665
}
6766
}

packages/toolchain/src/config/build/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub enum Runtime {
1212
}
1313

1414
#[derive(Debug, Copy, Clone, Serialize, Deserialize, strum::AsRefStr)]
15+
#[serde(rename_all = "snake_case")]
1516
pub enum Compression {
1617
/// No compression.
1718
#[strum(serialize = "none")]

packages/toolchain/src/config/mod.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,4 @@ pub struct Build {
6464

6565
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
6666
#[serde(rename_all = "snake_case", deny_unknown_fields)]
67-
pub struct Unstable {
68-
#[serde(skip_serializing_if = "Option::is_none")]
69-
pub multipart_enabled: Option<bool>,
70-
}
71-
72-
impl Unstable {
73-
pub fn multipart_enabled(&self) -> bool {
74-
self.multipart_enabled.unwrap_or(true)
75-
}
76-
}
67+
pub struct Unstable {}

0 commit comments

Comments
 (0)