Skip to content

Rivet.GCP reference

Source: packages/rivet/src/GCP/CloudRunPool.ts

Run a pool’s nodes on a Cloud Run worker pool: a pool on the control plane, and a worker pool whose instances host every Rivet.DurableObject given this pool. Worker pools serve no requests and keep a fixed number of instances running, which is what a node is: it only connects out to the control plane. Works with any control plane it can reach — RivetGCP.ComputeEngineControlPlane, RivetCloud.ControlPlane, or one on another cloud.

Every Durable Object given the same pool shares its nodes: declare the pool once and provide it to each class.

A deploy that changes the nodes rolls out a new worker pool revision. To move actors off the old nodes before Cloud Run stops them, give each deploy a higher version and set drainOnVersionUpgrade.

CloudRunPool: Running Durable Objects on Cloud Run

Section titled “CloudRunPool: Running Durable Objects on Cloud Run”

Two nodes

export const Cluster = RivetGCP.ComputeEngineControlPlane("Rivet");
export const Default = RivetGCP.CloudRunPool("Default", { replicas: 2 }).pipe(
Layer.provide(Cluster),
);

Secrets, a private network, and draining on deploy

export const Default = RivetGCP.CloudRunPool("Default", {
replicas: 2,
serviceAccount: "nodes@acme.iam.gserviceaccount.com",
network: "private",
subnetwork: "private-us-central1",
env: { RIVET_ENDPOINT: "http://10.0.0.2:6420" },
version: 42,
secrets: {
RIVET_TOKEN: "projects/acme/secrets/rivet-token/versions/1",
DATABASE_URL: "projects/acme/secrets/database-url/versions/3",
},
drainOnVersionUpgrade: true,
actorEvictionPeriod: 60,
}).pipe(Layer.provide(Cluster));

Source: packages/rivet/src/GCP/ComputeEngineControlPlane.ts

A Rivet control plane on Compute Engine, as a Rivet.Cluster Layer: instances across zones, each running the engine container with a persistent disk of its own, a Cloud Storage bucket for the durable copy of every actor’s data (reached as the instances’ own service account), and a Cloud Run service in front. Callers reach it over HTTPS at the service’s run.app address, so it needs no domain of your own; the service proxies to the engines through a Serverless VPC Access connector, and the engines take no traffic from outside their network. Instances find each other through the bucket and talk on a private port only they can reach. A namespace is created for the stage.

Each data disk is its own resource, so it outlives the instance it is attached to: a replaced instance mounts the same disk again.

ComputeEngineControlPlane: Running a control plane on GCP

Section titled “ComputeEngineControlPlane: Running a control plane on GCP”

Three instances

export const Cluster = RivetGCP.ComputeEngineControlPlane("Rivet");

Larger instances and disks

export const Cluster = RivetGCP.ComputeEngineControlPlane("Rivet", {
machineType: "n2-standard-4",
diskSize: 100,
});

Source: packages/rivet/src/GCP/ComputeEnginePool.ts

Run a pool’s nodes on Compute Engine: a pool on the control plane, and Container-Optimized OS instances across zones that each run every Rivet.DurableObject given this pool in a Node container. The node program sits in a Cloud Storage bucket the instances read as their own service account; a deploy that changes it, or the nodes’ env, restarts the container on each instance in place, one node at a time: a node restarts once the one before it runs the new program and the control plane lists every node connected, and gets stopTimeout seconds to stop.

Nodes only connect out to the control plane, so no inbound traffic reaches them, and the pool works with any control plane it can reach — RivetGCP.ComputeEngineControlPlane, RivetCloud.ControlPlane, or one on another cloud. On a RivetGCP.ComputeEngineControlPlane the nodes join its network.

ComputeEnginePool: Running Durable Objects on Compute Engine

Section titled “ComputeEnginePool: Running Durable Objects on Compute Engine”
export const Cluster = RivetGCP.ComputeEngineControlPlane("Rivet");
export const Default = RivetGCP.ComputeEnginePool("Default", { replicas: 2 }).pipe(
Layer.provide(Cluster),
);

Source: packages/rivet/src/GCP/ServicesPool.ts

Run Rivet Services on a Cloud Run worker pool: the services pool on the control plane, and a worker pool running Rivet’s prebuilt Services node, which hosts Durable Streams and agentOS. Worker pools serve no requests and only connect out to the control plane: callers reach every stream through its gateway, with its token. Works with any control plane it can reach.

ServicesPool: Running Rivet Services on GCP

Section titled “ServicesPool: Running Rivet Services on GCP”
export const Cluster = RivetGCP.ComputeEngineControlPlane("Rivet");
export const Services = RivetGCP.ServicesPool("Services").pipe(Layer.provide(Cluster));