Self-hosted remote Turborepo cache for Cloudflare Workers.
- Set up a Cloudflare account
- Clone this repo
- Create a Github Actions Secret
CLOUDFLARE_ACCOUNT_ID
and set it to your Cloudflare account ID - Create an access token in Cloudflare and store it as the Github Actions Secret
CLOUDFLARE_API_TOKEN
- Run
yarn
- Run
yarn wrangler login
to authenticate - Run
yarn wrangler kv:namespace create "TURBO_CACHE"
to create a KV namespace, and replace this line inwrangler.toml
with what the previous command tells you to.{ binding = "TURBO_CACHE", id = "fe734ad580ec407f9fec0aeba92d0407" }
- Generate a secret value to authenticate your requests. You can use this command for example:
node -p 'require("crypto").randomBytes(32).toString("hex")'
- Store this value as a secret in your Cloudflare Account:
and paste it when asked to.
wrangler secret put SECRET_TOKEN
- Store the same value as an Github Actions secret
TURBO_CACHE_TOKEN
in the repo you want to use Turborepo Remote Caching in. - Store the address of your worker as another secret
TURBO_CACHE_SERVER
in the same repo. - Configure an env variable in your workflows:
and append it to every command that uses Turborepo, e.g.
env: TURBO_FLAGS: "--api=${{ secrets.TURBO_CACHE_SERVER }} --token=${{ secrets.TURBO_CACHE_TOKEN }} --team=<your-team-name>"
- name: Compile TypeScript code run: yarn build $TURBO_FLAGS