Deploy to Cloudflare
Every detail of the Cloudflare deployment, from the button or a terminal, plus deploys on every push.
Get started is the short version of this page. Cloudflare Workers is the default platform. It’s the only one with built-in R2 and KV storage, a scheduled expiry task, and a stats database that needs no setup.
Before you begin
-
Turn on R2. If your account has never used it, open R2 Object Storage in the Cloudflare dashboard and follow the steps there. The free tier includes 10 GB a month.
-
Generate a token. Your Worker and every
turboclient share it:openssl rand -hex 32Anyone with this token can read and write every team’s artifacts. One token opens every team explains why.
Deploy with the button
- Select Deploy to Cloudflare and sign in to Cloudflare.
- Connect your GitHub or GitLab account. Cloudflare copies this repository into it and creates a Worker that builds from the copy with Workers Builds.
- Keep the build command,
pnpm run build, and the deploy command,pnpm run deploy. Both run from the repository root, because the server depends on other packages in the workspace. - Wait for the first deploy to finish. It creates the
turborepo-remote-cacheWorker, theturborepo-cacheR2 bucket, and theturborepo-cache-statsD1 database for the dashboard. - Go to Workers & Pages, select the Worker, and open Settings > Variables and Secrets. Add a secret named
TURBO_TOKENwith your token as its value. - Copy the Worker’s URL, such as
https://turborepo-remote-cache.<your-subdomain>.workers.dev.
Until TURBO_TOKEN is set, every cache request gets a 500. The deploy worked. The server just won’t serve anyone without a token.
Deploy from a terminal
You need Node.js 24 or later and pnpm. Install the version in the repository’s packageManager field, using the pnpm installation guide.
-
Clone the repository and install its dependencies:
git clone https://github.com/AdiRishi/turborepo-remote-cache-cloudflare.git cd turborepo-remote-cache-cloudflare pnpm install -
Remove
remoteCachefrom the rootturbo.json, or point it at your own server. It sends this repository’s builds to the maintainer’s cache, and withTURBO_TOKENin your shell,turbowould send your token there too. -
Build the Worker and deploy it:
pnpm build pnpm run deployWrangler opens a browser to sign you in to Cloudflare if you aren’t signed in yet. On the first deploy, it creates the
turborepo-cacheR2 bucket and theturborepo-cache-statsD1 database. When it finishes, it prints the Worker’s URL. -
Set the token:
cd apps/api pnpm exec wrangler secret put TURBO_TOKENWrangler asks for the value. Paste your token.
Check the deployment
Put your Worker’s URL and token in the terminal, then knock on the door:
CACHE_URL='https://turborepo-remote-cache.<your-subdomain>.workers.dev'
export TURBO_TOKEN='<your token>'
curl "$CACHE_URL/ping"
curl -H "Authorization: Bearer $TURBO_TOKEN" "$CACHE_URL/v8/artifacts/status"
The first request answers pong, and needs no token. The second answers {"status":"enabled"}. A 401 means the token doesn’t match the Worker’s secret. For anything else, see turbo cannot connect.
Then connect turbo and check that your builds hit the server.
Deploy changes from Git
Pick one service to deploy pushes to your copy. If you set up both, both deploy the same commit.
Workers Builds
If you used the button, Workers Builds is already set up. It deploys every push to your copy’s production branch. Keep the build directory at the repository root, the build command at pnpm run build, and the deploy command at pnpm run deploy.
GitHub Actions
The repository’s CI workflow deploys pushes to master after checks and end-to-end tests pass. To use it in your copy:
- Delete the
release,docs-cloudflare, anddocs-github-pagesjobs. They publish this project’s releases and documentation. - Add these repository secrets under Settings > Secrets and variables > Actions:
CLOUDFLARE_API_TOKEN: a token that can edit Workers, R2, and D1.CLOUDFLARE_ACCOUNT_ID: your Cloudflare account ID.TURBO_TOKEN: the same token your clients use. The workflow sets it as the Worker’s secret on each deployment. If this secret is missing, the Worker’s token becomesSECRET.
- Remove
remoteCachefrom the rootturbo.json, or point it at your own server. The workflow passesTURBO_TOKENto everyturborun, so without this step it sends your token to the maintainer’s cache. - Push to
master. If you use a different production branch, update the workflow’s branch filters and deployment condition.
When a new release comes out, Update your deployment shows how to merge it into your copy.