#!/bin/bash # # Deploy script for dev.coppertone.tech # Builds and restarts containers with zero-downtime strategy # # Usage: # ./deploy.sh # Full deploy (build, restart, reload nginx) # ./deploy.sh build # Just rebuild containers # ./deploy.sh restart # Just restart containers # ./deploy.sh status # Show status # ./deploy.sh logs # Show logs # set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_DIR="$SCRIPT_DIR/repo" DOMAIN="dev.coppertone.tech" # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' log_info() { echo -e "${BLUE}[INFO]${NC} $1"; } log_success() { echo -e "${GREEN}[OK]${NC} $1"; } log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } log_error() { echo -e "${RED}[ERROR]${NC} $1"; } cd "$SCRIPT_DIR" build_containers() { log_info "Building containers..." podman-compose build --no-cache log_success "Build complete" } stop_containers() { log_info "Stopping containers..." podman-compose down 2>/dev/null || true log_success "Containers stopped" } start_containers() { log_info "Starting containers..." podman-compose up -d log_success "Containers started" } reload_nginx() { log_info "Reloading nginx..." if /docker/www/scripts/nginx-reload.sh 2>/dev/null; then log_success "Nginx reloaded" else log_warn "Nginx reload failed (non-fatal)" fi } show_status() { log_info "Container status:" podman-compose ps echo "" if [ -d "$REPO_DIR" ]; then log_info "Recent commits:" cd "$REPO_DIR" git log -3 --oneline cd "$SCRIPT_DIR" fi } show_logs() { podman-compose logs -f --tail 50 } full_deploy() { echo "==========================================" echo " Deploying $DOMAIN" echo "==========================================" echo "" # Build FIRST while old containers still serve traffic build_containers echo "" # Quick restart stop_containers start_containers echo "" # Reload nginx reload_nginx echo "" log_success "==========================================" log_success " Deployment complete!" log_success "==========================================" echo "" show_status } case "${1:-deploy}" in deploy|"") full_deploy ;; build) build_containers ;; restart) stop_containers start_containers ;; stop) stop_containers ;; start) start_containers ;; status) show_status ;; logs) show_logs ;; reload-nginx) reload_nginx ;; *) echo "Usage: $0 {deploy|build|restart|stop|start|status|logs|reload-nginx}" exit 1 ;; esac