This guide will help you deploy the Draw2StoryPlay application to your Google Cloud VM using Docker and Docker Compose.
The application consists of 5 main components:
- Frontend (Vue.js SPA) - Port 80
- Backend API (Express.js) - Port 3000
- Animation API (Python Flask) - Port 5000
- PostgreSQL Database - Port 5432
- Redis (Task Queue) - Port 6379
- Nginx (Reverse Proxy) - Port 80/443
- OS: Ubuntu 20.04+ or Debian 11+
- RAM: Minimum 4GB (8GB recommended)
- Storage: Minimum 20GB
- CPU: 2+ cores
- Network: Public IP with ports 80, 443 open
- Docker Engine 20.10+
- Docker Compose 2.0+
- Git
ssh -i your-key.pem username@137.184.162.109# Update system
sudo apt update && sudo apt upgrade -y
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $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 to take effect
exit
# SSH back ingit clone https://github.com/UTSC-CSCC09-Programming-on-the-Web/project-meaaji.git
cd project-meaaji# Copy the production environment template
cp env.production.example .env
# Edit the .env file with your actual values
nano .envRequired Environment Variables:
DB_PASSWORD=your_secure_postgres_password_hereGOOGLE_CLIENT_ID=your_google_oauth_client_id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your_google_oauth_client_secret
FRONTEND_URL=https://137.184.162.109
GOOGLE_CALLBACK_URL=https://137.184.162.109/auth/callbackJWT_SECRET=your_super_secure_jwt_secret_make_it_long_and_randomSTRIPE_SECRET_KEY=sk_live_your_stripe_live_secret_key
STRIPE_WEBHOOK_SECRET=whsec_your_stripe_webhook_secret
MONTHLY_PRICE_ID=price_your_monthly_price_idVITE_API_URL=https://137.184.162.109
VITE_STRIPE_PUBLISHABLE_KEY=pk_live_your_stripe_live_publishable_key
VITE_GOOGLE_CLIENT_ID=your_google_oauth_client_id.apps.googleusercontent.comCO_API_KEY=your_cohere_api_key
STABILITY_API_KEY=your_stability_ai_api_key- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Google+ API
- Create OAuth 2.0 credentials:
- Choose Web application
- Add authorized redirect URI:
https://137.184.162.109/auth/callback
- Copy Client ID and Client Secret to your
.envfile
- Go to Stripe Dashboard
- Switch to Live mode
- Get live API keys from Developers β API keys
- Create subscription product:
- Go to Products β Add product
- Set name: "Monthly Subscription"
- Set pricing: Recurring, Monthly, $9.99
- Copy the Price ID
- Configure webhook endpoint:
- Go to Developers β Webhooks
- Add endpoint:
https://137.184.162.109/webhook - Select events:
checkout.session.completed,customer.subscription.updated,customer.subscription.deleted - Copy the webhook secret
# Make the deployment script executable
chmod +x deploy.sh
# Run the deployment
./deploy.sh# Check if all services are running
docker-compose ps
# Check logs if needed
docker-compose logs -f [service_name]
# Test the application
curl http://localhost/health# All services
docker-compose logs -f
# Specific service
docker-compose logs -f backend
docker-compose logs -f frontend
docker-compose logs -f animation# All services
docker-compose restart
# Specific service
docker-compose restart backend# Stop all services
docker-compose down
# Start all services
docker-compose up -d# Pull latest code
git pull
# Rebuild and restart
docker-compose down
docker-compose up --build -d# Allow only necessary ports
sudo ufw allow 22/tcp # SSH
sudo ufw allow 80/tcp # HTTP
sudo ufw allow 443/tcp # HTTPS
sudo ufw enable- Install Certbot:
sudo apt install certbot python3-certbot-nginx- Get SSL certificate:
sudo certbot --nginx -d your-domain.com- Update nginx configuration to use HTTPS
- Use strong passwords
- Restrict database access to application containers only
- Regular backups
# Application health
curl http://localhost/health
# Backend health
curl http://localhost:3000/health
# Animation API health
curl http://localhost:5000/api/health# Container resource usage
docker stats
# Disk usage
df -h
# Memory usage
free -h# Check logs
docker-compose logs [service_name]
# Check if ports are in use
sudo netstat -tulpn | grep :80
sudo netstat -tulpn | grep :3000# Check database container
docker-compose exec postgres psql -U postgres -d Draw2PlayDB
# Check database logs
docker-compose logs postgres# Check available memory
free -h
# Increase swap if needed
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile# Fix file permissions
sudo chown -R $USER:$USER .
chmod +x deploy.sh# Create backup
docker-compose exec postgres pg_dump -U postgres Draw2PlayDB > backup.sql
# Restore backup
docker-compose exec -T postgres psql -U postgres Draw2PlayDB < backup.sql# Backup uploads
tar -czf uploads_backup.tar.gz backend/uploads/
# Backup animation outputs
tar -czf animation_backup.tar.gz metaAPI/AnimatedDrawings/outputs/If you encounter issues:
- Check the logs:
docker-compose logs -f - Verify environment variables are set correctly
- Ensure all required services are running:
docker-compose ps - Check resource usage:
docker stats
After successful deployment:
- Set up monitoring (optional)
- Configure SSL certificates for HTTPS
- Set up automated backups
- Configure CI/CD pipeline (optional)
- Set up domain name (optional)
Your application should now be accessible at http://137.184.162.109!