#!/bin/bash # Deployment script for Dashboard Solusi AI Peternakan Ayam # Usage: ./deploy.sh [dev|prod] set -e MODE="${1:-prod}" echo "=========================================" echo " Dashboard Peternakan Ayam Deployment" echo "=========================================" echo "" echo "Mode: $MODE" echo "" # Check if Docker is installed if ! command -v docker &> /dev/null; then echo "❌ Docker is not installed. Please install Docker first." echo " Visit: https://docs.docker.com/get-docker/" exit 1 fi # Check if Docker Compose is installed if ! command -v docker-compose &> /dev/null; then echo "❌ Docker Compose is not installed. Please install Docker Compose first." echo " Visit: https://docs.docker.com/compose/install/" exit 1 fi echo "✓ Docker installed: $(docker --version)" echo "✓ Docker Compose installed: $(docker-compose --version)" echo "" # Create data directory if it doesn't exist if [ ! -d "data" ]; then echo "📁 Creating data directory..." mkdir -p data chmod 755 data echo "✓ Data directory created" else echo "✓ Data directory exists" fi echo "" # Pull latest code (if in git repo) if [ -d ".git" ]; then echo "📥 Pulling latest code..." git pull origin main || git pull origin evan || echo "⚠ Could not pull latest code" echo "" fi # Stop existing containers echo "🛑 Stopping existing containers..." docker-compose down echo "✓ Containers stopped" echo "" # Build images echo "🔨 Building Docker images..." docker-compose build --no-cache echo "✓ Images built" echo "" # Start containers if [ "$MODE" = "dev" ]; then echo "🚀 Starting containers in development mode..." docker-compose up else echo "🚀 Starting containers in production mode..." docker-compose up -d echo "✓ Containers started" echo "" # Wait for services to be healthy echo "⏳ Waiting for services to be healthy..." sleep 10 # Check container status echo "" echo "📊 Container Status:" docker-compose ps echo "" # Check health echo "🏥 Health Check:" # Check backend if curl -sf http://localhost:5001/health > /dev/null 2>&1; then echo "✓ Backend is healthy" else echo "⚠ Backend health check failed" fi # Check frontend if curl -sf http://localhost/health > /dev/null 2>&1; then echo "✓ Frontend is healthy" else echo "⚠ Frontend health check failed" fi echo "" echo "=========================================" echo " 🎉 Deployment Complete!" echo "=========================================" echo "" echo "Frontend: http://localhost" echo "Backend API: http://localhost:5001" echo "" echo "View logs: docker-compose logs -f" echo "Stop: docker-compose stop" echo "Remove: docker-compose down" echo "" fi