irgmedeiros / turborepo-remote-cache

open-source implementation of the Turborepo custom remote cache server.

Home Page:https://github.com/fox1t/turborepo-remote-cache

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Turborepo Remote Cache

GitHub package.json version Build Docker Pulls

This project is an open-source implementation of the Turborepo custom remote cache server. If Vercel's official cache server isn't a viable option, this server is an alternative for self-hosted deployments. It supports several storage providers and deploys environments. Moreover, the project provides "deploy to " buttons for one-click deployments whenever possible.

Index

Supported Storage Providers

  • Local filesystem
  • AWS S3
  • Azure Blob Storage (WIP)
  • Google Cloud Storage (WIP)
  • Google Drive Blobs (WIP)

ENV VARS

  • NODE_ENV: String. Optional. Possible values: development | production. Default value: production.
  • PORT: Number. Optional. Default value: 3000.
  • TURBO_TOKEN: String. Secret token used for the authentication. The value must be the same one provided for the token parameter of the build script. See Enable custom remote caching in a Turborepo monorepo for more info. This value should be private.
  • LOG_LEVEL: String. Optional. Default value: 'info'
  • STORAGE_PROVIDER: Optional. Possible values: local | s3. Default value: "local". Use this var to choose the storage provider.
  • STORAGE_PATH: String. Caching folder. If STORAGE_PROVIDER is set to s3, this will be the name of the bucket.
  • S3_ACCESS_KEY: String. Used only if STORAGE_PROVIDER=s3
  • S3_SECRET_KEY: String. Used only if STORAGE_PROVIDER=s3
  • S3_REGION: String. Used only if STORAGE_PROVIDER=s3
  • S3_ENDPOINT: String. Optional. Used only if STORAGE_PROVIDER=s3. NOTE: This var can be omitted if the other s3 vars are provided.

Deployment Environments

Enable custom remote caching in your Turborepo monorepo

To enable a custom remote caching server in your Turborepo monorepo, you must add a config file by hand. The turbo login command works only with the official Vercel server.

  1. create .turbo folder at the root of your monorepo
  2. create config.json file inside it, and add these properties:
    • teamId: it could be any string that starts with "team_". This property will be used as a cache storage folder for the current repository. Ex. team_myteam
    • apiUrl: address of a running turborepo-remote-cache server.

For example:

.turbo/config.json

{
  "teamId": "team_FcALQN9XEVbeJ1NjTQoS9Wup",
  "apiUrl": "http://localhost:3000"
}
  1. Modify your Turborepo top-level build script, adding the --token= parameter. Note: The token value must be the same used for your TURBO_TOKEN env var. See ENV_VARS section for more info.

For example:

package.json

//...
  "build": "turbo run build --token=\"yourToken\"",
  "dev": "turbo run dev --parallel",
  "lint": "turbo run lint",
  "format": "prettier --write \"**/*.{ts,tsx,md}\""
//...

Deploy on Vercel

The server can be easily deployed as Vercel Function using the deploy button.

Note: Local storage isn't supported for this deployment method.

Deploy with Vercel

Deploy on Docker

You can find the image on the dockerhub.

  1. create an .env file, containing all of the env vars you need. Check ENV_VARS for more info.
NODE_ENV=
PORT=
TURBO_TOKEN=
LOG_LEVEL=
STORAGE_PROVIDER=
STORAGE_PATH=
S3_ACCESS_KEY=
S3_SECRET_KEY=
S3_REGION=
S3_ENDPOINT=
  1. run the image using the .env file created on the step one.
docker run --env-file=.env -p 3000:3000 fox1t/turborepo-remote-cache

Deploy on DigitalOcean

The server can be easily deployed on DigitalOcean App Service.

Note: Local storage isn't supported for this deployment method.

Deploy to DO

Contribute to this project

  1. clone this repository

    git clone git@github.com:fox1t/turborepo-remote-cache.git

  2. cd turborepo-remote-cache

  3. npm i

  4. cp .env.example .env

  5. put your env vars to the env file. See ENV_VARS section for more details.

  6. npm run dev

About

open-source implementation of the Turborepo custom remote cache server.

https://github.com/fox1t/turborepo-remote-cache

License:MIT License


Languages

Language:TypeScript 83.8%Language:JavaScript 9.0%Language:Dockerfile 6.6%Language:Shell 0.5%