Complete guide for containerizing and deploying HonestLiar on AWS ECS, EKS, or EC2.
- Quick Start with Docker Compose
- AWS ECR Setup
- AWS ECS Deployment
- AWS EKS Deployment
- EC2 Deployment
- Production Best Practices
- Docker 20.10+
- Docker Compose 2.0+
-
Copy environment file:
cp .env.docker .env
-
Edit
.envfile with your configuration -
Start all services:
docker-compose up -d
-
Access the application:
- Frontend: http://localhost:3000
- Backend API: http://localhost:3001
- MongoDB: localhost:27017
-
View logs:
docker-compose logs -f
-
Stop services:
docker-compose down
docker-compose --profile production up -dThis includes an Nginx reverse proxy on port 80.
Backend:
cd backend
docker build -t honestliar-backend:latest .Frontend:
cd frontend
docker build -t honestliar-frontend:latest \
--build-arg VITE_API_URL=http://your-backend-url:3001 .# Test backend
docker run -p 3001:3001 \
-e STORAGE_TYPE=memory \
honestliar-backend:latest
# Test frontend
docker run -p 8080:8080 \
honestliar-frontend:latestaws ecr create-repository --repository-name honestliar-backend --region us-east-1
aws ecr create-repository --repository-name honestliar-frontend --region us-east-1Use the provided script:
chmod +x scripts/build-and-push.sh
./scripts/build-and-push.sh <AWS_ACCOUNT_ID> <AWS_REGION> <VERSION>Example:
./scripts/build-and-push.sh 123456789012 us-east-1 v1.0.0# Login to ECR
aws ecr get-login-password --region us-east-1 | \
docker login --username AWS --password-stdin \
123456789012.dkr.ecr.us-east-1.amazonaws.com
# Tag images
docker tag honestliar-backend:latest \
123456789012.dkr.ecr.us-east-1.amazonaws.com/honestliar-backend:latest
docker tag honestliar-frontend:latest \
123456789012.dkr.ecr.us-east-1.amazonaws.com/honestliar-frontend:latest
# Push images
docker push 123456789012.dkr.ecr.us-east-1.amazonaws.com/honestliar-backend:latest
docker push 123456789012.dkr.ecr.us-east-1.amazonaws.com/honestliar-frontend:latest- VPC with subnets
- Security groups (allow ports 80, 443, 3001, 8080)
- Application Load Balancer (optional)
- ECS Cluster
aws ecs create-cluster --cluster-name honestliar-clusterTask Execution Role (for pulling images):
aws iam create-role \
--role-name ecsTaskExecutionRole \
--assume-role-policy-document file://aws/ecs-task-execution-role.json
aws iam attach-role-policy \
--role-name ecsTaskExecutionRole \
--policy-arn arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicyaws secretsmanager create-secret \
--name honestliar/mongodb-uri \
--secret-string "mongodb://admin:password@mongodb.example.com:27017/honestliar"Edit aws/ecs-task-definition.json:
- Replace
<AWS_ACCOUNT_ID>with your account ID - Replace
<AWS_REGION>with your region - Update image URIs
- Update secret ARNs
aws ecs register-task-definition \
--cli-input-json file://aws/ecs-task-definition.jsonaws ecs create-service \
--cluster honestliar-cluster \
--service-name honestliar-service \
--cli-input-json file://aws/ecs-service.jsonUse the provided script:
chmod +x scripts/deploy-ecs.sh
./scripts/deploy-ecs.sh honestliar-cluster honestliar-service- EKS Cluster running
- kubectl configured
- AWS CLI configured
eksctl create cluster \
--name honestliar-cluster \
--region us-east-1 \
--nodegroup-name standard-workers \
--node-type t3.medium \
--nodes 3 \
--nodes-min 2 \
--nodes-max 4 \
--managedaws eks update-kubeconfig \
--name honestliar-cluster \
--region us-east-1Edit kubernetes/deployment.yaml:
- Replace
<AWS_ACCOUNT_ID>with your account ID - Replace
<AWS_REGION>with your region - Update image URIs
- Update secrets
Deploy application:
kubectl apply -f kubernetes/deployment.yamlDeploy ingress (optional):
kubectl apply -f kubernetes/ingress.yaml# Check pods
kubectl get pods -n honestliar
# Check services
kubectl get services -n honestliar
# Check ingress
kubectl get ingress -n honestliar
# View logs
kubectl logs -f deployment/backend -n honestliarUse the provided script:
chmod +x scripts/deploy-eks.sh
./scripts/deploy-eks.sh honestliar-cluster us-east-1- EC2 instance with Docker installed
- Security group allowing ports 80, 443, 3000, 3001
- Elastic IP (recommended)
# SSH into EC2
ssh -i your-key.pem ec2-user@your-ec2-ip
# Install Docker
sudo yum update -y
sudo yum install docker -y
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -a -G docker ec2-user
# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" \
-o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# Logout and login again for group changes
exit# Clone repository
git clone https://github.com/yourusername/honestliar-game.git
cd honestliar-game
# Copy and edit environment file
cp .env.docker .env
nano .env
# Start services
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
# View logs
docker-compose logs -fCreate systemd service file:
sudo nano /etc/systemd/system/honestliar.service[Unit]
Description=HonestLiar Game
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/home/ec2-user/honestliar-game
ExecStart=/usr/local/bin/docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
ExecStop=/usr/local/bin/docker-compose down
TimeoutStartSec=0
[Install]
WantedBy=multi-user.targetEnable service:
sudo systemctl enable honestliar.service
sudo systemctl start honestliar.service# Install certbot
sudo yum install certbot -y
# Get certificate
sudo certbot certonly --standalone -d your-domain.com
# Copy certificates
sudo mkdir -p nginx/ssl
sudo cp /etc/letsencrypt/live/your-domain.com/fullchain.pem nginx/ssl/cert.pem
sudo cp /etc/letsencrypt/live/your-domain.com/privkey.pem nginx/ssl/key.pem
# Update nginx config to enable HTTPS
# Uncomment HTTPS server block in nginx/nginx.conf
# Restart services
docker-compose restart- Use HTTPS with valid SSL certificates
- Enable authentication for MongoDB
- Use AWS Secrets Manager for sensitive data
- Enable CloudWatch logs for monitoring
- Setup VPC with private subnets
- Use security groups to restrict access
- Enable AWS WAF for DDoS protection
-
CloudWatch Metrics:
# Enable Container Insights (ECS) aws ecs update-cluster-settings \ --cluster honestliar-cluster \ --settings name=containerInsights,value=enabled -
Application Logs:
- ECS: CloudWatch Logs
- EKS: CloudWatch Container Insights
- EC2: Docker logs + CloudWatch agent
-
Health Checks:
- Backend:
http://backend:3001/health - Frontend:
http://frontend:8080/health
- Backend:
ECS Auto Scaling:
aws application-autoscaling register-scalable-target \
--service-namespace ecs \
--scalable-dimension ecs:service:DesiredCount \
--resource-id service/honestliar-cluster/honestliar-service \
--min-capacity 2 \
--max-capacity 10EKS Auto Scaling:
Already configured in kubernetes/deployment.yaml with HorizontalPodAutoscaler.
MongoDB Backup (if using managed MongoDB):
# Create backup
docker exec honestliar-mongodb mongodump --out /data/backup
# Schedule daily backups
0 2 * * * docker exec honestliar-mongodb mongodump --out /data/backup/$(date +\%Y\%m\%d)Rolling Updates (ECS):
./scripts/deploy-ecs.sh honestliar-cluster honestliar-serviceRolling Updates (EKS):
kubectl rollout restart deployment/backend -n honestliar
kubectl rollout restart deployment/frontend -n honestliarZero-Downtime Updates (EC2):
docker-compose pull
docker-compose up -d --no-deps --build# Test backend health
curl http://your-domain:3001/health
# Test frontend
curl http://your-domain:3000
# Test WebSocket connection
wscat -c ws://your-domain:3001/socket.io/# Install Apache Bench
sudo yum install httpd-tools -y
# Test backend
ab -n 1000 -c 10 http://your-domain:3001/health
# Test frontend
ab -n 1000 -c 10 http://your-domain:3000/Docker Compose:
docker-compose logs -f backend
docker-compose logs -f frontendECS:
aws logs tail /ecs/honestliar-backend --followEKS:
kubectl logs -f deployment/backend -n honestliar
kubectl describe pod <pod-name> -n honestliar-
Container won't start:
- Check environment variables
- Verify MongoDB connection
- Check health check logs
-
Cannot connect to backend:
- Verify security groups
- Check CORS settings
- Verify load balancer configuration
-
High CPU/Memory:
- Scale up resources
- Enable auto-scaling
- Check for memory leaks
Need help? Open an issue on GitHub or check our Contributing Guide.