#!/bin/bash # Deployment script for chuckie.coppertone.tech (MarketManager) # Can be triggered by webhook or run manually set -e DEPLOY_DIR="/docker/web-hosts/domains/chuckie.coppertone.tech" REPO_DIR="$DEPLOY_DIR/repo" LOG_FILE="$DEPLOY_DIR/deploy.log" log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE" } log "=====================================" log "Starting MarketManager deployment" log "=====================================" cd "$DEPLOY_DIR" # Pull latest code from Gitea log "Pulling latest code from Gitea..." cd "$REPO_DIR" git fetch gitea main 2>&1 | tee -a "$LOG_FILE" git reset --hard gitea/main 2>&1 | tee -a "$LOG_FILE" git clean -fd 2>&1 | tee -a "$LOG_FILE" COMMIT=$(git log -1 --pretty=format:'%h - %s (%an)') log "Deployed commit: $COMMIT" cd "$DEPLOY_DIR" # Rebuild containers log "Building containers..." podman-compose build --no-cache 2>&1 | tee -a "$LOG_FILE" # Stop old containers log "Stopping old containers..." podman-compose down --timeout 30 2>&1 | tee -a "$LOG_FILE" || true # Start new containers log "Starting new containers..." podman-compose up -d 2>&1 | tee -a "$LOG_FILE" # Wait for services to start log "Waiting for services to start..." sleep 10 # Reload nginx log "Reloading nginx..." /docker/www/scripts/nginx-reload.sh 2>&1 | tee -a "$LOG_FILE" # Health check log "Checking service health..." if curl -sf http://localhost:9200/health > /dev/null; then log "✓ Backend health check passed" else log "✗ Backend health check failed!" fi # Show container status log "Container status:" podman-compose ps 2>&1 | tee -a "$LOG_FILE" log "=====================================" log "Deployment complete!" log "====================================="