#!/bin/bash # Claude Code Tracker Docker Deployment Script set -e echo "🚀 Deploying Claude Code Tracker with Docker..." # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Function to print colored output print_status() { echo -e "${BLUE}[INFO]${NC} $1" } print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } print_error() { echo -e "${RED}[ERROR]${NC} $1" } # Check if .env file exists if [ ! -f ".env" ]; then print_warning ".env file not found. Creating from .env.example..." cp .env.example .env print_status "Please edit .env file to configure your domain and other settings" fi # Check if Caddy network exists if ! docker network ls | grep -q "caddy"; then print_warning "Caddy network not found. Creating external network..." docker network create caddy print_success "Created 'caddy' external network" else print_status "Caddy network already exists" fi # Create data directory if it doesn't exist if [ ! -d "./data" ]; then print_status "Creating data directory..." mkdir -p ./data fi # Set permissions for data directory chmod 755 ./data print_status "Building and starting containers..." # Build and start the containers docker-compose up -d --build # Wait for the service to be ready print_status "Waiting for service to be ready..." sleep 10 # Check if the service is healthy if docker-compose ps | grep -q "Up (healthy)"; then print_success "Claude Code Tracker is running and healthy!" else print_warning "Service is starting up. Checking logs..." docker-compose logs --tail=20 claude-tracker fi # Display useful information echo "" echo "📋 Deployment Information:" echo "==========================" print_status "Container name: claude-tracker-api" print_status "Internal port: 8000" # Read domain from .env file if [ -f ".env" ]; then DOMAIN=$(grep "^DOMAIN=" .env | cut -d'=' -f2) if [ -n "$DOMAIN" ]; then print_status "External URL: https://$DOMAIN" else print_status "External URL: Configure DOMAIN in .env file" fi fi echo "" echo "🔧 Management Commands:" echo "======================" echo "View logs: docker-compose logs -f claude-tracker" echo "Restart service: docker-compose restart claude-tracker" echo "Stop service: docker-compose down" echo "Update service: docker-compose pull && docker-compose up -d" echo "Shell access: docker-compose exec claude-tracker /bin/bash" echo "" echo "📊 Health Check:" echo "================" echo "Container status: docker-compose ps" echo "Health endpoint: curl http://localhost:8000/health" echo "API documentation: https://$DOMAIN/docs" echo "Dashboard: https://$DOMAIN/dashboard" echo "" echo "🎯 Hook Configuration:" echo "=====================" echo "Download pre-built hook configs from:" echo "https://$DOMAIN/dashboard/docs/hook-reference" echo "" print_success "Deployment completed! 🎉" # Check if Caddy is running if docker ps | grep -q caddy; then print_success "Caddy reverse proxy detected" else print_warning "Caddy reverse proxy not running. Start it to access via domain." fi