Files
CamTalk/deploy.sh

77 lines
1.4 KiB
Bash
Executable File
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.
#!/usr/bin/env bash
set -euo pipefail
PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$PROJECT_DIR"
# 颜色输出
GREEN='\033[0;32m'
NC='\033[0m'
info() { echo -e "${GREEN}[INFO]${NC} $*"; }
cmd_build() {
info "构建 Docker 镜像..."
# 启用 BuildKit 加速构建
DOCKER_BUILDKIT=1 docker compose build --parallel
info "构建完成"
}
cmd_up() {
info "启动服务..."
docker compose up -d
info "服务已启动"
# 获取公网 IP
PUBLIC_IP=$(curl -s --max-time 5 ifconfig.me 2>/dev/null || curl -s --max-time 5 ip.sb 2>/dev/null || echo "YOUR_SERVER_IP")
info "前端: http://${PUBLIC_IP}:9000"
info "健康检查: http://${PUBLIC_IP}:9000/api/health"
}
cmd_down() {
info "停止服务..."
docker compose down
info "服务已停止"
}
cmd_restart() {
info "重启服务..."
cmd_down
cmd_up
}
cmd_logs() {
docker compose logs -f "${@}"
}
cmd_status() {
docker compose ps
}
usage() {
cat <<EOF
CamTalk 部署脚本
用法: $0 <命令>
命令:
build 构建 Docker 镜像
up 启动服务(后台运行)
down 停止服务
restart 重启服务
logs 查看日志(可加服务名,如: $0 logs backend
status 查看服务状态
EOF
}
case "${1:-}" in
build) cmd_build ;;
up) cmd_up ;;
down) cmd_down ;;
restart) cmd_restart ;;
logs) shift; cmd_logs "$@" ;;
status) cmd_status ;;
*) usage; exit 1 ;;
esac