Cloud Deployment¶
Deploy MyAIAssistant to various cloud platforms.
AWS (Amazon Web Services)¶
EC2 (Virtual Server)¶
- Launch an EC2 instance (Ubuntu 22.04 recommended)
- Install Docker and Docker Compose:
- Clone and deploy:
- Configure security groups:
- Allow inbound TCP 80 (HTTP)
- Allow inbound TCP 8000 (API)
- Allow inbound TCP 443 (HTTPS) if using SSL
ECS (Elastic Container Service)¶
- Push images to Amazon ECR:
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <account>.dkr.ecr.us-east-1.amazonaws.com
docker tag myaiassistant-backend:latest <account>.dkr.ecr.us-east-1.amazonaws.com/myaiassistant-backend:latest
docker push <account>.dkr.ecr.us-east-1.amazonaws.com/myaiassistant-backend:latest
- Create ECS task definitions
- Create ECS service with load balancer
- Configure target groups for health checks
Google Cloud Platform¶
Compute Engine¶
- Create a VM instance
- Install Docker:
- Deploy with docker-compose
Cloud Run¶
Deploy as serverless containers:
# Build and push to Container Registry
gcloud builds submit --tag gcr.io/PROJECT_ID/myaiassistant-backend ./backend
gcloud builds submit --tag gcr.io/PROJECT_ID/myaiassistant-frontend ./frontend
# Deploy to Cloud Run
gcloud run deploy myaiassistant-backend \
--image gcr.io/PROJECT_ID/myaiassistant-backend \
--platform managed \
--allow-unauthenticated
Microsoft Azure¶
Container Instances¶
- Create Azure Container Registry
- Push images:
az acr login --name myregistry
docker tag myaiassistant-backend myregistry.azurecr.io/myaiassistant-backend
docker push myregistry.azurecr.io/myaiassistant-backend
- Create container group:
az container create \
--resource-group mygroup \
--name myaiassistant \
--image myregistry.azurecr.io/myaiassistant-backend \
--ports 8000
DigitalOcean¶
Droplets¶
- Create a Docker Droplet from marketplace
- SSH and deploy:
App Platform¶
- Connect GitHub repository
- Configure build settings:
- Backend: Dockerfile in
./backend - Frontend: Dockerfile in
./frontend - Set environment variables
- Deploy
Reverse Proxy Setup¶
Nginx¶
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://localhost:80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /api {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Traefik¶
Add labels to docker-compose.yml:
services:
backend:
labels:
- "traefik.enable=true"
- "traefik.http.routers.backend.rule=Host(`yourdomain.com`) && PathPrefix(`/api`)"
- "traefik.http.services.backend.loadbalancer.server.port=8000"
frontend:
labels:
- "traefik.enable=true"
- "traefik.http.routers.frontend.rule=Host(`yourdomain.com`)"
- "traefik.http.services.frontend.loadbalancer.server.port=80"
SSL/TLS Configuration¶
Let's Encrypt with Certbot¶
# Install certbot
sudo apt install certbot python3-certbot-nginx -y
# Generate certificate
sudo certbot --nginx -d yourdomain.com
# Auto-renewal (already configured by certbot)
sudo certbot renew --dry-run
Docker with Let's Encrypt¶
Add certbot service:
services:
certbot:
image: certbot/certbot
volumes:
- ./certbot/conf:/etc/letsencrypt
- ./certbot/www:/var/www/certbot
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
Scaling¶
Horizontal Scaling¶
Scale backend instances:
Or via command:
Load Balancer¶
Add nginx load balancer:
services:
nginx:
image: nginx:alpine
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- backend
Database Considerations¶
For production scaling:
- Replace SQLite with PostgreSQL
- Use managed database service (RDS, Cloud SQL)
- Configure connection pooling
- Set up read replicas for high traffic
Monitoring¶
Container Health¶
# Check container status
docker-compose ps
# View resource usage
docker stats
# View logs
docker-compose logs -f
Application Monitoring¶
The backend exposes a health endpoint:
Consider adding:
- Prometheus metrics
- Grafana dashboards
- Log aggregation (ELK, CloudWatch)
Security Checklist¶
- [ ] Use environment variables for secrets
- [ ] Enable HTTPS/SSL
- [ ] Configure CORS properly
- [ ] Use network isolation
- [ ] Keep base images updated
- [ ] Implement rate limiting
- [ ] Use strong passwords
- [ ] Enable container security scanning
- [ ] Restrict container capabilities
- [ ] Use non-root users in containers