Deployment Guide
Deployment Guide
Section titled “Deployment Guide”This guide covers deploying the 8531 TeamSite to various environments, managing configurations, and understanding the deployment architecture.
🌐 Environment Architecture
Section titled “🌐 Environment Architecture”Environments
Section titled “Environments”- Production:
https://team.8531.ca- Main production site - Development:
https://dev.team.8531.ca- Staging and preview deployments - Local:
http://localhost:4321- Local development environment
Environment Detection
Section titled “Environment Detection”The application automatically detects its environment and configures:
- Site URLs: Production, development, or local URLs
- Auth Callbacks: Environment-specific OAuth redirect URLs
- CORS Policies: Proper cross-origin request handling
- Security Headers: Production-appropriate security measures
🚀 Vercel Deployment
Section titled “🚀 Vercel Deployment”The project is configured for Vercel deployment with zero-downtime deployment strategy.
Vercel Configuration
Section titled “Vercel Configuration”The vercel.json file includes:
- Serverless function configuration for API endpoints
- Security headers for all routes
- CORS configuration for API routes
- Environment variable settings
{ "buildCommand": "npm run build", "outputDirectory": "dist", "installCommand": "npm install", "devCommand": "npm run dev", "functions": { "src/pages/api/**/*.ts": { "runtime": "nodejs18.x" } }, "headers": [ { "source": "/(.*)", "headers": [ { "key": "X-Frame-Options", "value": "DENY" }, { "key": "X-Content-Type-Options", "value": "nosniff" } ] }, { "source": "/api/(.*)", "headers": [ { "key": "Access-Control-Allow-Origin", "value": "https://team.8531.ca" }, { "key": "Access-Control-Allow-Methods", "value": "GET, POST, PUT, DELETE, OPTIONS" } ] } ]}Setting Up Vercel
Section titled “Setting Up Vercel”-
Install Vercel CLI
Terminal window npm i -g vercel -
Login to Vercel
Terminal window vercel login -
Link Project
Terminal window vercel link -
Configure Environment Variables
Terminal window vercel env add -
Deploy
Terminal window vercel --prod
Automatic Deployment
Section titled “Automatic Deployment”The project supports automatic deployment:
- Main Branch: Deploys to production
- Pull Requests: Creates preview deployments
- Push to Main: Triggers production deployment
🔧 Environment Configuration
Section titled “🔧 Environment Configuration”Production Environment Variables
Section titled “Production Environment Variables”Configure these in Vercel dashboard or CLI:
Required Variables
Section titled “Required Variables”NODE_ENV=productionSITE_URL=https://team.8531.caAUTH_GATEWAY_URL=https://auth.8531.caJWT_SECRET=your-production-jwt-secretJWT_ISSUER=https://auth.8531.caJWT_AUDIENCE=8531-appsOptional Variables
Section titled “Optional Variables”# Google Drive IntegrationGOOGLE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nYour-private-key\n-----END PRIVATE KEY-----"
# LoggingLOG_LEVEL=warn
# Analytics (if used)ANALYTICS_ID=your-analytics-idDevelopment Environment
Section titled “Development Environment”For dev.team.8531.ca:
NODE_ENV=developmentSITE_URL=https://dev.team.8531.caAUTH_GATEWAY_URL=https://auth.8531.caJWT_SECRET=your-development-jwt-secretLocal Development
Section titled “Local Development”For local development (.env.local):
NODE_ENV=developmentSITE_URL=http://localhost:4321AUTH_GATEWAY_URL=https://auth.8531.caJWT_SECRET=your-local-jwt-secret📦 Build Process
Section titled “📦 Build Process”Build Commands
Section titled “Build Commands”# Development build (with source maps)npm run build
# Production build (optimized)NODE_ENV=production npm run build
# Build specific outputnpm run build -- --mode productionBuild Optimization
Section titled “Build Optimization”The build process includes:
- Static Site Generation: Pre-builds all pages at build time
- API Routes: Converted to serverless functions
- Asset Optimization: Minification and compression
- Code Splitting: Automatic JavaScript bundling
- Image Optimization: Responsive image generation
Build Outputs
Section titled “Build Outputs”dist/├── _astro/ # Generated Astro assets├── assets/ # Static assets (images, fonts)├── favicon.svg # Site favicon├── manifest.json # PWA manifest└── index.html # Entry point🔄 CI/CD Pipeline
Section titled “🔄 CI/CD Pipeline”GitHub Actions (Optional)
Section titled “GitHub Actions (Optional)”Create .github/workflows/deploy.yml:
name: Deploy
on: push: branches: [main] pull_request: branches: [main]
jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: 20 cache: npm
- run: npm ci - run: npm run build
- name: Deploy to Vercel uses: amondnet/vercel-action@v25 with: vercel-token: ${{ secrets.VERCEL_TOKEN }} vercel-org-id: ${{ secrets.ORG_ID }} vercel-project-id: ${{ secrets.PROJECT_ID }} vercel-args: '--prod'Pre-deployment Checklist
Section titled “Pre-deployment Checklist”Before deploying to production:
- All tests passing
- Environment variables configured
- Build succeeds without errors
- Preview deployment tested
- Security headers verified
- Performance metrics acceptable
- Backup current version (if needed)
🔒 Security Configuration
Section titled “🔒 Security Configuration”Production Security Headers
Section titled “Production Security Headers”{ "X-Frame-Options": "DENY", "X-Content-Type-Options": "nosniff", "X-XSS-Protection": "1; mode=block", "Referrer-Policy": "strict-origin-when-cross-origin", "Permissions-Policy": "camera=(), microphone=(), geolocation=()"}CORS Configuration
Section titled “CORS Configuration”Production CORS settings:
{ "origin": ["https://team.8531.ca"], "methods": ["GET", "POST", "PUT", "DELETE", "OPTIONS"], "allowedHeaders": ["Content-Type", "Authorization"], "credentials": true}SSL/HTTPS
Section titled “SSL/HTTPS”- Production enforces HTTPS
- Automatic SSL certificate via Vercel
- HSTS headers enabled
- Secure cookie flags
📊 Monitoring & Analytics
Section titled “📊 Monitoring & Analytics”Vercel Analytics
Section titled “Vercel Analytics”Built-in Vercel Analytics provides:
- Page view tracking
- Web Vitals monitoring
- Real-time visitor data
- Performance metrics
Custom Monitoring
Section titled “Custom Monitoring”Add custom monitoring:
export function trackEvent(name: string, data?: any) { if (typeof window !== 'undefined' && window.gtag) { window.gtag('event', name, data); }}Error Tracking
Section titled “Error Tracking”Consider adding error tracking:
export function reportError(error: Error) { console.error(error); // Send to error tracking service}🚨 Rollback Procedures
Section titled “🚨 Rollback Procedures”Quick Rollback
Section titled “Quick Rollback”-
Vercel Rollback
Terminal window vercel rollback -
Git Rollback
Terminal window git revert <commit-hash>git push origin main -
Emergency Patch
Terminal window # Create hotfix branchgit checkout -b hotfix/emergency-fix# Make fixesgit commit -m "Emergency fix"git push origin hotfix/emergency-fix
Rollback Checklist
Section titled “Rollback Checklist”Before rolling back:
- Identify problematic commit
- Communicate with team
- Prepare rollback communication
- Test rollback in staging
- Monitor after rollback
- Document root cause
🔄 Domain Configuration
Section titled “🔄 Domain Configuration”Custom Domain Setup
Section titled “Custom Domain Setup”-
DNS Configuration
A @ 76.76.19.61CNAME www vercel.app -
Vercel Domain Settings
- Add domain in Vercel dashboard
- Configure automatic HTTPS
- Set up redirects
-
Environment-specific Domains
- Production:
team.8531.ca - Development:
dev.team.8531.ca - Staging:
staging.team.8531.ca(optional)
- Production:
Domain Redirects
Section titled “Domain Redirects”Configure redirects in vercel.json:
{ "rewrites": [ { "source": "/old-path", "destination": "/new-path" }, { "source": "/blog/:slug", "destination": "/posts/:slug" } ]}📈 Performance Optimization
Section titled “📈 Performance Optimization”Build Optimizations
Section titled “Build Optimizations”- Tree Shaking: Remove unused code
- Minification: Compress JavaScript and CSS
- Image Optimization: Responsive images
- Font Optimization: Font subsetting and preloading
Runtime Optimizations
Section titled “Runtime Optimizations”- Edge Caching: Cache static assets at edge
- API Caching: Cache API responses
- CDN: Global content delivery
- Lazy Loading: Load resources as needed
Performance Budget
Section titled “Performance Budget”Set performance budgets in astro.config.mjs:
export default defineConfig({ vite: { build: { rollupOptions: { output: { manualChunks: { vendor: ['astro'], framework: ['@astrojs/starlight'] } } } } }});🔍 Testing in Production
Section titled “🔍 Testing in Production”A/B Testing
Section titled “A/B Testing”Implement feature flags for A/B testing:
export const flags = { newFeature: process.env.ENABLE_NEW_FEATURE === 'true'};Canary Deployments
Section titled “Canary Deployments”Deploy to subset of users:
- Create canary branch
- Deploy to
canary.team.8531.ca - Route percentage of traffic
- Monitor performance
- Full rollout if successful
Blue-Green Deployment
Section titled “Blue-Green Deployment”- Maintain two production environments
- Switch traffic with DNS
- Instant rollback capability
- Zero-downtime deployments
📋 Maintenance Tasks
Section titled “📋 Maintenance Tasks”Regular Maintenance
Section titled “Regular Maintenance”- Weekly: Review error logs, update dependencies
- Monthly: Security audits, performance reviews
- Quarterly: Architecture review, capacity planning
Dependency Updates
Section titled “Dependency Updates”# Check for outdated packagesnpm outdated
# Update packagesnpm update
# Audit for security vulnerabilitiesnpm audit fixDatabase Maintenance (if applicable)
Section titled “Database Maintenance (if applicable)”- Back up data regularly
- Optimize queries
- Archive old data
- Monitor storage usage
📞 Deployment Support
Section titled “📞 Deployment Support”Getting Help
Section titled “Getting Help”- Vercel Support: Support via Vercel dashboard
- Community: Astro and Starlight Discord
- Documentation: Available on site
- Issues: Create GitHub issues for bugs
Troubleshooting
Section titled “Troubleshooting”Common deployment issues:
-
Build Failures
- Check Node.js version
- Verify environment variables
- Review build logs
-
Runtime Errors
- Check function logs in Vercel
- Verify API routes configuration
- Test environment variables
-
Performance Issues
- Check Vercel Analytics
- Review Core Web Vitals
- Optimize images and assets