-
Notifications
You must be signed in to change notification settings - Fork 47
Add S3 backend storage and update docs #996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
AdiRishi
wants to merge
1
commit into
master
Choose a base branch
from
cursor/add-s3-backend-storage-and-update-docs-d72a
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+824
−10
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| --- | ||
| layout: doc | ||
| --- | ||
|
|
||
| # ☁️ Storing artifacts in Amazon S3 | ||
|
|
||
| [Amazon S3](https://aws.amazon.com/s3/) provides scalable, reliable object storage that can be used to store your build artifacts. With S3, you can leverage AWS's global infrastructure for storing and retrieving your build cache. | ||
|
|
||
| Follow these steps to store your build artifacts in Amazon S3: | ||
|
|
||
| ## 1. Create an S3 Bucket | ||
|
|
||
| An S3 bucket is a container for objects in Amazon S3. You can create a bucket via the [AWS Management Console](https://console.aws.amazon.com/) or using the [AWS CLI](https://aws.amazon.com/cli/). | ||
|
|
||
| ### Using the AWS CLI | ||
|
|
||
| ```sh | ||
| aws s3 mb s3://your-bucket-name --region your-region | ||
| ``` | ||
|
|
||
| ### Using the AWS Management Console | ||
|
|
||
| 1. Navigate to the [AWS S3 console](https://console.aws.amazon.com/s3/) | ||
| 2. Click the `Create bucket` button | ||
| 3. Enter a name for your bucket and select the region | ||
| 4. Configure bucket settings as needed | ||
| 5. Click `Create bucket` | ||
|
|
||
| ::: tip | ||
| Choose a region closest to where the bulk of your API requests will be coming from. For example, if you want to optimize for requests coming from GitHub Actions in the US, pick a US region. | ||
|
|
||
| You can find the list of available regions [here](https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region). | ||
| ::: | ||
|
|
||
| ## 2. Create IAM User and Access Keys | ||
|
|
||
| You'll need AWS access credentials to authenticate with S3. Follow these steps to create an IAM user with S3 permissions: | ||
|
|
||
| ### Using the AWS Management Console | ||
|
|
||
| 1. Navigate to the [IAM console](https://console.aws.amazon.com/iam/) | ||
| 2. Click `Users` in the left sidebar | ||
| 3. Click `Create user` | ||
| 4. Enter a username and select `Programmatic access` | ||
| 5. Click `Next: Permissions` | ||
| 6. Click `Attach existing policies directly` | ||
| 7. Search for and select `AmazonS3FullAccess` (or create a custom policy with minimal S3 permissions) | ||
| 8. Complete the user creation process | ||
| 9. Save the Access Key ID and Secret Access Key | ||
|
|
||
| ### Minimal S3 Policy | ||
|
|
||
| If you prefer to create a custom policy with minimal permissions, use this policy: | ||
|
|
||
| ```json | ||
| { | ||
| "Version": "2012-10-17", | ||
| "Statement": [ | ||
| { | ||
| "Effect": "Allow", | ||
| "Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject", "s3:ListBucket"], | ||
| "Resource": ["arn:aws:s3:::your-bucket-name", "arn:aws:s3:::your-bucket-name/*"] | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| ## 3. Update Your Configuration | ||
|
|
||
| Update your `wrangler.jsonc` file to include the S3 configuration. Since S3 credentials are sensitive, they should be set as secrets: | ||
|
|
||
| ```jsonc{5-15} | ||
| { | ||
| "name": "turborepo-remote-cache", | ||
| // Other settings... | ||
|
|
||
| "vars": { | ||
| "ENVIRONMENT": "production", | ||
| "BUCKET_OBJECT_EXPIRATION_HOURS": 720, | ||
| "S3_BUCKET_NAME": "your-bucket-name", | ||
| "S3_REGION": "us-east-1" | ||
| }, | ||
|
|
||
| // Comment out R2 and KV configurations when using S3 | ||
| // "r2_buckets": [...], | ||
| // "kv_namespaces": [...] | ||
| } | ||
| ``` | ||
|
|
||
| Set the sensitive S3 credentials as secrets: | ||
|
|
||
| ```sh | ||
| echo "your-access-key-id" | wrangler secret put S3_ACCESS_KEY_ID | ||
| echo "your-secret-access-key" | wrangler secret put S3_SECRET_ACCESS_KEY | ||
| ``` | ||
|
|
||
| ## 4. Deploy Your Worker | ||
|
|
||
| Once you've updated your Worker script and `wrangler.jsonc` file, deploy your Worker using the Wrangler CLI or your GitHub actions workflow. | ||
|
|
||
| And that's it! Your build artifacts will now be stored in Amazon S3. | ||
|
|
||
| ## Configuration Options | ||
|
|
||
| | Variable | Required | Description | Default | | ||
| | ---------------------- | -------- | ---------------------------- | ----------- | | ||
| | `S3_ACCESS_KEY_ID` | Yes | AWS access key ID | - | | ||
| | `S3_SECRET_ACCESS_KEY` | Yes | AWS secret access key | - | | ||
| | `S3_BUCKET_NAME` | Yes | S3 bucket name | - | | ||
| | `S3_REGION` | No | AWS region for the S3 bucket | `us-east-1` | | ||
|
|
||
| ::: info | ||
| When S3 storage is configured, it takes priority over R2 and KV storage. The storage priority order is: S3 > KV > R2. | ||
| ::: | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Configuration Examples | ||
|
|
||
| This directory contains example configuration files for different storage backends. | ||
|
|
||
| ## Available Examples | ||
|
|
||
| - **`s3-config.jsonc`** - Configuration for Amazon S3 storage | ||
| - **`r2-config.jsonc`** - Configuration for Cloudflare R2 storage (if you have one) | ||
| - **`kv-config.jsonc`** - Configuration for Cloudflare KV storage (if you have one) | ||
|
|
||
| ## Usage | ||
|
|
||
| 1. Copy the appropriate configuration file to your project root | ||
| 2. Rename it to `wrangler.jsonc` | ||
| 3. Update the values to match your setup | ||
| 4. Set the required secrets using `wrangler secret put` | ||
|
|
||
| ## Setting Secrets | ||
|
|
||
| For S3 storage, you'll need to set these secrets: | ||
|
|
||
| ```bash | ||
| echo "your-access-key-id" | wrangler secret put S3_ACCESS_KEY_ID | ||
| echo "your-secret-access-key" | wrangler secret put S3_SECRET_ACCESS_KEY | ||
| ``` | ||
|
|
||
| For all storage types, you'll also need: | ||
|
|
||
| ```bash | ||
| echo "your-turbo-token" | wrangler secret put TURBO_TOKEN | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "$schema": "node_modules/wrangler/config-schema.json", | ||
| "name": "turborepo-remote-cache", | ||
| "main": "src/index.ts", | ||
| "compatibility_date": "2025-02-24", | ||
| "upload_source_maps": true, | ||
| "observability": { | ||
| "enabled": true, | ||
| }, | ||
| "vars": { | ||
| "ENVIRONMENT": "production", | ||
| "BUCKET_OBJECT_EXPIRATION_HOURS": 720, | ||
| "S3_BUCKET_NAME": "your-turborepo-cache-bucket", | ||
| "S3_REGION": "us-east-1", | ||
| }, | ||
| "triggers": { | ||
| "crons": ["0 3 * * *"], | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Avoid recommending AmazonS3FullAccess; prefer a minimal, bucket-scoped policy.
Granting AmazonS3FullAccess is overly permissive. Recommend attaching the minimal policy (shown below) and explicitly discourage FullAccess in production.
Apply this diff to Step 7:
📝 Committable suggestion
🤖 Prompt for AI Agents