#!/bin/bash # # Deploy script for test.coppertone.tech # Pulls latest from develop branch, rebuilds, and restarts containers # # Usage: # ./deploy.sh # Full deploy (pull, build, restart) # ./deploy.sh pull # Just pull latest code # ./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" BRANCH="${DEPLOY_BRANCH:-testing}" # 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" pull_latest() { log_info "Pulling latest from $BRANCH branch..." cd "$REPO_DIR" # Ensure we're on the right branch current_branch=$(git branch --show-current) if [ "$current_branch" != "$BRANCH" ]; then log_info "Switching from $current_branch to $BRANCH..." git checkout "$BRANCH" fi # Pull latest git fetch origin "$BRANCH" git reset --hard "origin/$BRANCH" # Show latest commit log_success "Updated to: $(git log -1 --oneline)" 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" } show_status() { log_info "Container status:" podman-compose ps echo "" log_info "Recent commits:" cd "$REPO_DIR" git log -3 --oneline cd "$SCRIPT_DIR" } show_logs() { podman-compose logs -f --tail 50 } 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 } full_deploy() { echo "==========================================" echo " Deploying test.coppertone.tech" echo " Branch: $BRANCH" echo "==========================================" echo "" pull_latest echo "" stop_containers echo "" build_containers echo "" start_containers echo "" reload_nginx echo "" log_success "==========================================" log_success " Deployment complete!" log_success "==========================================" echo "" show_status } case "${1:-deploy}" in deploy|"") full_deploy ;; pull) pull_latest ;; 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|pull|build|restart|stop|start|status|logs|reload-nginx}" exit 1 ;; esac