forked from quant-speed-AI/Scoring-System
chore: 优化 Docker 配置,添加生产环境部署脚本和文档
This commit is contained in:
95
deploy.sh
Normal file
95
deploy.sh
Normal file
@@ -0,0 +1,95 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 创赢未来报名评分系统 - 生产环境部署脚本
|
||||
# 用法: ./deploy.sh [环境变量]
|
||||
|
||||
set -e
|
||||
|
||||
# 颜色定义
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# 打印带颜色的信息
|
||||
print_info() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# 检查环境
|
||||
print_info "检查 Docker 环境..."
|
||||
if ! command -v docker &> /dev/null; then
|
||||
print_error "Docker 未安装,请先安装 Docker"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v docker-compose &> /dev/null && ! docker compose version &> /dev/null; then
|
||||
print_error "Docker Compose 未安装,请先安装 Docker Compose"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 检查 .env 文件
|
||||
if [ ! -f .env ]; then
|
||||
print_warning ".env 文件不存在,将使用默认配置"
|
||||
print_warning "建议复制 .env.example 为 .env 并修改配置"
|
||||
fi
|
||||
|
||||
# 显示部署信息
|
||||
print_info "================================"
|
||||
print_info "创赢未来报名评分系统 - 部署脚本"
|
||||
print_info "================================"
|
||||
|
||||
# 拉取最新代码(如果是 git 仓库)
|
||||
if [ -d .git ]; then
|
||||
print_info "拉取最新代码..."
|
||||
git pull || print_warning "Git pull 失败,使用本地代码继续"
|
||||
fi
|
||||
|
||||
# 停止旧容器
|
||||
print_info "停止旧容器..."
|
||||
docker-compose down --remove-orphans
|
||||
|
||||
# 删除旧镜像(可选)
|
||||
print_info "清理旧镜像..."
|
||||
docker-compose rm -f
|
||||
|
||||
# 构建镜像
|
||||
print_info "构建 Docker 镜像..."
|
||||
docker-compose build --no-cache
|
||||
|
||||
# 启动服务
|
||||
print_info "启动服务..."
|
||||
docker-compose up -d
|
||||
|
||||
# 等待服务启动
|
||||
print_info "等待服务启动..."
|
||||
sleep 10
|
||||
|
||||
# 检查服务状态
|
||||
print_info "检查服务状态..."
|
||||
if docker-compose ps | grep -q "Up"; then
|
||||
print_success "服务启动成功!"
|
||||
echo ""
|
||||
print_info "访问地址:"
|
||||
print_success " - 前端: http://localhost"
|
||||
print_success " - 后端 API: http://localhost:8000/api/"
|
||||
print_success " - 后台管理: http://localhost:8000/admin/"
|
||||
echo ""
|
||||
print_info "查看日志: docker-compose logs -f"
|
||||
else
|
||||
print_error "服务启动失败,请检查日志: docker-compose logs"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user