Turborepo Remote Cache (TRRC)
repository·main·Indexed 23 days ago
https://github.com/ducktors/turborepo-remote-cacheAn open-source, self-hosted alternative to Vercel's remote cache server for Turborepo. Version 2.11.5 supports multiple storage providers including local, S3, Google Cloud Storage, and Azure Blob Storage. It features three authentication modes (static, JWT, and none), artifact integrity verification via signing, and a read-only mode for CI-populated caches. Deployment options include Docker, DigitalOcean, Vercel, AWS Lambda, and GCP Cloud Run.
What's inside turborepo-remote-cache
- Turborepo Remote Cache (TRRC) is an open-source implementation of the Turborepo custom remote cache server. It serves as a self-hosted alternative to Vercel's official cache server, allowing developers to host their own remote cache for Turborepo monorepos. The project supports multiple storage providers and various deployment environments.
Overview of Turborepo Remote Cache (TRRC)
mainTurborepo Remote Cache (TRRC) is an open-source implementation of the Turborepo custom remote cache server. It serves as a self-hosted alternative to Vercel's official cache server, allowing developers to host their own remote caching infrastructure. The project supports multiple storage providers and various deployment environments, often providing one-click deployment options.Configure HTTP/2 for large artifact support in Cloud Run
mainCloud Run imposes a 32 MiB request size limit if HTTP/2 is not enabled. To support Turborepo artifacts larger than 32 MiB, you must enable HTTP/2 support in your deployment.
To do this:
- Set the environment variable
HTTP2totrue. - In the Cloud Run Networking tab, enable the Use HTTP/2 end-to-end option.
If you choose not to use HTTP/2, you must remove the
HTTP2environment variable and disable the Use HTTP/2 end-to-end option in the Networking tab, but be aware that artifacts will be limited to 32 MiB.- Set the environment variable
Configure Authentication Modes
mainThe server supports three authentication modes via the
AUTH_MODEenvironment variable. Choose the mode that fits your security requirements:static: Uses a secret token for authentication. You must provide one or more tokens viaTURBO_TOKEN(comma-separated). This is the default mode.jwt: Uses JSON Web Tokens for authentication. RequiresJWKS_URLto retrieve public keys for verification. You can optionally configureJWT_ISSUER,JWT_AUDIENCE, and scope requirements usingJWT_READ_SCOPESandJWT_WRITE_SCOPES.none: Disables authentication (not recommended for production).
If using
staticmode, ensure theTURBO_TOKENmatches thetokenparameter provided in your Turborepobuildscript.Enable custom remote caching in your Turborepo project
mainTo use a custom
turborepo-remote-cacheserver instead of Vercel's, you must manually configure the connection. Note thatturbo loginandturbo linkonly work with Vercel's remote cache.1. Create a configuration file
Create a
.turbo/config.jsonfile at the root of your repository and specify theapiurl:{ "apiurl": "http://cache.ducktors.dev" }2. Provide credentials
You must provide
TURBO_TEAMandTURBO_TOKENusing one of the following three methods. Prefer using environment variables for security.Method A: Environment Variables (Recommended)
Set
TURBO_TEAMandTURBO_TOKENas environment variables in your local shell or CI pipeline. These will override any values found in.turbo/config.json.Method B: Config File
Add
teamslugandtokendirectly to.turbo/config.json.Warning: Including the
tokenin this file is less secure if you commit the file to version control.{ "apiurl": "http://cache.ducktors.dev", "teamslug": "ducktors", "token": "myGeneratedToken" }Method C: package.json Scripts (Not Recommended)
Pass
--teamand--tokenas flags to your turbo commands inpackage.json.Warning: This is insecure as the token is committed to the repository.
{ "scripts": { "build": "turbo run build --team=\"ducktors\" --token=\"myGeneratedToken\"" } }{ "apiurl": "http://cache.ducktors.dev" }Configure DigitalOcean Spaces
mainDigitalOcean Spaces is supported as an S3-compatible provider. Follow these steps:
- Create a Space.
- Generate a new spaces access key.
- Set the following environment variables:
STORAGE_PROVIDER=s3AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYfrom your access key.AWS_REGION=us-east-1(Note: DigitalOcean usesus-east-1for SDK compatibility).STORAGE_PATH: The name of your Space.S3_ENDPOINT: The endpoint of your Space (e.g.,https://nyc3.digitaloceanspaces.com).
Deploy the cache server as a Google Cloud Run service
mainThis guide outlines how to deploy
turborepo-remote-cacheto Google Cloud using a Cloud Run service and a Cloud Storage bucket for persistence.Step 1: Create a Cloud Storage Bucket
Create a bucket in the Cloud Storage console with these settings:
- Location type: Regional (closest to you).
- Storage class: Standard.
- Prevent public access: Enabled with Uniform access control.
- Data protection: Retention duration set to 0 days.
- Lifecycle rule (Recommended): Set a rule to automatically delete objects older than a few weeks to manage stale cache data.
Step 2: Deploy the Cloud Run Service
Deploy a new service in the Cloud Run console using the following configuration:
- Container Image:
ducktors/turborepo-remote-cache:latest - Region: Your closest region.
- Authentication: Disable Use Cloud IAM to authenticate incoming requests.
- Billing: Select Request-based billing.
- Scaling:
- Minimum instances:
0 - Maximum instances:
1(The service uses a shared bucket and has not been tested with multiple concurrent instances).
- Minimum instances:
- Ingress: Select All.
- Networking: Enable Use HTTP/2 end-to-end.
Container Settings
- Port:
3000 - Volumes:
- Add a volume of type Cloud Storage bucket using the bucket created in Step 1.
- Mount the volume at path:
/turbo-cache
- Environment Variables:
| Variable | Value |
|---|---|
|
STORAGE_PROVIDER|local| |STORAGE_PATH|/turbo-cache| |STORAGE_PATH_USE_TMP_FOLDER|false| |TURBO_TOKEN| your_secret_key (a strong, random secret) | |HTTP2|true|
Step 3: Configure Turborepo
Copy the Cloud Run service URL (ending in
.run.app). Use this URL and yourTURBO_TOKENto configure your Turborepo project as described in the Enable custom remote caching guide.Configure Local Storage
mainWhen
STORAGE_PROVIDERis set tolocal, the server uses a folder on the filesystem.STORAGE_PATH: The folder name/path under/tmp.STORAGE_PATH_USE_TMP_FOLDER: Iftrue(default), the system's/tmpfolder is used as a prefix toSTORAGE_PATH.
Deploy on Vercel
mainThe server can be deployed as a Vercel Serverless Function using the Vercel deploy button.
Note: Local storage is not supported when using this deployment method.
Configure Static Token Authentication
mainTo usestaticauthentication (the default), set theAUTH_MODEtostaticand provide one or more secret tokens using theTURBO_TOKENvariable. Multiple tokens can be specified as a comma-delimited string.Configure Google Cloud Storage (GCS)
mainTo use Google Cloud Storage, set
STORAGE_PROVIDER=google-cloud-storageand provide a bucket name viaSTORAGE_PATH. You must grant theStorage Object Adminrole to your service account for the target bucket.Option 1: Using static Service Account credentials
Use this method by providing the details from your service account JSON key file directly in your environment variables.
Option 2: Using Application Default Credentials (ADC)
Leave the
GCS_*environment variables empty to allow the SDK to discover credentials automatically (e.g., via IAM roles or local ADC setup).# Option 1: Static Credentials STORAGE_PROVIDER=google-cloud-storage STORAGE_PATH=<name-of-the-bucket> GCS_PROJECT_ID=<project_id> GCS_CLIENT_EMAIL=<client_email> GCS_PRIVATE_KEY=<private_key> # Option 2: Application Default Credentials (ADC) STORAGE_PROVIDER=google-cloud-storage STORAGE_PATH=<name-of-the-bucket> GCS_PROJECT_ID= GCS_CLIENT_EMAIL= GCS_PRIVATE_KEY=Access TRRC Documentation
mainDetailed documentation for TRRC is hosted externally. Key topics include:
- Supported Storage Providers: Information on which backends can be used to store cache artifacts.
- Environment Variables: A complete list of configuration keys required for the server.
- Deployment Instructions: Guides for various deployment environments.
- Custom Remote Caching: How to enable and configure custom remote caching within your Turborepo monorepo.