This project offers an open source implementation of the Turborepo custom remote cache server purpose-built from the ground up for Cloudflare Workers
📚 For detailed documentation, please refer to our official website
[!IMPORTANT] You can now store your build artifacts in either Cloudflare 🪣 R2 or 🔑 KV storage. Find out how in our official documentation
If you're a Turborepo user, this project offers compelling advantages:
This project already comes with wrangler (cloudflare's CLI tool for managing works) installed and configured, so all you need to do is clone this repository and run pnpm run deploy.
# 1. Clone the repository
git clone https://github.com/AdiRishi/turborepo-remote-cache-cloudflare.git
# 2. Install packages
pnpm install
# 3. Create the R2 bucket for storage
pnpm wrangler r2 bucket create turborepo-cache
# 4. Publish the project
pnpm run deploy
# 5. Set a Bearer auth token
echo "SECRET" | pnpm wrangler secret put TURBO_TOKEN
In order to successfully run the deploy Github action you will need the following secrets
CLOUDFLARE_API_TOKENCLOUDFLARE_ACCOUNT_IDTURBO_TOKENFor those who have forked this repository, feel free to delete the release.yml workflow file. This is only used to automatically publish new releases of this repository to GitHub releases.
This project sets up a cron trigger for Cloudflare workers, which automatically deletes old cache files within the bound R2 bucket. This behavior can be customized:
BUCKET_OBJECT_EXPIRATION_HOURS option in wrangler.jsonc or set it via workers environment variablesHere's my recommended approach for setting up remote caching in your Turborepo project. You can read more about this topic in the official Turborepo documentation.
turbo.jsonModify the turbo.json file at your project root to include signature validation
{
"remoteCache": { "signature": true }
}
dotenv-cliInstall the dotenv-cli npm package:
# You may have to add -W if you are installing this on your workspace root
pnpm add -D dotenv-cli
.env FileCreate a .env file at your project root with the following content:
TURBO_API=YOUR_API_URL # Remember to remove the trailing slash
TURBO_TEAM=team_my_team_name
TURBO_TOKEN=SECRET # The turbo token must be a valid Bearer auth token
TURBO_REMOTE_CACHE_SIGNATURE_KEY=SECRET
Keep the following in mind
SECRET and YOUR_API_URL with your chosen values.TURBO_API value must not end with a trailing slashTURBO_TEAM value must begin with team_.env file to .gitignoreLoad the .env file prior to execution. Instead of running a command like turbo run build directly, use dotenv -- turbo run build. This loads everything in our .env file into the process's environment variables.
Here's how to modify your scripts in package.json to use dotenv-cli:
{
"scripts": {
"build": "dotenv -- turbo run build",
"dev": "dotenv -- turbo run dev",
"lint": "dotenv -- turbo run lint",
"test": "dotenv -- turbo run test"
}
}
And that's it 🎉🎉
Whenever you run a turbo command you will see Remote cache enabled in it's log output
pnpm lint
$ dotenv -- turbo run lint
• Packages in scope: turborepo-project, webapp, docs
• Running lint in 3 packages
• Remote caching enabled
...output
Tasks: 3 successful, 3 total
Cached: 3 cached, 3 total
Time: 1.174s >>> FULL TURBO
✨ Done in 3.54s.
Made with ❤️
$ claude mcp add turborepo-remote-cache-cloudflare \
-- python -m otcore.mcp_server <graph>