Files
CamTalk/deploy.sh
hhs c0b4eeda46 refactor: 统一配置文件系统
- 补全 backend/config.yaml 所有非敏感配置项并添加中文注释
- 重写 config.go:Load(workDir) 显式传参,BindEnv 绑定敏感字段,删除 AutomaticEnv
- setDefaults 默认值与 config.yaml 保持一致(mimo/dashscope)
- backend/.env.example 重写为纯敏感信息模板
- .env 固定在 /opt/camtalk/.env,docker-compose 通过绝对路径加载
- deploy.sh 统一使用 --env-file,移除硬编码 IP
- deploy.yml 删除 CI 写入 .env 的步骤
- Dockerfile 移除 COPY config.yaml
- 修复 deploy.yml 中 POSTGRES_PASSWORD 的 &{{ 拼写错误
2026-06-19 18:41:35 +08:00

102 lines
2.2 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"
# .env 固定路径(独立于项目目录,保证持久性)
ENV_FILE="/opt/camtalk/.env"
# 颜色输出
GREEN='\033[0;32m'
NC='\033[0m'
info() { echo -e "${GREEN}[INFO]${NC} $*"; }
# .env 检查:首次部署时从 .env.example 复制模板,提示用户填写
check_env() {
local env_example="$PROJECT_DIR/backend/.env.example"
if [ ! -f "$ENV_FILE" ]; then
mkdir -p "$(dirname "$ENV_FILE")"
if [ -f "$env_example" ]; then
cp "$env_example" "$ENV_FILE"
info "未找到 $ENV_FILE,已从 .env.example 复制模板"
echo " 请编辑 $ENV_FILE 填入实际配置后重新运行本脚本"
exit 0
else
echo "错误: $ENV_FILE 和 .env.example 均不存在,请手动创建"
exit 1
fi
fi
}
check_env
# 所有 docker compose 命令统一使用 --env-file用于解析 ${POSTGRES_USER} 等变量
DC="docker compose --env-file $ENV_FILE"
cmd_build() {
info "构建 Docker 镜像..."
DOCKER_BUILDKIT=1 $DC build --parallel
info "构建完成"
}
cmd_up() {
info "启动服务..."
$DC up -d
info "服务已启动"
PUBLIC_IP=$(curl -s --connect-timeout 3 https://ifconfig.me 2>/dev/null || \
curl -s --connect-timeout 3 https://api.ipify.org 2>/dev/null || \
echo "YOUR_SERVER_IP")
info "前端: http://$PUBLIC_IP:9000"
info "健康检查: http://$PUBLIC_IP:9000/api/health"
}
cmd_down() {
info "停止服务..."
$DC down
info "服务已停止"
}
cmd_restart() {
info "重启服务..."
cmd_down
cmd_up
}
cmd_logs() {
$DC logs -f "${@}"
}
cmd_status() {
$DC ps
}
usage() {
cat <<EOF
CamTalk 部署脚本
用法: $0 <命令>
命令:
build 构建 Docker 镜像
up 启动服务(后台运行)
down 停止服务
restart 重启服务
logs 查看日志(可加服务名,如: $0 logs backend
status 查看服务状态
.env 路径: $ENV_FILE
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