Files
xinghuoapi/scripts/apply-deploy-config.sh
huangzhenpc d46653b2c2
Some checks failed
CI / test (push) Has been cancelled
CI / golangci-lint (push) Has been cancelled
Security Scan / backend-security (push) Has been cancelled
Security Scan / frontend-security (push) Has been cancelled
添加上游同步自动化工具
新增工具脚本:
- scripts/sync-upstream.sh: 主同步脚本,自动从上游拉取并应用配置
- scripts/apply-branding.sh: 自动应用StarFireAPI品牌化修改
- scripts/apply-deploy-config.sh: 自动应用部署配置
- scripts/README.md: 工具使用说明

功能特性:
 自动备份当前分支
 从上游仓库拉取最新代码
 自动应用品牌化修改(Sub2API → StarFireAPI)
 自动应用部署配置(端口、Redis、镜像等)
 智能提示和确认
 支持回滚操作

使用方法:
chmod +x scripts/*.sh
./scripts/sync-upstream.sh

修改 .gitignore 以允许追踪自定义同步工具

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 01:42:21 +08:00

109 lines
2.9 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
# =============================================================================
# 部署配置脚本 - StarFireAPI
# =============================================================================
# 功能:自动应用部署相关的配置修改
# 用法:./scripts/apply-deploy-config.sh
# =============================================================================
set -e
# 颜色输出
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'
log_info() {
echo -e "${BLUE}[部署配置]${NC} $1"
}
log_success() {
echo -e "${GREEN}[部署配置]${NC} $1"
}
# 部署配置
DOCKER_IMAGE="starfireapi:latest"
SERVER_PORT="6580"
REDIS_HOST="172.18.0.2"
REDIS_PORT="6379"
REDIS_PASSWORD="redis_JCHeKT"
log_info "开始应用部署配置..."
# 1. 修改 docker-compose.yml
log_info "修改 docker-compose.yml..."
# 修改镜像名称
sed -i 's|image: weishaw/sub2api:latest|image: starfireapi:latest|g' deploy/docker-compose.yml
# 修改默认端口
sed -i 's|${SERVER_PORT:-8080}|${SERVER_PORT:-6580}|g' deploy/docker-compose.yml
# 修改 Redis 配置为外部 Redis
sed -i 's|REDIS_HOST=redis|REDIS_HOST=${REDIS_HOST:-172.18.0.2}|g' deploy/docker-compose.yml
sed -i 's|- REDIS_PORT=6379|- REDIS_PORT=${REDIS_PORT:-6379}|g' deploy/docker-compose.yml
sed -i 's|- REDIS_PASSWORD=${REDIS_PASSWORD:-}|- REDIS_PASSWORD=${REDIS_PASSWORD:-redis_JCHeKT}|g' deploy/docker-compose.yml
# 移除 Redis 的 depends_on
sed -i '/redis:/,/condition: service_healthy/d' deploy/docker-compose.yml
# 禁用内置 Redis添加 profiles
sed -i '/^ redis:/a\ profiles:\n - disabled' deploy/docker-compose.yml
# 移除 TOTP 配置(如果存在)
sed -i '/TOTP_ENCRYPTION_KEY/,+5d' deploy/docker-compose.yml
# 2. 修改 .env.example
log_info "修改 .env.example..."
# 修改默认端口
sed -i 's|SERVER_PORT=8080|SERVER_PORT=6580|g' deploy/.env.example
# 修改 Redis 配置
sed -i 's|# Redis Configuration|# Redis Configuration (External Redis)|g' deploy/.env.example
sed -i 's|REDIS_HOST=redis|REDIS_HOST=172.18.0.2|g' deploy/.env.example
sed -i '/^REDIS_HOST=/a\REDIS_PORT=6379' deploy/.env.example
sed -i 's|REDIS_PASSWORD=|REDIS_PASSWORD=redis_JCHeKT|g' deploy/.env.example
# 3. 添加部署文档
log_info "添加部署文档..."
if [[ ! -f "DEPLOY_SERVER.md" ]]; then
cat > DEPLOY_SERVER.md << 'DEPLOY_DOC'
# StarFireAPI 服务器部署文档
## 快速部署
```bash
# 1. 克隆代码
git clone https://git.586vip.cn/oadmin/xinghuoapi.git
cd xinghuoapi
# 2. 配置环境变量
cd deploy
cp .env.example .env
# 编辑 .env 设置密码等配置
# 3. 构建镜像
cd ..
docker build -t starfireapi:latest .
# 4. 启动服务
cd deploy
docker compose up -d
# 5. 查看日志
docker compose logs -f sub2api
```
## 配置说明
- **服务端口**: 6580
- **外部Redis**: 172.18.0.2:6379
- **镜像名称**: starfireapi:latest
详细配置请参考 deploy/.env.example
DEPLOY_DOC
fi
log_success "部署配置应用完成"