Skip to content

Commit 62357da

Browse files
author
Jeffrey-Xu
committed
Initial commit: Multi-cloud Kubernetes Monopoly game
- Complete microservices architecture - Game engine, user service, matchmaking, notification services - Next.js frontend - Terraform infrastructure - GitHub Actions CI/CD - Fixed user service health check rate limiting
0 parents  commit 62357da

File tree

122 files changed

+37222
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+37222
-0
lines changed

.github/workflows/frontend-ci.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Frontend CI/CD
2+
3+
on:
4+
push:
5+
paths:
6+
- 'monopoly/frontend/**'
7+
8+
jobs:
9+
build-and-deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: '18'
19+
cache: 'npm'
20+
cache-dependency-path: monopoly/frontend/package-lock.json
21+
22+
- name: Install dependencies
23+
run: |
24+
cd monopoly/frontend
25+
npm ci
26+
27+
- name: Get ALB endpoint for API URL
28+
run: |
29+
echo "Getting ALB endpoint from AWS..."
30+
# This will be set from Terraform outputs in production
31+
echo "API_URL=https://monopoly-dev-api.example.com" >> $GITHUB_ENV
32+
echo "WS_URL=wss://monopoly-dev-api.example.com" >> $GITHUB_ENV
33+
34+
- name: Build static site
35+
run: |
36+
cd monopoly/frontend
37+
npm run export
38+
env:
39+
NEXT_PUBLIC_API_URL: ${{ env.API_URL }}
40+
NEXT_PUBLIC_WS_URL: ${{ env.WS_URL }}
41+
42+
- name: Configure AWS credentials
43+
uses: aws-actions/configure-aws-credentials@v2
44+
with:
45+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
46+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
47+
aws-region: us-west-2
48+
49+
- name: Get S3 bucket name from Terraform
50+
run: |
51+
cd infra-dev/infrastructure
52+
BUCKET_NAME=$(terraform output -raw s3_frontend_bucket)
53+
echo "S3_BUCKET=$BUCKET_NAME" >> $GITHUB_ENV
54+
55+
DISTRIBUTION_ID=$(terraform output -raw cloudfront_distribution_id)
56+
echo "CLOUDFRONT_ID=$DISTRIBUTION_ID" >> $GITHUB_ENV
57+
58+
- name: Deploy to S3
59+
run: |
60+
cd monopoly/frontend
61+
aws s3 sync out/ s3://${{ env.S3_BUCKET }} --delete --cache-control "public, max-age=31536000, immutable" --exclude "*.html"
62+
aws s3 sync out/ s3://${{ env.S3_BUCKET }} --delete --cache-control "public, max-age=0, must-revalidate" --include "*.html"
63+
64+
- name: Invalidate CloudFront
65+
run: |
66+
aws cloudfront create-invalidation --distribution-id ${{ env.CLOUDFRONT_ID }} --paths "/*"
67+
68+
- name: Output frontend URL
69+
run: |
70+
cd infra-dev/infrastructure
71+
FRONTEND_URL=$(terraform output -raw frontend_url)
72+
echo "🚀 Frontend deployed to: $FRONTEND_URL"
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
name: Game Engine CI/CD
2+
3+
on:
4+
push:
5+
paths:
6+
- 'monopoly/game-engine/**'
7+
8+
jobs:
9+
build-and-deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Set up Docker Buildx
16+
uses: docker/setup-buildx-action@v2
17+
18+
- name: Login to Docker Hub
19+
uses: docker/login-action@v2
20+
with:
21+
username: ${{ secrets.DOCKER_USERNAME }}
22+
password: ${{ secrets.DOCKER_PASSWORD }}
23+
24+
- name: Build and push Docker image
25+
uses: docker/build-push-action@v4
26+
with:
27+
context: ./monopoly/game-engine
28+
platforms: linux/amd64,linux/arm64
29+
push: true
30+
tags: jeffreyxu2025/monopoly-game-engine:${{ github.sha }}
31+
cache-from: type=gha
32+
cache-to: type=gha,mode=max
33+
34+
- name: Generate deployment manifest
35+
run: |
36+
mkdir -p infra-dev/manifests
37+
cat > infra-dev/manifests/game-engine.yaml << EOF
38+
apiVersion: apps/v1
39+
kind: Deployment
40+
metadata:
41+
name: game-engine
42+
namespace: monopoly-game
43+
labels:
44+
app: game-engine
45+
spec:
46+
replicas: 2
47+
selector:
48+
matchLabels:
49+
app: game-engine
50+
template:
51+
metadata:
52+
labels:
53+
app: game-engine
54+
spec:
55+
containers:
56+
- name: game-engine
57+
image: jeffreyxu2025/monopoly-game-engine:${{ github.sha }}
58+
ports:
59+
- containerPort: 3001
60+
env:
61+
- name: PORT
62+
value: "3001"
63+
- name: DB_HOST
64+
valueFrom:
65+
secretKeyRef:
66+
name: db-credentials
67+
key: host
68+
- name: DB_PORT
69+
valueFrom:
70+
secretKeyRef:
71+
name: db-credentials
72+
key: port
73+
- name: DB_NAME
74+
value: "monopoly_game"
75+
- name: DB_USER
76+
valueFrom:
77+
secretKeyRef:
78+
name: db-credentials
79+
key: username
80+
- name: DB_PASSWORD
81+
valueFrom:
82+
secretKeyRef:
83+
name: db-credentials
84+
key: password
85+
- name: REDIS_HOST
86+
value: "monopoly-dev-redis.f2xiko.ng.0001.usw2.cache.amazonaws.com"
87+
- name: REDIS_PORT
88+
value: "6379"
89+
- name: USER_SERVICE_URL
90+
value: "http://user-service:3002"
91+
- name: NOTIFICATION_SERVICE_URL
92+
value: "http://notification-service:3004"
93+
resources:
94+
requests:
95+
memory: "256Mi"
96+
cpu: "200m"
97+
limits:
98+
memory: "512Mi"
99+
cpu: "400m"
100+
livenessProbe:
101+
httpGet:
102+
path: /health
103+
port: 3001
104+
initialDelaySeconds: 30
105+
periodSeconds: 10
106+
readinessProbe:
107+
httpGet:
108+
path: /health
109+
port: 3001
110+
initialDelaySeconds: 5
111+
periodSeconds: 5
112+
---
113+
apiVersion: v1
114+
kind: Service
115+
metadata:
116+
name: game-engine-service
117+
namespace: monopoly-game
118+
spec:
119+
selector:
120+
app: game-engine
121+
ports:
122+
- port: 3001
123+
targetPort: 3001
124+
type: ClusterIP
125+
EOF
126+
127+
- name: Configure AWS credentials
128+
uses: aws-actions/configure-aws-credentials@v2
129+
with:
130+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
131+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
132+
aws-region: us-west-2
133+
134+
- name: Deploy Game Engine
135+
run: |
136+
aws eks update-kubeconfig --region us-west-2 --name monopoly-dev-jxre
137+
kubectl apply -f infra-dev/manifests/game-engine.yaml
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
name: Generate Architecture Documentation
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
paths:
7+
- 'docs/**'
8+
- 'diagrams/**'
9+
- '**.md'
10+
pull_request:
11+
branches: [ main ]
12+
13+
jobs:
14+
generate-diagrams:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Python
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: '3.9'
25+
26+
- name: Install dependencies
27+
run: |
28+
pip install diagrams
29+
sudo apt-get update
30+
sudo apt-get install -y graphviz
31+
32+
- name: Generate architecture diagrams
33+
run: |
34+
cd diagrams
35+
python system_architecture.py || echo "Diagrams.py generation skipped"
36+
37+
- name: Setup Node.js for Mermaid
38+
uses: actions/setup-node@v4
39+
with:
40+
node-version: '18'
41+
42+
- name: Install Mermaid CLI
43+
run: npm install -g @mermaid-js/mermaid-cli
44+
45+
- name: Generate Mermaid diagrams
46+
run: |
47+
# Extract and generate Mermaid diagrams from markdown files
48+
find . -name "*.md" -exec grep -l "```mermaid" {} \; | while read file; do
49+
echo "Processing $file for Mermaid diagrams"
50+
done
51+
52+
- name: Validate documentation links
53+
run: |
54+
# Check for broken internal links
55+
find . -name "*.md" -exec grep -l "\[.*\](.*\.md)" {} \; | while read file; do
56+
echo "Validating links in $file"
57+
done
58+
59+
- name: Generate documentation site
60+
run: |
61+
mkdir -p docs/generated
62+
echo "# Multi-Cloud Gaming Platform Documentation" > docs/generated/index.md
63+
echo "Generated on: $(date)" >> docs/generated/index.md
64+
echo "" >> docs/generated/index.md
65+
echo "## Architecture Diagrams" >> docs/generated/index.md
66+
67+
# List all generated diagrams
68+
if [ -d "diagrams/generated" ]; then
69+
ls diagrams/generated/*.png 2>/dev/null | while read diagram; do
70+
name=$(basename "$diagram" .png)
71+
echo "- [$name]($diagram)" >> docs/generated/index.md
72+
done
73+
fi
74+
75+
- name: Commit generated files
76+
run: |
77+
git config --local user.email "action@github.com"
78+
git config --local user.name "GitHub Action"
79+
git add docs/generated/ diagrams/generated/ || true
80+
git commit -m "Auto-update architecture documentation [skip ci]" || exit 0
81+
82+
- name: Push changes
83+
if: github.ref == 'refs/heads/main'
84+
uses: ad-m/github-push-action@master
85+
with:
86+
github_token: ${{ secrets.GITHUB_TOKEN }}
87+
branch: main
88+
89+
validate-architecture:
90+
runs-on: ubuntu-latest
91+
92+
steps:
93+
- name: Checkout repository
94+
uses: actions/checkout@v4
95+
96+
- name: Validate Terraform syntax
97+
run: |
98+
if [ -d "learn-terraform-multicloud-kubernetes" ]; then
99+
cd learn-terraform-multicloud-kubernetes
100+
find . -name "*.tf" -exec terraform fmt -check {} \; || echo "Terraform formatting issues found"
101+
fi
102+
103+
- name: Validate Kubernetes manifests
104+
run: |
105+
if [ -d "k8s" ]; then
106+
find k8s -name "*.yaml" -o -name "*.yml" | while read manifest; do
107+
echo "Validating $manifest"
108+
# Basic YAML syntax check
109+
python -c "import yaml; yaml.safe_load(open('$manifest'))" || echo "YAML syntax error in $manifest"
110+
done
111+
fi
112+
113+
- name: Check documentation completeness
114+
run: |
115+
# Ensure key documentation files exist
116+
required_docs=(
117+
"README.md"
118+
"ARCHITECTURE_BLUEPRINT.md"
119+
"PROJECT_PLAN.md"
120+
"SERVICE_MESH_STRATEGY.md"
121+
)
122+
123+
for doc in "${required_docs[@]}"; do
124+
if [ ! -f "$doc" ]; then
125+
echo "❌ Missing required documentation: $doc"
126+
exit 1
127+
else
128+
echo "✅ Found: $doc"
129+
fi
130+
done
131+
132+
- name: Generate architecture summary
133+
run: |
134+
echo "# Architecture Validation Report" > validation-report.md
135+
echo "Generated: $(date)" >> validation-report.md
136+
echo "" >> validation-report.md
137+
138+
echo "## Documentation Status" >> validation-report.md
139+
find . -name "*.md" -type f | wc -l | xargs echo "- Total markdown files:" >> validation-report.md
140+
141+
echo "" >> validation-report.md
142+
echo "## Infrastructure Status" >> validation-report.md
143+
if [ -d "learn-terraform-multicloud-kubernetes" ]; then
144+
find learn-terraform-multicloud-kubernetes -name "*.tf" | wc -l | xargs echo "- Terraform files:" >> validation-report.md
145+
fi
146+
147+
echo "" >> validation-report.md
148+
echo "## Application Status" >> validation-report.md
149+
if [ -d "monopoly" ]; then
150+
echo "- Monopoly game directory: ✅" >> validation-report.md
151+
else
152+
echo "- Monopoly game directory: ❌" >> validation-report.md
153+
fi
154+
155+
if [ -d "cicd" ]; then
156+
echo "- CI/CD configuration: ✅" >> validation-report.md
157+
else
158+
echo "- CI/CD configuration: ❌" >> validation-report.md
159+
fi
160+
161+
- name: Upload validation report
162+
uses: actions/upload-artifact@v3
163+
with:
164+
name: architecture-validation-report
165+
path: validation-report.md

0 commit comments

Comments
 (0)