#!/bin/bash # HTTrack Scraper - Quick Deployment Script # This script helps you quickly deploy the HTTrack Gradio app set -e # Exit on error # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Print colored message print_message() { local color=$1 shift echo -e "${color}$@${NC}" } print_message $BLUE "╔═══════════════════════════════════════════╗" print_message $BLUE "║ HTTrack Website Scraper Deployment ║" print_message $BLUE "╚═══════════════════════════════════════════╝" echo # Check if Docker is installed check_docker() { if ! command -v docker &> /dev/null; then print_message $RED "❌ Docker is not installed!" echo "Please install Docker from: https://docs.docker.com/get-docker/" exit 1 fi print_message $GREEN "✅ Docker is installed" } # Check if Docker Compose is available check_docker_compose() { if docker compose version &> /dev/null; then DOCKER_COMPOSE_CMD="docker compose" print_message $GREEN "✅ Docker Compose V2 is available" elif command -v docker-compose &> /dev/null; then DOCKER_COMPOSE_CMD="docker-compose" print_message $GREEN "✅ Docker Compose V1 is available" else print_message $YELLOW "⚠️ Docker Compose not found, will use Docker only" DOCKER_COMPOSE_CMD="" fi } # Build Docker image build_image() { print_message $BLUE "🔨 Building Docker image..." docker build -t httrack-scraper:latest . || { print_message $RED "❌ Failed to build Docker image" exit 1 } print_message $GREEN "✅ Docker image built successfully" } # Deploy with Docker Compose deploy_compose() { print_message $BLUE "🚀 Deploying with Docker Compose..." $DOCKER_COMPOSE_CMD up -d || { print_message $RED "❌ Failed to deploy with Docker Compose" exit 1 } print_message $GREEN "✅ Deployed successfully with Docker Compose" } # Deploy with Docker only deploy_docker() { print_message $BLUE "🚀 Deploying with Docker..." # Stop and remove existing container if it exists docker stop httrack-scraper 2>/dev/null || true docker rm httrack-scraper 2>/dev/null || true # Run new container docker run -d \ --name httrack-scraper \ -p 7860:7860 \ --restart unless-stopped \ httrack-scraper:latest || { print_message $RED "❌ Failed to deploy with Docker" exit 1 } print_message $GREEN "✅ Deployed successfully with Docker" } # Show deployment info show_info() { echo print_message $GREEN "╔═══════════════════════════════════════════╗" print_message $GREEN "║ Deployment Successful! 🎉 ║" print_message $GREEN "╚═══════════════════════════════════════════╝" echo print_message $BLUE "📍 Access the app at: http://localhost:7860" print_message $BLUE "🐳 Container name: httrack-scraper" echo print_message $YELLOW "Useful commands:" echo " • View logs: docker logs -f httrack-scraper" echo " • Stop app: docker stop httrack-scraper" echo " • Start app: docker start httrack-scraper" echo " • Restart app: docker restart httrack-scraper" if [ -n "$DOCKER_COMPOSE_CMD" ]; then echo " • Compose logs: $DOCKER_COMPOSE_CMD logs -f" echo " • Compose stop: $DOCKER_COMPOSE_CMD down" fi echo } # Check container health check_health() { print_message $BLUE "🏥 Checking container health..." sleep 3 if docker ps | grep -q httrack-scraper; then print_message $GREEN "✅ Container is running" # Try to curl the endpoint if command -v curl &> /dev/null; then if curl -s -f http://localhost:7860/ > /dev/null; then print_message $GREEN "✅ App is responding" else print_message $YELLOW "⚠️ App not responding yet (may need more time to start)" fi fi else print_message $RED "❌ Container is not running" print_message $YELLOW "Check logs with: docker logs httrack-scraper" exit 1 fi } # Main deployment flow main() { # Pre-flight checks check_docker check_docker_compose echo # Build build_image echo # Deploy based on available tools if [ -n "$DOCKER_COMPOSE_CMD" ]; then deploy_compose else deploy_docker fi # Health check check_health # Show info show_info } # Handle script arguments case "${1:-}" in "build") check_docker build_image ;; "deploy") main ;; "stop") print_message $BLUE "🛑 Stopping application..." if [ -n "$DOCKER_COMPOSE_CMD" ]; then check_docker_compose $DOCKER_COMPOSE_CMD down else docker stop httrack-scraper fi print_message $GREEN "✅ Application stopped" ;; "restart") print_message $BLUE "🔄 Restarting application..." if [ -n "$DOCKER_COMPOSE_CMD" ]; then check_docker_compose $DOCKER_COMPOSE_CMD restart else docker restart httrack-scraper fi print_message $GREEN "✅ Application restarted" ;; "logs") if [ -n "$DOCKER_COMPOSE_CMD" ]; then check_docker_compose $DOCKER_COMPOSE_CMD logs -f else docker logs -f httrack-scraper fi ;; "clean") print_message $YELLOW "🧹 Cleaning up..." docker stop httrack-scraper 2>/dev/null || true docker rm httrack-scraper 2>/dev/null || true docker rmi httrack-scraper:latest 2>/dev/null || true print_message $GREEN "✅ Cleanup complete" ;; *) print_message $YELLOW "Usage: $0 {build|deploy|stop|restart|logs|clean}" echo echo "Commands:" echo " build - Build the Docker image only" echo " deploy - Build and deploy the application" echo " stop - Stop the running application" echo " restart - Restart the application" echo " logs - View application logs" echo " clean - Remove container and image" echo echo "Quick start: $0 deploy" exit 1 ;; esac