bagsy/DEPLOYMENT_AUTOMATION.md

570 lines
12 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ShopList - Complete Deployment Automation & Infrastructure
## 🎯 What Was Delivered
You now have a **complete, production-ready deployment system** with:
- ✅ **SST Infrastructure as Code** - AWS deployment automated
- ✅ **Interactive Deployment Wizard** - One command to deploy backend
- ✅ **Automated Build Scripts** - iOS and Android building simplified
- ✅ **Comprehensive Checklists** - Step-by-step deployment guides
- ✅ **Quick Start Guide** - Get deployed in 4 steps
---
## 📦 New Files Created
### Infrastructure & Deployment
```
sst.config.ts ← SST infrastructure definition
scripts/deploy.ts ← Backend deployment wizard
scripts/build-ios.ts ← iOS build automation
scripts/build-android.ts ← Android build automation
```
### Documentation
```
QUICK_START.md ← 4-step deployment
DEPLOYMENT_CHECKLIST.md ← Complete step-by-step guide
```
### Generated (by wizard)
```
.deployment/
├── config.json ← Your deployment config
├── outputs.txt ← AWS URLs & endpoints
├── CHECKLIST.md ← Interactive checklist
├── secrets.json ← Secrets (keep safe!)
└── builds.log ← Build history
apps/api/.env.production ← Backend secrets
apps/mobile/.env.production ← Mobile config
```
---
## 🚀 How to Use - The Simple Way
### Deploy Everything with One Command
```bash
cd /Users/barnabasbodily/shop
bun run deploy
```
The wizard will:
1. ✅ Check you have AWS configured
2. ✅ Ask for deployment preferences
3. ✅ Generate environment files
4. ✅ Deploy to AWS automatically
5. ✅ Give you the API URL
6. ✅ Show next steps
**That's it! Backend is live.**
### Build & Deploy iOS
```bash
bun run build:ios
```
This will:
- Increment version number
- Build with EAS
- Submit to TestFlight
- Show you how to invite family
### Build & Deploy Android
```bash
bun run build:android
```
This will:
- Increment version number
- Build APK
- Generate download link
- Show you how to share with family
---
## 🏗️ Infrastructure - What Gets Created
### AWS Architecture (SST Managed)
```
┌────────────────────────────────────────────┐
│ ShopList Infrastructure │
├────────────────────────────────────────────┤
│ │
│ VPC (10.0.0.0/16) │
│ ├─ Lambda (Next.js API) │
│ ├─ PostgreSQL (RDS) │
│ ├─ Redis (Elasticache) │
│ └─ NAT Gateway │
│ │
│ API Gateway (REST + WebSocket) │
│ CloudWatch (Logs + Monitoring) │
│ S3 (Uploads - for future) │
│ Cognito (Optional auth) │
│ │
└────────────────────────────────────────────┘
```
### Cost Estimate (Monthly)
| Service | Cost |
| ---------------- | ------------ |
| Lambda | $1-5 |
| RDS (PostgreSQL) | $15-30 |
| Redis | $15-25 |
| NAT Gateway | $32 |
| Data Transfer | $0-10 |
| **TOTAL** | **~$63-102** |
_Family-sized usage, us-east-1 region_
### Deployment Time
- First deploy: 15-20 minutes
- Updates: 5-10 minutes
---
## 📱 Frontend Distribution
### iOS (TestFlight - Recommended)
```bash
bun run build:ios
# What happens:
1. Builds for TestFlight
2. Increments version automatically
3. Uploads to Apple
4. You submit for review (24-48 hours)
5. Family gets email invite
6. They tap → Install
7. Future builds auto-update
```
**Advantages:**
- No developer account needed ($99/year)
- Automatic updates
- Easy for family
- Built-in feedback system
### Android (Direct APK Sideload)
```bash
bun run build:android
# What happens:
1. Builds APK file
2. Increments version automatically
3. Generates download link
4. You share link with family
5. They download & install
6. Updates require new APK
```
**Advantages:**
- Instant deployment
- No review process
- Full control
---
## 📋 The Complete Deployment Flow
### Step 1: Prepare
```bash
# Create AWS account: https://aws.amazon.com
# Configure AWS: aws configure
# Git initialized: git init
```
### Step 2: Deploy Backend
```bash
bun run deploy
# Follow wizard prompts
# ✅ Backend live in 15-20 min
```
### Step 3: Deploy iOS
```bash
bun run build:ios
# ✅ Ready for TestFlight in 5 min
# Invite family via App Store Connect
```
### Step 4: Deploy Android
```bash
bun run build:android
# ✅ APK ready in 5 min
# Share download link with family
```
### Step 5: Test & Launch
```bash
# Test on 2+ devices
# Verify real-time sync works
# Send launch email to family
# 🎉 Done!
```
---
## 🔧 Scripts Overview
### `bun run deploy`
**Interactive deployment wizard**
- Checks prerequisites
- Prompts for configuration
- Creates environment files
- Deploys to AWS
- Saves outputs to `.deployment/`
### `bun run build:ios`
**iOS TestFlight build**
- Auto-increments version
- Builds for TestFlight
- Uploads to Apple
- Guides through submission
### `bun run build:ios:dev`
**iOS development build**
- For testing on simulator
- Faster build time
- Not for production
### `bun run build:android`
**Android APK build**
- Auto-increments version
- Generates APK file
- Creates sideload link
- Guides sharing process
### `bun run build:android:play`
**Android Play Store build**
- For Play Store submission
- Creates signed AAB file
- Generates Play Store packaging
---
## 📊 Configuration Files
### `sst.config.ts`
Defines your AWS infrastructure:
```typescript
- VPC configuration
- Database setup
- Redis cache
- Lambda function
- Environment variables
- Logging & monitoring
```
### `.deployment/config.json` (After Wizard)
Your saved deployment configuration:
```json
{
"environment": "production",
"region": "us-east-1",
"domain": "api.shoplist.com",
"redisCacheEnabled": true,
"databaseName": "shoplist"
}
```
### Environment Files (Generated)
**`apps/api/.env.production`**
- Database connection
- Auth secrets
- API keys
- Node environment
**`apps/mobile/.env.production`**
- API URL
- App version
- Environment
---
## 🎯 Key Features
### Automated
```bash
✅ One command deployment
✅ Version auto-increment
✅ Build artifact generation
✅ Deployment logging
```
### Guided
```bash
✅ Interactive prompts
✅ Clear error messages
✅ Next step instructions
✅ Troubleshooting help
```
### Safe
```bash
✅ Secrets not committed to git
✅ Backups configured
✅ Environment isolation
✅ CloudWatch monitoring
```
### Scalable
```bash
✅ Infrastructure as code
✅ Easy environment switching
✅ Auto-scaling Lambda
✅ Database read replicas (optional)
```
---
## 🚨 Important Notes
### Before First Deploy
```bash
# ✅ Required
- AWS account with credentials
- bun/Node.js installed
- Docker installed
- Git repository initialized
# ℹ️ Optional but recommended
- Custom domain registered
- OpenRouter API key (for AI)
```
### Security
```bash
# Keep safe!
- .deployment/secrets.json
- .env.production files
- AWS credentials (~/.aws/credentials)
# Share safely
- API URLs (public)
- TestFlight links (public)
- APK download links (public)
# Never share
- Database passwords
- API keys
- Auth secrets
```
### Monitoring
```bash
# After deployment, regularly check:
bunx sst logs --stage prod # View logs
aws cloudwatch get-metric-statistics # Check metrics
aws rds describe-db-instances # Database status
```
---
## 📚 Documentation Map
### Quick Reference
- `QUICK_START.md` - 4-step deployment
- `README.md` - Project overview
- `.deployment/CHECKLIST.md` - Full checklist (generated)
### Detailed Guides
- `DEPLOYMENT_CHECKLIST.md` - Complete step-by-step
- `DEPLOYMENT_GUIDE.md` - Architecture overview
- `docs/iOS_SIDELOADING_GUIDE.md` - iOS installation
- `docs/WEBSOCKET_SYNC.md` - Real-time sync
### Technical
- `AGENTS.md` - Full specification
- `sst.config.ts` - Infrastructure code
- `scripts/deploy.ts` - Wizard source
---
## 🔍 What Happens Under the Hood
### When You Run `bun run deploy`
```
1. Check prerequisites
├─ AWS CLI installed?
├─ Docker installed?
├─ AWS credentials configured?
└─ All green? Continue
2. Prompt for configuration
├─ Environment (dev/staging/prod)
├─ AWS region
├─ Domain name
├─ Database name
├─ Redis enabled?
├─ API key secrets
└─ Save to config.json
3. Create environment files
├─ apps/api/.env.production
├─ apps/mobile/.env.production
└─ .deployment/secrets.json
4. Deploy to AWS
├─ bunx sst deploy --stage prod
├─ Creates VPC
├─ Launches database
├─ Deploys Lambda
├─ Sets up API Gateway
├─ Configures WebSocket
└─ Saves outputs
5. Save outputs
├─ .deployment/outputs.txt
├─ .deployment/config.json
└─ .deployment/CHECKLIST.md
6. Show next steps
├─ Your API URL
├─ iOS build instructions
├─ Android build instructions
└─ Testing commands
```
---
## ✅ Pre-Deployment Checklist
- [ ] AWS account created
- [ ] AWS credentials configured (`aws configure`)
- [ ] bun installed (`bun --version`)
- [ ] Docker installed (`docker --version`)
- [ ] Git repo initialized (`git init && git add . && git commit`)
- [ ] All code committed (no uncommitted changes)
- [ ] Environment variables set up
- [ ] (Optional) Custom domain registered
- [ ] (Optional) OpenRouter API key obtained
---
## 🎉 After Deployment
1. **Check backend is working**
```bash
curl https://your-api-url/api/health
```
2. **Monitor logs**
```bash
bunx sst logs --stage prod
```
3. **Deploy iOS**
```bash
bun run build:ios
```
4. **Deploy Android**
```bash
bun run build:android
```
5. **Send to family**
- iOS: TestFlight link
- Android: APK link
6. **Celebrate!** 🎊
---
## 🆘 Common Issues & Fixes
| Issue | Cause | Fix |
| --------------------------- | ---------------------------- | ---------------------- |
| "AWS credentials not found" | Not configured | `aws configure` |
| "sst command not found" | Not installed | `npm install -g sst` |
| "Permission denied" | Insufficient IAM permissions | Add more policies |
| "Deployment timeout" | Slow network | Retry with `--verbose` |
| "Build failed on iOS" | Bad code | Check `bun typecheck` |
---
## 📞 Support
### If Something Goes Wrong
1. Check `DEPLOYMENT_CHECKLIST.md` troubleshooting section
2. View logs: `bunx sst logs --stage prod`
3. Check AWS Console for error messages
4. Read relevant docs (iOS/WebSocket/etc.)
### Resources
- AWS: https://console.aws.amazon.com
- SST Docs: https://docs.sst.dev
- Expo Docs: https://docs.expo.dev
- Better Auth: https://www.better-auth.com
---
## 🚀 You're Ready!
Everything is set up. Just run:
```bash
bun run deploy
```
And follow the wizard. Your backend will be live in 15-20 minutes, and your family can start using it in 30-45 minutes total.
**Good luck! 🎉**