adeo-maturity-tool/deploy.sh
Phil Dore aa4d730833 Add Docker deploy files (Dockerfile, docker-compose, deploy.sh)
Matches loreal-spec-tool deploy pattern. Runs on port 3102.
clients/ dir mounted as volume so data.json persists across deploys.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-28 16:52:07 +01:00

63 lines
2.6 KiB
Bash
Executable file

#!/bin/bash
# =============================================================================
# deploy.sh — idempotent deploy for adeo-maturity-tool
# Usage: bash /opt/adeo-maturity-tool/deploy.sh
# =============================================================================
set -euo pipefail
APP_NAME="adeo-maturity-tool"
REPO_DIR="/opt/${APP_NAME}"
COMPOSE_FILE="${REPO_DIR}/docker-compose.yml"
GREEN='\033[0;32m'; YELLOW='\033[1;33m'; RED='\033[0;31m'; BOLD='\033[1m'; NC='\033[0m'
log() { echo -e "${GREEN}[deploy]${NC} $1"; }
warn() { echo -e "${YELLOW}[warn]${NC} $1"; }
error() { echo -e "${RED}[error]${NC} $1"; exit 1; }
step() { echo -e "\n${BOLD}$1${NC}"; }
compose() { docker compose -f "$COMPOSE_FILE" "$@"; }
step "Checking prerequisites"
command -v git >/dev/null 2>&1 || error "git is not installed"
command -v docker >/dev/null 2>&1 || error "docker is not installed"
docker compose version >/dev/null 2>&1 || error "docker compose v2 not found"
step "Pulling latest code"
cd "$REPO_DIR"
git pull origin main
log "Code: $(git log -1 --format='%h %s')"
step "Building Docker image"
compose build --pull
log "Build complete"
step "Starting application"
compose up -d app
log "Container started"
step "Health check"
sleep 2
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3102/api/health || echo "000")
[ "$HTTP_STATUS" = "200" ] && log "API OK (HTTP 200)" || error "Health check failed (HTTP ${HTTP_STATUS})"
FIRST_RUN_FLAG="${REPO_DIR}/.deployed"
if [ ! -f "$FIRST_RUN_FLAG" ]; then
touch "$FIRST_RUN_FLAG"
echo ""
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD} First deploy. Add this to your Apache VirtualHost:${NC}"
echo ""
echo " ProxyPass /adeo-maturity http://localhost:3102"
echo " ProxyPassReverse /adeo-maturity http://localhost:3102"
echo ""
echo " Then: sudo a2enmod proxy proxy_http && sudo systemctl reload apache2"
echo ""
echo -e "${BOLD} NOTE: clients/adeo/data.json is NOT in git.${NC}"
echo " Upload it to ${REPO_DIR}/clients/adeo/data.json after first deploy."
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
fi
echo ""
echo -e "${GREEN}${BOLD}Deploy complete${NC}$(date '+%Y-%m-%d %H:%M:%S')"
echo -e " App: http://localhost:3102 | API: http://localhost:3102/api/health"
echo ""