Skip to content

Commit e41d24a

Browse files
Complete dev deployment system with SSL and security fixes
- Add comprehensive development deployment infrastructure - Fix ERB template to use Origin Access Control instead of public S3 bucket policy - Add wildcard certificate support for dev environments - Create deployment and cleanup scripts with proper error handling - Update .gitignore to exclude auto-generated files - Add Ruby version consistency across components - Include complete documentation and usage instructions This provides a secure, automated development deployment workflow.
1 parent 0ad7f3d commit e41d24a

File tree

12 files changed

+4845
-8
lines changed

12 files changed

+4845
-8
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
# Ignore Gradle build output directory
1515
build
1616

17-
# Ignore the generated template.yml file
17+
# Ignore the generated template.yml files
1818
template.yml
19+
app-template.yml

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.7.8
1+
3.0.5

api-gateway-routes/.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.7.8

beta-template.yml.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ JAVALAB_APP_TYPES = %w(
5757
-%>
5858
Globals:
5959
Function:
60-
Runtime: ruby2.7
60+
Runtime: ruby3.2
6161
Timeout: 30
6262
MemorySize: 256
6363
Tracing: Active

cicd/3-app/javabuilder/config/dev.config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"_comment": "This file is used by AWS CodePipeline for automated dev deployments. Referenced in cicd/2-cicd/cicd.template.yml line 314 as TemplateConfiguration. Local dev scripts use hardcoded parameters instead.",
23
"Parameters": {
34
"BaseDomainName": "code.org",
45
"BaseDomainNameHostedZonedID": "Z2LCOI49SCXUGU",

cicd/3-app/javabuilder/template.yml.erb

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ Parameters:
5656
Type: Number
5757
Description: The threshold for the high concurrent executions alarm.
5858
Default: 400
59+
WildcardCertificateArn:
60+
Type: String
61+
Description: ARN of existing wildcard certificate for dev environments (optional)
62+
Default: ""
5963
<%
6064
JAVALAB_APP_TYPES = %w(
6165
Theater
@@ -65,12 +69,14 @@ JAVALAB_APP_TYPES = %w(
6569
-%>
6670
Globals:
6771
Function:
68-
Runtime: ruby2.7
72+
Runtime: ruby3.2
6973
Timeout: 30
7074
MemorySize: 256
7175
Tracing: Active
7276
Conditions:
7377
IsDevCondition: !Equals [!Ref BaseDomainName, "dev-code.org"]
78+
UseWildcardCertificate: !Not [!Equals [!Ref WildcardCertificateArn, ""]]
79+
CreateNewCertificates: !Equals [!Ref WildcardCertificateArn, ""]
7480
SilenceAlertsCondition: !Or [Condition: IsDevCondition, !Equals [!Ref SilenceAlerts, "true"]]
7581
Resources:
7682
# Note: We can't update the name of a DomainName resource once it has been created because the
@@ -96,11 +102,12 @@ Resources:
96102
DomainName: !Sub "${SubdomainName}<%=config[:Suffix]%>.${BaseDomainName}"
97103
DomainNameConfigurations:
98104
- EndpointType: REGIONAL
99-
CertificateArn: !Ref <%=config[:Prefix]%>Certificate
105+
CertificateArn: !If [UseWildcardCertificate, !Ref WildcardCertificateArn, !Ref <%=config[:Prefix]%>Certificate]
100106
CertificateName: !Sub "${SubdomainName}<%=config[:Suffix]%>.${BaseDomainName}"
101107

102108
<%=config[:Prefix]%>Certificate:
103109
Type: AWS::CertificateManager::Certificate
110+
Condition: CreateNewCertificates
104111
Properties:
105112
DomainName: !Sub "${SubdomainName}<%=config[:Suffix]%>.${BaseDomainName}"
106113
ValidationMethod: DNS
@@ -489,6 +496,15 @@ Resources:
489496
Status: Enabled
490497
ExpirationInDays: 1
491498

499+
ContentOAC:
500+
Type: AWS::CloudFront::OriginAccessControl
501+
Properties:
502+
OriginAccessControlConfig:
503+
Name: !Sub "${SubdomainName}-content-oac"
504+
OriginAccessControlOriginType: s3
505+
SigningBehavior: always
506+
SigningProtocol: sigv4
507+
492508
ContentBucketPolicy:
493509
Type: AWS::S3::BucketPolicy
494510
Properties:
@@ -498,10 +514,15 @@ Resources:
498514
- Action: ['s3:GetObject']
499515
Effect: Allow
500516
Resource: !Sub "arn:aws:s3:::${ContentBucket}/*"
501-
Principal: '*'
517+
Principal:
518+
Service: cloudfront.amazonaws.com
519+
Condition:
520+
StringEquals:
521+
"AWS:SourceArn": !Sub "arn:aws:cloudfront::${AWS::AccountId}:distribution/${ContentCDN}"
502522

503523
ContentApiCertificate:
504524
Type: AWS::CertificateManager::Certificate
525+
Condition: CreateNewCertificates
505526
Properties:
506527
DomainName: !Sub "${SubdomainName}-content.${BaseDomainName}"
507528
ValidationMethod: DNS
@@ -526,7 +547,7 @@ Resources:
526547
Enabled: true
527548
Aliases: [!Sub "${SubdomainName}-content.${BaseDomainName}"]
528549
ViewerCertificate:
529-
AcmCertificateArn: !Ref ContentApiCertificate
550+
AcmCertificateArn: !If [UseWildcardCertificate, !Ref WildcardCertificateArn, !Ref ContentApiCertificate]
530551
MinimumProtocolVersion: TLSv1
531552
SslSupportMethod: sni-only
532553
CustomErrorResponses:
@@ -540,7 +561,7 @@ Resources:
540561
Origins:
541562
- Id: ContentBucket
542563
DomainName: !GetAtt ContentBucket.DomainName
543-
S3OriginConfig: {}
564+
OriginAccessControlId: !Ref ContentOAC
544565
DefaultCacheBehavior:
545566
TargetOriginId: ContentBucket
546567
AllowedMethods: [DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT]

dev-deployment/README.md

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# Javabuilder Dev Environment Deployment Guide
2+
3+
Comprehensive guide for deploying and managing the JavaBuilder AWS Lambda environment for development.
4+
5+
## 🎯 Quick Start
6+
7+
For a complete no-SSL deployment (recommended for dev):
8+
```bash
9+
./deploy-javabuilder-dev-no-ssl-fixed.sh
10+
```
11+
12+
For modular deployment:
13+
```bash
14+
./01-deploy-base-infrastructure.sh # Deploy IAM roles first
15+
./02-build-java-components.sh # Build Java artifacts
16+
./03-deploy-application.sh # Deploy application stack
17+
```
18+
19+
## 📋 Current Environment Status
20+
21+
- **AWS Account**: 165336972514
22+
- **Profile**: codeorg-dev
23+
- **Region**: us-east-1
24+
- **Stack Name**: javabuilder-dev
25+
- **Bucket**: javabuilder-dev-artifacts-*
26+
27+
### ✅ Working Components
28+
- ✅ AWS CLI configured with `codeorg-dev` profile
29+
- ✅ S3 bucket creation for artifacts
30+
- ✅ ERB template processing with SSL removal
31+
- ✅ CloudFormation template packaging and deployment
32+
- ✅ Java artifacts built and packaged correctly
33+
- ✅ Lambda functions deployed and active
34+
35+
### 🔧 Key Components
36+
- **javabuilder-authorizer**: Handles API Gateway authorization
37+
- **api-gateway-routes**: API Gateway interaction logic
38+
- **org-code-javabuilder**: Core Java logic built with Gradle
39+
- **WebSocket API**: Real-time communication for build sessions
40+
- **CloudFront**: Content delivery for build artifacts
41+
42+
## 🚀 Deployment Options
43+
44+
### Option 1: No-SSL Deployment (Recommended for Dev)
45+
**Best for development environments without Route53 permissions**
46+
```bash
47+
./deploy-javabuilder-dev-no-ssl-fixed.sh
48+
```
49+
- Removes SSL certificates and custom domains
50+
- Uses CloudFront default domain
51+
- Faster deployment, fewer permissions needed
52+
53+
### Option 2: Full SSL Deployment
54+
**For production-like environments with Route53 access**
55+
```bash
56+
./01-deploy-base-infrastructure.sh
57+
./02-build-java-components.sh
58+
./03-deploy-application.sh
59+
```
60+
61+
### Option 3: Clean Slate Deployment
62+
**If stack exists but needs complete refresh**
63+
```bash
64+
./cleanup-javabuilder-dev.sh # Remove existing stack
65+
./deploy-javabuilder-dev-no-ssl-fixed.sh # Deploy fresh
66+
```
67+
68+
## 🔧 Prerequisites
69+
70+
### Required Software
71+
- **AWS CLI**: Configure with `codeorg-dev` profile
72+
- **Ruby**: For ERB template processing
73+
- **Java/Gradle**: For building org-code-javabuilder components
74+
75+
### Required Permissions
76+
- CloudFormation stack management
77+
- S3 bucket creation and object management
78+
- Lambda function deployment
79+
- IAM role creation (for base infrastructure)
80+
- API Gateway management
81+
82+
### Pre-Deployment Check
83+
```bash
84+
./pre-deploy-check.sh # Verify all prerequisites
85+
```
86+
87+
## 📁 Required Artifacts
88+
89+
### Java Build Artifacts
90+
-`org-code-javabuilder/lib/build/distributions/lib.zip`
91+
-`org-code-javabuilder/font_config.zip`
92+
-`org-code-javabuilder/change_runtime_directory/` (directory)
93+
94+
### CloudFormation Templates
95+
- `../cicd/3-app/javabuilder/template.yml.erb` (source)
96+
- `process-template-no-ssl.rb` (SSL removal script)
97+
- Generated templates: `template-no-ssl.yml`, `packaged-*.yml`
98+
99+
## 🔍 Deployment Process Details
100+
101+
### 1. Template Processing
102+
- Processes ERB template with environment variables
103+
- Removes SSL resources for no-SSL deployment
104+
- Handles large template packaging via S3
105+
106+
### 2. Artifact Packaging
107+
- Creates S3 bucket for deployment artifacts
108+
- Packages Lambda code from local directories
109+
- Uploads packaged template to S3
110+
111+
### 3. CloudFormation Deployment
112+
- Uses `--template-url` for large templates
113+
- Includes `CAPABILITY_AUTO_EXPAND` for SAM transforms
114+
- Provides all required parameters via JSON file
115+
116+
### 4. Post-Deployment Verification
117+
- Validates stack creation status
118+
- Tests WebSocket API endpoint
119+
- Verifies CloudFront distribution
120+
- Confirms Lambda function deployment
121+
122+
## 🚨 Common Issues & Solutions
123+
124+
### Template Too Large
125+
**Error**: Template body exceeds 51200 characters
126+
**Solution**: Script automatically uploads to S3 and uses `--template-url`
127+
128+
### SSL Certificate Errors
129+
**Error**: Certificate validation or Route53 permissions
130+
**Solution**: Use no-SSL deployment script
131+
132+
### Missing IAM Roles
133+
**Error**: Stack exports not found
134+
**Solution**: Deploy base infrastructure first with `01-deploy-base-infrastructure.sh`
135+
136+
### Java Artifacts Missing
137+
**Error**: CodeUri points to non-existent files
138+
**Solution**: Run `02-build-java-components.sh` or ensure artifacts exist
139+
140+
### Stack in ROLLBACK_COMPLETE State
141+
**Error**: Cannot update stack in failed state
142+
**Solution**: Use `cleanup-javabuilder-dev.sh` to delete and recreate
143+
144+
## 🧪 Testing & Verification
145+
146+
### Health Check Script
147+
```bash
148+
./test-deployment-health.sh # Verify deployment status
149+
```
150+
151+
### Manual Verification
152+
```bash
153+
# Check stack status
154+
aws cloudformation describe-stacks --stack-name javabuilder-dev --profile codeorg-dev
155+
156+
# Test WebSocket endpoint
157+
aws apigatewayv2 get-apis --profile codeorg-dev
158+
159+
# Verify Lambda functions
160+
aws lambda list-functions --profile codeorg-dev | grep -i javabuilder
161+
```
162+
163+
## 🧹 Cleanup & Maintenance
164+
165+
### Clean Failed Deployments
166+
```bash
167+
./cleanup-failed-stack.sh # Remove failed stacks
168+
./cleanup-javabuilder-dev.sh # Remove specific dev stack
169+
```
170+
171+
### Artifact Management
172+
- S3 buckets are created with unique suffixes
173+
- Old artifacts remain in S3 (manual cleanup needed)
174+
- CloudFormation stacks are idempotent (safe to redeploy)
175+
176+
## 📖 File Reference
177+
178+
### Main Scripts
179+
- `deploy-javabuilder-dev-no-ssl-fixed.sh` - Complete no-SSL deployment
180+
- `01-deploy-base-infrastructure.sh` - IAM roles and base resources
181+
- `02-build-java-components.sh` - Build Java artifacts
182+
- `03-deploy-application.sh` - Deploy application stack
183+
184+
### Configuration Files
185+
- `dev-deployment-params.json` - CloudFormation parameters
186+
- `dev.config.json` - Environment configuration
187+
- `process-template-no-ssl.rb` - SSL removal script
188+
189+
### Generated Files
190+
- `template-no-ssl.yml` - Processed template without SSL
191+
- `packaged-*.yml` - CloudFormation packaged templates
192+
- `runtime.zip` - Lambda runtime artifacts
193+
194+
For issues or questions, consult AWS CloudFormation logs or reach out to the DevOps team.
195+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
# Cleanup JavaBuilder Dev Environment
4+
set -e
5+
6+
PROFILE="codeorg-dev"
7+
APP_STACK="javabuilder-dev"
8+
BASE_STACK="javabuilder-base-infrastructure"
9+
10+
echo "🗑️ Starting JavaBuilder Dev Environment Cleanup..."
11+
12+
echo "📋 Checking if application stack exists..."
13+
if aws cloudformation describe-stacks --stack-name "$APP_STACK" --profile "$PROFILE" >/dev/null 2>&1; then
14+
echo "🔄 Deleting application stack: $APP_STACK"
15+
aws cloudformation delete-stack --stack-name "$APP_STACK" --profile "$PROFILE"
16+
17+
echo "⏳ Waiting for application stack deletion to complete..."
18+
aws cloudformation wait stack-delete-complete --stack-name "$APP_STACK" --profile "$PROFILE"
19+
echo "✅ Application stack deleted successfully!"
20+
else
21+
echo "ℹ️ Application stack $APP_STACK not found"
22+
fi
23+
24+
echo "🧹 Checking for leftover S3 buckets..."
25+
echo "S3 buckets that may need manual cleanup:"
26+
aws s3 ls --profile "$PROFILE" | grep javabuilder || echo "No JavaBuilder S3 buckets found"
27+
28+
echo "✅ Cleanup complete!"
29+
echo "💡 To also remove base infrastructure, run:"
30+
echo " aws cloudformation delete-stack --stack-name $BASE_STACK --profile $PROFILE"

0 commit comments

Comments
 (0)