#!/bin/bash

# QAUP 一键部署脚本

set -e

echo "=== QAUP 一键部署 ==="

# 检查Docker
if ! command -v docker &> /dev/null; then
    echo "❌ Docker 未安装"
    exit 1
fi

# 载入镜像
echo "载入Docker镜像..."
docker load -i images.tar.gz

# 创建数据目录
echo "创建数据目录..."
mkdir -p data/postgres data/redis logs

# 启动服务
echo "启动服务..."
docker compose up -d

# 等待服务启动
echo "等待服务启动（60秒）..."
sleep 60

# 检查服务状态
if curl -f -s http://localhost:8080/actuator/health > /dev/null 2>&1; then
    echo "✅ 部署成功！"
    echo ""
    echo "访问地址: http://localhost:8080"
    echo "数据库: localhost:5432 (qaup/qaup123)"
    echo "Redis: localhost:6379"
    echo ""
    echo "管理命令:"
    echo "  查看状态: docker compose ps"
    echo "  查看日志: docker compose logs -f qaup-app"
    echo "  停止服务: docker compose down"
    echo "  升级应用: ./update.sh"
else
    echo "❌ 服务启动失败，请检查日志:"
    docker compose logs
fi