Skip to content

Commit 08bb56f

Browse files
Merge pull request #233 from circleci/generate-redirects
Generate redirects and make a single test redirect in prod
2 parents 918d60a + b2dde0c commit 08bb56f

File tree

4 files changed

+1633
-0
lines changed

4 files changed

+1633
-0
lines changed

.circleci/config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ jobs:
206206
set -e
207207
echo "[INFO] Deploying production site..."
208208
aws s3 sync "$BUILD_DIRECTORY" "s3://$AWS_S3_BUCKET/"
209+
- run:
210+
name: Deploy Single Test Redirect to S3
211+
command: |
212+
AWS_S3_BUCKET=<< parameters.bucket_name >>
213+
214+
set -e
215+
echo "[INFO] Deploying single test redirect..."
216+
bash scripts/test-single-redirect.sh "$AWS_S3_BUCKET"
209217
- notify_error:
210218
message: "Production deployment job failed for branch ${CIRCLE_BRANCH}"
211219

scripts/README-redirects.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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

Comments
 (0)