|
| 1 | +# S3 Redirects Test |
| 2 | + |
| 3 | +Simple test setup to validate AWS S3 website redirect functionality for the CircleCI documentation site. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This tests S3's built-in website redirect feature by creating an empty object with redirect metadata. When a user visits the old URL, S3 automatically redirects them to the new URL with a 301 (permanent redirect) status. |
| 8 | + |
| 9 | +## Files |
| 10 | + |
| 11 | +- `scripts/test-single-redirect.sh` - Simple test script with hardcoded redirect |
| 12 | +- `scripts/redirects_v2.yml` - Full redirect mappings (for future use) |
| 13 | + |
| 14 | +## How It Works |
| 15 | + |
| 16 | +1. **Test Redirect**: Hardcoded in the script: |
| 17 | + ``` |
| 18 | + /about-circleci/ -> /guides/about-circleci/about-circleci/index.html |
| 19 | + ``` |
| 20 | + |
| 21 | +2. **Deployment Process**: |
| 22 | + - Create S3 object at `about-circleci/index.html` |
| 23 | + - Set `x-amz-website-redirect-location` metadata to new path |
| 24 | + - S3 automatically handles the redirect |
| 25 | + |
| 26 | +## Usage |
| 27 | + |
| 28 | +### Test Single Redirect |
| 29 | + |
| 30 | +```bash |
| 31 | +bash scripts/test-single-redirect.sh "bucket-name" |
| 32 | +``` |
| 33 | + |
| 34 | +### Manual Testing |
| 35 | + |
| 36 | +Test the deployed redirect: |
| 37 | +```bash |
| 38 | +curl -I "https://circleci.com/docs/about-circleci/" |
| 39 | +``` |
| 40 | + |
| 41 | +Should return: |
| 42 | +``` |
| 43 | +HTTP/1.1 301 Moved Permanently |
| 44 | +Location: /guides/about-circleci/about-circleci/index.html |
| 45 | +``` |
| 46 | + |
| 47 | +## CircleCI Integration |
| 48 | + |
| 49 | +The redirect test is integrated into the `deploy-production` job: |
| 50 | + |
| 51 | +1. **Deploy Main Site**: Syncs the Antora build to S3 |
| 52 | +2. **Deploy Test Redirect**: Creates single redirect object |
| 53 | + |
| 54 | +## AWS Command |
| 55 | + |
| 56 | +The core redirect is created with: |
| 57 | +```bash |
| 58 | +aws s3api put-object \ |
| 59 | + --bucket bucket-name \ |
| 60 | + --key about-circleci/index.html \ |
| 61 | + --website-redirect-location /guides/about-circleci/about-circleci/index.html \ |
| 62 | + --content-type text/html \ |
| 63 | + --content-length 0 |
| 64 | +``` |
| 65 | + |
| 66 | +## Next Steps |
| 67 | + |
| 68 | +1. Test this single redirect works |
| 69 | +2. If successful, implement batch processing for all 502 redirects in `redirects_v2.yml` |
| 70 | +3. The full redirect system can be found in previous git commits |
| 71 | + |
| 72 | +## AWS S3 Website Configuration |
| 73 | + |
| 74 | +Ensure your S3 bucket is configured for static website hosting: |
| 75 | +```bash |
| 76 | +aws s3 website s3://your-bucket-name --index-document index.html --error-document 404.html |
| 77 | +``` |
| 78 | + |
| 79 | +The redirect functionality requires website hosting to be enabled on the bucket. |
0 commit comments