Serverless Turborepo remote caching using API Gateway and S3.
This project is a serverless implementation of the Turborepo custom remote cache server.
It makes use of the preflight Turborepo feature to return signed S3 URLs to the client to upload/download artifacts directly from S3.
Build and Deployment is managed by the Serverless Framework.
-
Clone this repo
git clone git@github.com:gpdenny/turborepo-s3-cache.git
-
Install dependencies
yarn install
-
Copy example environment variables
You can do this for each environment you might wish to deploy to, for example, dev.
cp .env.example .env.dev
-
Modify environment variables to your requirements
SERVICE_NAME
- Serverless service name, used to prefix all AWS resourcesREGION
- The AWS Region to deploy the service toTEAMS_TABLE_NAME
- Name for the DynamoDB teams table see belowCACHE_BUCKET_NAME
- Name for the artifacts S3 bucketCACHE_EXPIRATION_DAYS
- Number of days cache artifacts are kept in S3 before being deleted
-
Run Serverless deploy
Include the stage flag, with the environment you wish to deploy.
yarn serverless deploy --stage dev
-
Populate the Teams DynamoDB table
aws dynamodb put-item \ --table-name `TEAMS_TABLE_NAME` \ --item \ '{"name": {"S": "myteam"}, "tokens": {"L": [{"S": "token_1"}, {"S": "token_2"}]}}'
-
Add remote cache to your Turborepo config
.turbo/config.json
{ "teamId": "team_myteam", "apiUrl": "https://fxbu8kd8i.execute-api.eu-central-1.amazonaws.com/dev/" }
package.json
[...] "lint": "turn run lint --token'\"token1\"" [...]
Inspiration, code snippets, etc.