#!/bin/bash set -e echo "๐Ÿš€ VoxBlog Deployment Script" echo "==============================" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Check if .env exists if [ ! -f .env ]; then echo -e "${RED}โŒ .env file not found!${NC}" echo "Please create .env file from .env.example" exit 1 fi # Pull latest code echo -e "${YELLOW}๐Ÿ“ฅ Pulling latest code...${NC}" git pull origin main # Stop existing containers echo -e "${YELLOW}๐Ÿ›‘ Stopping existing containers...${NC}" docker-compose down # Build new images echo -e "${YELLOW}๐Ÿ”จ Building new images...${NC}" docker-compose build --no-cache # Start containers echo -e "${YELLOW}โ–ถ๏ธ Starting containers...${NC}" docker-compose up -d # Wait for services to be ready echo -e "${YELLOW}โณ Waiting for services to start...${NC}" sleep 15 # Run database migrations echo -e "${YELLOW}๐Ÿ—„๏ธ Running database migrations...${NC}" docker-compose exec -T api pnpm run drizzle:migrate || echo "Migration skipped or failed" # Health check echo -e "${YELLOW}๐Ÿฅ Performing health checks...${NC}" API_HEALTH=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3301/api/health || echo "000") if [ "$API_HEALTH" = "200" ]; then echo -e "${GREEN}โœ… API is healthy${NC}" else echo -e "${RED}โŒ API health check failed (HTTP $API_HEALTH)${NC}" echo "Checking API logs:" docker-compose logs --tail=50 api exit 1 fi ADMIN_HEALTH=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3300 || echo "000") if [ "$ADMIN_HEALTH" = "200" ]; then echo -e "${GREEN}โœ… Admin is healthy${NC}" else echo -e "${RED}โŒ Admin health check failed (HTTP $ADMIN_HEALTH)${NC}" echo "Checking Admin logs:" docker-compose logs --tail=50 admin exit 1 fi # Clean up old images echo -e "${YELLOW}๐Ÿงน Cleaning up old Docker images...${NC}" docker image prune -af --filter "until=24h" echo "" echo -e "${GREEN}โœ… Deployment complete!${NC}" echo "" echo "Services running:" echo " - API: http://localhost:3301" echo " - Admin: http://localhost:3300" echo "" echo "To view logs: docker-compose logs -f" echo "To stop: docker-compose down"