Getting started
Deploy from code
Build and roll out Workers on a Rivet cluster from your own deploy tooling with the open-orange TypeScript SDK.
The open-orange package is also a TypeScript SDK for orange deploy. Your deploy
pipeline builds and rolls out Workers with typed results and errors, and parses no
CLI output.
Quickstart
You need what orange deploy needs: Docker running, a Rivet Cloud cluster, and a
Worker project with its packages installed. See Deploy.
-
Add the package
pnpm add open-orange -
Write the deploy
deploytakes theorange deployflags as options and resolves to the same result as the last line oforange deploy --json. Save this asdeploy.mts:import { deploy } from "open-orange"; const result = await deploy({ configPath: "workers/api/wrangler.jsonc", cluster: "my-cluster", onEvent: (event) => console.error(event.type), }); if (result.type === "deployed") console.log(result.buildId, result.url); -
Run it
Node.js 22.18 and later run TypeScript files directly.
node deploy.mts
Build once, roll out twice
build makes the image and uploads it, and rolls out nothing. rollout puts a
ready build on a runner pool. So a pipeline promotes the build it tested:
import { build, rollout } from "open-orange";
const target = { configPath: "wrangler.jsonc", cluster: "my-cluster" };
const { buildId } = await build(target);
await rollout({ ...target, build: buildId, pool: "staging" });
await rollout({ ...target, build: buildId, pool: "production" });
Handle errors
A failed call rejects with a typed error. _tag names it, and reportable is true
when the failure may be a bug in Orange or Rivet Cloud, so a retry or a bug report
can help.
import { deploy, RivetCloudError } from "open-orange";
try {
await deploy({ cluster: "my-cluster" });
} catch (error) {
if (error instanceof RivetCloudError && error.status === 401) console.error("Rotate RIVET_CLOUD_TOKEN.");
throw error;
}
Use it from Effect
deployEffect, buildEffect, and rolloutEffect are the same calls as
Effect programs. Provide deployLiveLayer and an
Output, and replace any service, such as ImageBuilder for a remote builder:
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import { deployEffect, deployLiveLayer, eventOutputLayer, ImageBuilder } from "open-orange";
// `myBuilder` is your builder's client. Its methods return Effects.
const remoteBuilder = Layer.succeed(
ImageBuilder,
ImageBuilder.of({
preflight: () => Effect.void,
build: (image) => myBuilder.build(image),
save: (reference, tarballPath) => myBuilder.download(reference, tarballPath),
}),
);
const result = await deployEffect({ cluster: "my-cluster" }).pipe(
Effect.provide(remoteBuilder),
Effect.provide(Layer.merge(deployLiveLayer, eventOutputLayer((event) => console.error(event.type)))),
Effect.runPromise,
);
AI context Every call, option, result, event, error, and service
Written for LLMs and coding agents: every edge case, measurement, and known deviation. You do not need it to use the feature.
Calls
| Promise | Effect | What it does | Resolves to |
|---|---|---|---|
deploy(options) | deployEffect(options) | orange deploy: a build and a rollout, or a rollout of build, or a dry run | DeployedResult or DryRunResult |
build(options) | buildEffect(options) | Builds the image, uploads it, and waits until Rivet Cloud has prepared it | BuildResult |
rollout(options) | rolloutEffect(options) | Rolls a runner pool out to a ready build and waits until every node runs it | DeployedResult |
runOrange(args, io?) | Runs the orange CLI in this process, as orange <args> | The exit code |
The Promise forms take onEvent too. The Effect forms need DeployServices:
Credentials, RivetCloud, WorkerConfig, ImageBuilder, and Output.
rolloutEffect builds nothing, so it needs no ImageBuilder.
Options
Every call takes these:
| Option | Default | Notes |
|---|---|---|
cwd | The directory of configPath, else the current directory | Relative paths and the .rivet/project.json link that orange link saved are found from here. |
configPath | The nearest wrangler.json in cwd or a parent, else the nearest wrangler.jsonc, else wrangler.toml, as Wrangler and orange deploy find it | |
environment | None | The Wrangler environment, as -e. |
cluster | RIVET_CLUSTER, then the link in cwd | |
org | RIVET_ORG, then the link | |
token | RIVET_CLOUD_TOKEN, then the orange login session | A Rivet Cloud token. |
cloudApi | https://cloud-api.rivet.dev | |
onEvent | None | Promise forms only. Receives each event. |
build and deploy also take:
| Option | Default | Notes |
|---|---|---|
image | The Worker’s name | |
tag | The UTC time and 4 random hex digits, such as 20261028-213000-3f9a | |
outdir | A new directory for each call, removed after the image is saved | Where the Dockerfile and build context go. |
secretsFiles | None | Their values never enter the image. |
rollout and deploy also take region (default: the cluster’s only region),
pool (default default), machineType, nodeCount, vars (NAME:value),
secrets (KEY or KEY=SECRET_NAME), and secretsFiles. They mean what the
orange deploy flags of the same name mean. See Deploy.
rollout needs build, the ID of a ready build. deploy takes build to roll
one out instead of building, and dryRun to write the build context and return
the plan. A dry run calls no API and needs no Docker. Without outdir, its
context stays in a new directory that the result names.
Results
| Type | Fields |
|---|---|
DeployedResult | type: "deployed", buildId, reference (image:tag, unset when Rivet Cloud does not report the image of a build passed as build), cluster, region, pool, url |
BuildResult | buildId, reference |
DryRunResult | type: "dry_run", dockerfile, context, reference, build, cluster, region, pool, cloudApi, hasToken, variables, secrets, selfHost (build and run as argument lists) |
Events
onEvent and eventOutputLayer receive the events that orange deploy --json
prints, except failure, which is the rejected error instead:
| Event | Fields |
|---|---|
warning | message |
start | image, cluster, region, pool |
image_build | reference |
upload | buildId, bytes |
upload_retry | attempt, reason, waitMs |
prepare, build_ready | buildId |
secret | name, changed, version |
unpin | names |
rollout | pool, buildId, created |
deployed, dry_run | The result |
build emits warning, image_build, upload, upload_retry, prepare, and
build_ready. rollout emits warning, start, secret, unpin, rollout,
and deployed.
Orange does not wait for a listener. A listener that throws, or returns a promise
that rejects, does not change the result. Orange reports it with
process.emitWarning as an OpenOrangeEventListenerWarning, whose cause is the
error.
Errors
| Error | When |
|---|---|
UsageError | An invalid option, such as nodeCount: 0 |
CredentialsError | No cluster, no token, or a sign-in that cannot be read or refreshed |
WorkerConfigError | The Wrangler configuration cannot be read or is invalid |
DockerError | Docker is missing, its daemon does not answer, or a Docker command failed |
RivetCloudError | Rivet Cloud refused a request, answered with something unexpected, or could not be reached. status holds the HTTP status. |
DeployError | The deploy itself failed, such as a build or a rollout |
Each is an Error with _tag and message. All but UsageError and
CredentialsError have reportable. OrangeError is their union. A defect, any
other thrown error, rejects as itself.
Calls that run at once
Calls in one process can run at the same time. Each one writes its build context
to a directory of its own and tags its image with a random suffix. Two calls that
pass the same outdir, or build the same image:tag, at the same time: the
second rejects with a DeployError.
Limits
- Two calls that run a project’s
build.commandat the same time can each bundle what the other one wrote. Run one build of a project at a time. - Interrupting an Effect call while it writes its build context can leave that work running. Do not reuse its
outdiruntil the process ends. - Two calls that reach one
outdirthrough different paths, such as a symlink, are not seen as the same directory.
Environment
RIVET_CLOUD_TOKEN,RIVET_CLUSTER, andRIVET_ORGare read through Effect’sConfig. AConfigProviderreplaces them. A variable that the provider leaves out has no value:process.envis not read.- Docker’s output and the output of
build.commandgo to stderr. - The SDK leaves
WRANGLER_LOGas the caller set it.
Services
| Service | What it does | Live implementation in deployLiveLayer |
|---|---|---|
Credentials | Resolves the cluster, organization, Cloud API, and token | Options, then the environment, the link, and orange login |
RivetCloud | The Rivet Cloud API client and the image upload | HTTP, with retries for GET, PUT, and the upload |
WorkerConfig | Loads the Worker’s resolved configuration | The Wrangler configuration file |
ImageBuilder | preflight(), build({ contextDirectory, dockerfilePath, reference }), and save(reference, tarballPath), which writes a docker image save tarball | docker on PATH |
Output | Receives events | Not in deployLiveLayer. Use eventOutputLayer(onEvent). |