Files
site_aegisone/max_bot/max_bot_deploy.sh
T

107 lines
4.2 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# ==========================================
# MAX Bot — Deploy Script
# ==========================================
# Usage: bash max_bot_deploy.sh
# Run on VPS as angel user (or from local with SSH)
set -e
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; NC='\033[0m'
log() { echo -e "${CYAN}[$(date +%H:%M:%S)]${NC} $1"; }
ok() { echo -e " ${GREEN}$1${NC}"; }
info() { echo -e " ${YELLOW}$1${NC}"; }
fail() { echo -e " ${RED}$1${NC}"; exit 1; }
cd "$(dirname "$0")"
echo -e "${CYAN}"
echo "=========================================="
echo " MAX Bot — Deploy"
echo "=========================================="
echo -e "${NC}"
BOT="/opt/projects/aegisone-py/max_bot"
PY="/opt/projects/aegisone-py"
NGX="/opt/projects/nginx-proxy"
# ==========================================
# 1. Deploy max_bot files
# ==========================================
log "Deploying max_bot files..."
mkdir -p "$BOT"
rsync -a --delete ./ "$BOT/" 2>/dev/null || cp -r ./* "$BOT/"
ok "Files deployed to $BOT"
# ==========================================
# 2. Deploy nginx config
# ==========================================
log "Deploying nginx config for max.aegisone.ru..."
cp max_bot/nginx/max-aegisone.conf "$NGX/conf.d/max-aegisone.conf"
docker compose -f "$NGX/docker-compose.yml" exec nginx nginx -s reload 2>/dev/null || true
ok "Nginx reloaded"
# ==========================================
# 3. Run SQL migrations
# ==========================================
PG_CONTAINER=$(docker ps --filter "name=aegisone-postgres" --format "{{.ID}}" | head -1)
if [ -n "$PG_CONTAINER" ]; then
log "Running SQL migration v1.5.0..."
cat "$PY/sql/v1.5.0_migration.sql" 2>/dev/null | docker exec -i "$PG_CONTAINER" psql -U aegisone -d aegisone 2>&1 | grep -v "^INSERT\|^CREATE\|^ALTER\|^CREATE INDEX" || true
ok "SQL migration v1.5.0 applied"
log "Running SQL migration v1.5.2..."
cat "$BOT/sql/migrations/v1.5.2_role_menu_permissions.sql" 2>/dev/null | docker exec -i "$PG_CONTAINER" psql -U aegisone -d aegisone 2>&1 | grep -v "^INSERT\|^CREATE\|^ALTER\|^CREATE INDEX" || true
ok "SQL migration v1.5.2 applied"
log "Running SQL migration v1.5.5..."
cat "$BOT/sql/migrations/v1.5.5_tables_and_seed.sql" 2>/dev/null | docker exec -i "$PG_CONTAINER" psql -U aegisone -d aegisone 2>&1 | grep -v "^INSERT\|^CREATE\|^ALTER\|^CREATE INDEX" || true
ok "SQL migration v1.5.5 applied"
else
info "PostgreSQL container not found — run migration manually"
fi
# ==========================================
# 4. Run SQL migration v1.6.0 via docker exec pipe
# ==========================================
PG_CONTAINER=$(docker ps --filter "name=aegisone-postgres" --format "{{.ID}}" | head -1)
if [ -n "$PG_CONTAINER" ]; then
log "Running SQL migration v1.6.0..."
cat "$BOT/sql/migrations/v1.6.0_fixes.sql" | docker exec -i "$PG_CONTAINER" psql -U aegisone -d aegisone 2>&1 | grep -v "^INSERT\|^UPDATE\|^DELETE\|^ALTER TABLE\|^CREATE INDEX\|^DROP VIEW" || true
ok "SQL migration v1.6.0 applied"
else
info "PostgreSQL container not found — run migration manually"
fi
# ==========================================
# 5. Build & start max_bot
# ==========================================
log "Building and starting max_bot..."
cd "$BOT" && docker compose up -d --build
ok "max_bot started on port 8002"
# ==========================================
# 6. Health check
# ==========================================
log "Checking health..."
sleep 3
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8002/health 2>/dev/null || echo "000")
if [ "$HTTP_CODE" = "200" ]; then
ok "max_bot is healthy (HTTP $HTTP_CODE)"
else
info "Health check returned HTTP $HTTP_CODE — check logs: docker logs aegisone-max-bot"
fi
# ==========================================
# Done
# ==========================================
echo ""
echo -e "${GREEN}=========================================="
echo " MAX Bot deploy complete!"
echo "==========================================${NC}"
echo ""
echo " Bot webhook: https://max.aegisone.ru/webhook"
echo " Bot API: https://max.aegisone.ru/api/"
echo " Health check: http://localhost:8002/health"
echo " Logs: docker logs -f aegisone-max-bot"
echo ""