Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

CL10b: raea cloud on Cloudflare Containers (sdk/cloud/deploy/cloudflare): a Worker in front of one container that sleeps when idle and wakes on the next request, its home folder kept in R2 through RAEA_CLOUD_STATE

shinyobjectz1e8b2e63dcf8
diff --git a/sdk/cloud/deploy/cloudflare/package.json b/sdk/cloud/deploy/cloudflare/package.json
new file mode 100644
index 00000000..2f8d121f
--- /dev/null
+++ b/sdk/cloud/deploy/cloudflare/package.json
@@ -0,0 +1,8 @@
+{
+ "name": "raea-cloud-cloudflare",
+ "private": true,
+ "type": "module",
+ "scripts": { "deploy": "wrangler deploy" },
+ "dependencies": { "@cloudflare/containers": "0.3.7" },
+ "devDependencies": { "wrangler": "4.152.0", "@cloudflare/workers-types": "4.20261001.0" }
+}
diff --git a/sdk/cloud/deploy/cloudflare/worker.ts b/sdk/cloud/deploy/cloudflare/worker.ts
new file mode 100644
index 00000000..5d6547db
--- /dev/null
+++ b/sdk/cloud/deploy/cloudflare/worker.ts
@@ -0,0 +1,34 @@
+// raea cloud on Cloudflare Containers (docs/cloud.feature CL10): a Worker in front of one container, which sleeps when
+// it's idle and wakes on the next request. A container's disk doesn't outlive it, so the home folder (the agents'
+// sign-ins, the workspace) is kept in R2 through raea cloud's RAEA_CLOUD_STATE: restored on start, saved on stop.
+// The server checks the token itself; the Worker passes every request, WebSockets too, to the container.
+import { Container, getContainer } from "@cloudflare/containers"
+
+interface Env {
+ RAEA: DurableObjectNamespace<RaeaCloud>
+ RAEA_CLOUD_TOKEN: string
+ RAEA_CLOUD_STATE: string
+ RAEA_CLOUD_STATE_KEY: string
+ RAEA_CLOUD_STATE_SECRET: string
+ RAEA_AGENT?: string
+ ANTHROPIC_API_KEY?: string
+ OPENAI_API_KEY?: string
+ GEMINI_API_KEY?: string
+}
+
+export class RaeaCloud extends Container<Env> {
+ defaultPort = 8080
+ sleepAfter = "15m"
+
+ constructor(ctx: DurableObjectState, env: Env) {
+ super(ctx, env)
+ const pass = ["RAEA_CLOUD_TOKEN", "RAEA_CLOUD_STATE", "RAEA_CLOUD_STATE_KEY", "RAEA_CLOUD_STATE_SECRET", "RAEA_AGENT", "ANTHROPIC_API_KEY", "OPENAI_API_KEY", "GEMINI_API_KEY"] as const
+ this.envVars = Object.fromEntries(pass.filter((k) => env[k]).map((k) => [k, env[k] as string]))
+ }
+}
+
+export default {
+ async fetch(req: Request, env: Env): Promise<Response> {
+ return getContainer(env.RAEA, "raea").fetch(req)
+ },
+}
diff --git a/sdk/cloud/deploy/cloudflare/wrangler.jsonc b/sdk/cloud/deploy/cloudflare/wrangler.jsonc
new file mode 100644
index 00000000..46fb136f
--- /dev/null
+++ b/sdk/cloud/deploy/cloudflare/wrangler.jsonc
@@ -0,0 +1,27 @@
+// raea cloud on Cloudflare Containers (worker.ts). From sdk/cloud/deploy/cloudflare, after `npm install`:
+//
+// npx wrangler secret put RAEA_CLOUD_TOKEN # openssl rand -hex 32
+// npx wrangler r2 bucket create raea-cloud-home
+// npx wrangler secret put RAEA_CLOUD_STATE # https://ACCOUNT_ID.r2.cloudflarestorage.com/raea-cloud-home/home.tar.zst
+// npx wrangler secret put RAEA_CLOUD_STATE_KEY # an R2 API token's access key id, scoped to that bucket
+// npx wrangler secret put RAEA_CLOUD_STATE_SECRET # and its secret
+// npx wrangler deploy # builds image/Dockerfile (RAEA_VERSION and AGENTS: its defaults)
+{
+ "name": "raea-cloud",
+ "main": "worker.ts",
+ "compatibility_date": "2026-10-01",
+ "containers": [
+ {
+ "class_name": "RaeaCloud",
+ "image": "../../image/Dockerfile",
+ "image_build_context": "../..",
+ // 4 vCPU, 12 GiB, 20 GB of disk: raea renders on the CPU here
+ "instance_type": "standard-4",
+ "max_instances": 1
+ }
+ ],
+ "durable_objects": { "bindings": [{ "name": "RAEA", "class_name": "RaeaCloud" }] },
+ "migrations": [{ "tag": "v1", "new_sqlite_classes": ["RaeaCloud"] }],
+ "vars": { "RAEA_AGENT": "kimi-code" },
+ "observability": { "enabled": true }
+}