#!/bin/bash # Build and Deploy script for Etsy Finance Tracker set -e # Exit on any error echo "🏗️ Etsy Finance Tracker Deployment Script" echo "" # Check if Docker is running if ! docker info > /dev/null 2>&1; then echo "❌ Docker is not running. Please start Docker Desktop and try again." exit 1 fi # Parse command line arguments DEPLOYMENT_TYPE=${1:-"local"} case $DEPLOYMENT_TYPE in "local") echo "📦 Local Build Deployment" echo "This will build the application locally and run it." echo "" # Build the React client echo "� Building React client..." cd client if [ ! -f "package.json" ]; then echo "❌ Client package.json not found" exit 1 fi npm ci --silent npm run build cd .. # Ensure client build directory exists if [ ! -d "client/dist" ]; then echo "❌ Client build failed - dist directory not found" exit 1 fi echo "✅ Client built successfully" # Build and start with Docker Compose echo "🐳 Starting Docker containers (local build)..." docker-compose down --remove-orphans docker-compose up --build -d ;; "ghcr") echo "📦 GitHub Container Registry Deployment" echo "This will use pre-built images from GitHub Container Registry." echo "" echo "🔄 Pulling latest images..." docker-compose -f docker-compose.ghcr.yml pull echo "🐳 Starting Docker containers (GHCR images)..." docker-compose -f docker-compose.ghcr.yml down --remove-orphans docker-compose -f docker-compose.ghcr.yml up -d ;; "help"|"--help"|"-h") echo "Usage: $0 [DEPLOYMENT_TYPE]" echo "" echo "DEPLOYMENT_TYPE:" echo " local - Build locally and deploy (default)" echo " ghcr - Use pre-built images from GitHub Container Registry" echo " help - Show this help message" echo "" echo "Examples:" echo " $0 # Local build" echo " $0 local # Local build" echo " $0 ghcr # Use GitHub images" echo "" exit 0 ;; *) echo "❌ Unknown deployment type: $DEPLOYMENT_TYPE" echo "Run '$0 help' for usage information." exit 1 ;; esac # Wait for services to be ready echo "⏳ Waiting for services to be ready..." sleep 10 # Health check echo "🔍 Checking application health..." for i in {1..10}; do if curl -s http://localhost:3000/health > /dev/null; then echo "✅ Application is healthy!" break fi if [ $i -eq 10 ]; then echo "⚠️ Health check failed, but services may still be starting..." else sleep 2 fi done echo "" echo "🎉 Deployment complete!" echo "" echo "📍 Access Points:" echo " 🌐 Web Application: http://localhost:3000" echo " 🔍 Health Check: http://localhost:3000/health" echo " 📊 API Endpoints: http://localhost:3000/api/" echo "" echo "📋 Management Commands:" if [ "$DEPLOYMENT_TYPE" = "ghcr" ]; then echo " 📊 View logs: docker-compose -f docker-compose.ghcr.yml logs -f" echo " 🔄 Restart: docker-compose -f docker-compose.ghcr.yml restart" echo " 🛑 Stop: docker-compose -f docker-compose.ghcr.yml down" echo " 🔄 Update: docker-compose -f docker-compose.ghcr.yml pull && docker-compose -f docker-compose.ghcr.yml up -d" else echo " 📊 View logs: docker-compose logs -f" echo " 🔄 Restart: docker-compose restart" echo " 🛑 Stop: docker-compose down" echo " 🔄 Rebuild: docker-compose up --build -d" fi echo ""