Skip to content

Commit 3faeb35

Browse files
committed
strip back to simple test script for a single redirect
1 parent c91f490 commit 3faeb35

File tree

5 files changed

+74
-274
lines changed

5 files changed

+74
-274
lines changed

.circleci/config.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,19 +207,13 @@ jobs:
207207
echo "[INFO] Deploying production site..."
208208
aws s3 sync "$BUILD_DIRECTORY" "s3://$AWS_S3_BUCKET/"
209209
- run:
210-
name: Install Python Dependencies for Redirects
211-
command: |
212-
set -e
213-
echo "[INFO] Installing PyYAML for redirect processing..."
214-
sudo pip3 install PyYAML
215-
- run:
216-
name: Deploy Redirects to S3
210+
name: Deploy Single Test Redirect to S3
217211
command: |
218212
AWS_S3_BUCKET=<< parameters.bucket_name >>
219213
220214
set -e
221-
echo "[INFO] Deploying redirects with batch processing..."
222-
bash scripts/deploy-redirects-batch.sh "$AWS_S3_BUCKET" "scripts/test-single-redirect.yml"
215+
echo "[INFO] Deploying single test redirect..."
216+
bash scripts/test-single-redirect.sh "$AWS_S3_BUCKET"
223217
- notify_error:
224218
message: "Production deployment job failed for branch ${CIRCLE_BRANCH}"
225219

scripts/README-redirects.md

Lines changed: 35 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,39 @@
1-
# S3 Redirects Deployment System
1+
# S3 Redirects Test
22

3-
This documentation explains how to deploy URL redirects for the CircleCI documentation site using AWS S3's website redirect functionality.
3+
Simple test setup to validate AWS S3 website redirect functionality for the CircleCI documentation site.
44

55
## Overview
66

7-
The redirect system uses AWS S3's built-in website redirect feature by creating empty objects with redirect metadata. When a user visits an old URL, S3 automatically redirects them to the new URL with a 301 (permanent redirect) status.
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.
88

99
## Files
1010

11-
- `scripts/redirects_v2.yml` - YAML file containing all redirect mappings
12-
- `scripts/deploy-redirects-batch.sh` - Optimized batch deployment script
11+
- `scripts/test-single-redirect.sh` - Simple test script with hardcoded redirect
12+
- `scripts/redirects_v2.yml` - Full redirect mappings (for future use)
1313

1414
## How It Works
1515

16-
1. **Redirect File Format**: The `redirects_v2.yml` file contains redirect mappings:
17-
```yaml
18-
- old: /about-circleci/
19-
new: /guides/about-circleci/about-circleci/index.html
16+
1. **Test Redirect**: Hardcoded in the script:
17+
```
18+
/about-circleci/ -> /guides/about-circleci/about-circleci/index.html
2019
```
2120

2221
2. **Deployment Process**:
23-
- Parse the YAML file
24-
- For each redirect, create an S3 object at the old path
25-
- Set the `x-amz-website-redirect-location` metadata to the new path
22+
- Create S3 object at `about-circleci/index.html`
23+
- Set `x-amz-website-redirect-location` metadata to new path
2624
- S3 automatically handles the redirect
2725

28-
3. **URL Mapping**:
29-
- Old paths like `/about-circleci/` become S3 objects at `about-circleci/index.html`
30-
- When accessed, S3 returns a 301 redirect to the new location
31-
3226
## Usage
3327

34-
### Deploy Redirects
28+
### Test Single Redirect
3529

36-
The redirect deployment is integrated into the CircleCI pipeline and runs automatically after the main site deployment.
37-
38-
Manual deployment:
3930
```bash
40-
bash scripts/deploy-redirects-batch.sh "bucket-name" "scripts/redirects_v2.yml"
31+
bash scripts/test-single-redirect.sh "bucket-name"
4132
```
4233

34+
### Manual Testing
4335

44-
45-
## Performance Considerations
46-
47-
### Batch Processing
48-
The `deploy-redirects-batch.sh` script is optimized for handling redirects efficiently:
49-
- Processes redirects in batches of 50
50-
- Uses concurrent uploads (10 parallel requests)
51-
- Includes error handling and retry logic
52-
- Handles hundreds of redirects quickly
53-
54-
### Rate Limiting
55-
- The deployment script includes appropriate rate limiting
56-
- Batch script uses thread pools to manage concurrency
57-
58-
## CircleCI Integration
59-
60-
The redirect deployment is integrated into the `deploy-production` job:
61-
62-
1. **Install Dependencies**: Installs PyYAML for YAML parsing
63-
2. **Deploy Main Site**: Syncs the Antora build to S3
64-
3. **Deploy Redirects**: Creates redirect objects using the batch script
65-
66-
## Adding New Redirects
67-
68-
1. Edit `scripts/redirects_v2.yml`
69-
2. Add new redirect mapping:
70-
```yaml
71-
- old: /old-path/
72-
new: /new-path/index.html
73-
```
74-
3. Commit and push - redirects will be deployed automatically
75-
76-
## Redirect Format Guidelines
77-
78-
- **Old paths**: Should start with `/` and can end with or without `/`
79-
- **New paths**: Should be the full path to the new location
80-
- **Index files**: Old paths without file extensions automatically get `index.html` appended
81-
- **Trailing slashes**: Old paths are normalized (trailing slashes removed)
82-
83-
## Troubleshooting
84-
85-
### Common Issues
86-
87-
1. **Permission Errors**: Ensure AWS credentials have S3 write permissions
88-
2. **YAML Parse Errors**: Validate YAML syntax in redirects file
89-
3. **S3 Bucket Errors**: Verify bucket name and region settings
90-
91-
### Checking Redirect Status
92-
93-
Use curl to test individual redirects:
36+
Test the deployed redirect:
9437
```bash
9538
curl -I "https://circleci.com/docs/about-circleci/"
9639
```
@@ -101,19 +44,30 @@ HTTP/1.1 301 Moved Permanently
10144
Location: /guides/about-circleci/about-circleci/index.html
10245
```
10346

104-
### Debugging
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
10553

106-
1. Check CircleCI logs for deployment errors
107-
2. Test redirects manually with curl or browser
108-
3. Manually inspect S3 objects and their metadata
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+
```
10965

110-
## Best Practices
66+
## Next Steps
11167

112-
1. **Test Manually**: Use curl or browser to spot-check redirects when needed
113-
2. **Batch Operations**: Use the batch script for large numbers of redirects
114-
3. **Monitor Performance**: Keep an eye on deployment times and error rates
115-
4. **Clean URLs**: Ensure redirect paths are clean and consistent
116-
5. **Backup**: Keep backup of working redirect files before major changes
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
11771

11872
## AWS S3 Website Configuration
11973

scripts/deploy-redirects-batch.sh

Lines changed: 0 additions & 179 deletions
This file was deleted.

scripts/test-single-redirect.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Check required parameter
6+
if [ -z "$1" ]; then
7+
echo "Usage: $0 <bucket_name>"
8+
echo "Example: $0 circleci-docs-platform-assets/docs-preview"
9+
exit 1
10+
fi
11+
12+
BUCKET_NAME="$1"
13+
14+
# Hardcoded single redirect for testing
15+
OLD_PATH="/about-circleci/"
16+
NEW_PATH="/guides/about-circleci/about-circleci/index.html"
17+
18+
echo "[INFO] Testing single redirect deployment to bucket: s3://$BUCKET_NAME"
19+
echo "[INFO] Redirect: $OLD_PATH -> $NEW_PATH"
20+
21+
# Convert old path to S3 key
22+
S3_KEY="about-circleci/index.html"
23+
24+
echo "[INFO] Creating S3 object: $S3_KEY"
25+
echo "[INFO] With redirect to: $NEW_PATH"
26+
27+
# Create the redirect object
28+
aws s3api put-object \
29+
--bucket "$BUCKET_NAME" \
30+
--key "$S3_KEY" \
31+
--website-redirect-location "$NEW_PATH" \
32+
--content-type "text/html" \
33+
--content-length "0"
34+
35+
echo "[INFO] ✅ Redirect created successfully!"
36+
echo "[INFO] Test with: curl -I https://your-domain/about-circleci/"

0 commit comments

Comments
 (0)