-
Notifications
You must be signed in to change notification settings - Fork 142
feat: 添加Linux部署脚本幂等性,更新README.md #566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -149,6 +149,7 @@ Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force | |||||
|
|
||||||
| - ⚠️ 请妥善保存脚本输出的**管理员令牌**(Admin Token),这是登录后台的唯一凭证! | ||||||
| - ⚠️ Windows 用户:如果未安装 Docker Desktop,脚本会自动打开下载页面 | ||||||
| - ⚠️ 软件更新:请参考 `Docker Compose 启动章节`,deploy脚本仅用于首次部署,并不用于更新软件 (环境限制,目前仅暂在 Linux 安装脚本确保了部署幂等性,未覆盖 Powershell 脚本) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 文案存在小笔误。 "目前仅暂在 Linux" 中的"暂"字应删除或改为"目前仅在"。 📝 建议的修改-- ⚠️ 软件更新:请参考 `Docker Compose 启动章节`,deploy脚本仅用于首次部署,并不用于更新软件 (环境限制,目前仅暂在 Linux 安装脚本确保了部署幂等性,未覆盖 Powershell 脚本)
+- ⚠️ 软件更新:请参考 `Docker Compose 启动章节`,deploy 脚本仅用于首次部署,并不用于更新软件(环境限制,目前仅在 Linux 安装脚本确保了部署幂等性,未覆盖 PowerShell 脚本)另外建议:
📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| ### 三步启动(Docker Compose) | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -47,6 +47,7 @@ DIR_ARG="" | |||||||||||||||||||||||||||||
| DOMAIN_ARG="" | ||||||||||||||||||||||||||||||
| ENABLE_CADDY=false | ||||||||||||||||||||||||||||||
| NON_INTERACTIVE=false | ||||||||||||||||||||||||||||||
| FORCE_REINSTALL=false | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| show_help() { | ||||||||||||||||||||||||||||||
| cat << EOF | ||||||||||||||||||||||||||||||
|
|
@@ -62,6 +63,7 @@ Options: | |||||||||||||||||||||||||||||
| --domain <domain> Domain for Caddy HTTPS (enables Caddy automatically) | ||||||||||||||||||||||||||||||
| --enable-caddy Enable Caddy reverse proxy without HTTPS (HTTP only) | ||||||||||||||||||||||||||||||
| -y, --yes Non-interactive mode (skip prompts, use defaults) | ||||||||||||||||||||||||||||||
| -f, --force Force reinstall (remove existing installation) | ||||||||||||||||||||||||||||||
| -h, --help Show this help message | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Examples: | ||||||||||||||||||||||||||||||
|
|
@@ -128,6 +130,10 @@ parse_args() { | |||||||||||||||||||||||||||||
| NON_INTERACTIVE=true | ||||||||||||||||||||||||||||||
| shift | ||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||
| -f|--force) | ||||||||||||||||||||||||||||||
| FORCE_REINSTALL=true | ||||||||||||||||||||||||||||||
| shift | ||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||
| -h|--help) | ||||||||||||||||||||||||||||||
| show_help | ||||||||||||||||||||||||||||||
| exit 0 | ||||||||||||||||||||||||||||||
|
|
@@ -218,6 +224,90 @@ detect_os() { | |||||||||||||||||||||||||||||
| log_info "Detected OS: $OS_TYPE" | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| check_existing_installation() { | ||||||||||||||||||||||||||||||
| log_info "Checking for existing installation..." | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| local installation_found=false | ||||||||||||||||||||||||||||||
| local existing_containers=() | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Check if deployment directory exists with key files | ||||||||||||||||||||||||||||||
| if [[ -d "$DEPLOY_DIR" ]]; then | ||||||||||||||||||||||||||||||
| if [[ -f "$DEPLOY_DIR/docker-compose.yaml" ]] || [[ -f "$DEPLOY_DIR/.env" ]]; then | ||||||||||||||||||||||||||||||
| installation_found=true | ||||||||||||||||||||||||||||||
| log_warning "Found existing installation at: $DEPLOY_DIR" | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Check for running containers with our naming pattern | ||||||||||||||||||||||||||||||
| if command -v docker &> /dev/null; then | ||||||||||||||||||||||||||||||
| while IFS= read -r container; do | ||||||||||||||||||||||||||||||
| existing_containers+=("$container") | ||||||||||||||||||||||||||||||
| done < <(docker ps -a --filter "name=claude-code-hub-" --format "{{.Names}}" 2>/dev/null) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if [[ ${#existing_containers[@]} -gt 0 ]]; then | ||||||||||||||||||||||||||||||
| installation_found=true | ||||||||||||||||||||||||||||||
| log_warning "Found existing Docker containers:" | ||||||||||||||||||||||||||||||
| for container in "${existing_containers[@]}"; do | ||||||||||||||||||||||||||||||
| echo " - $container" | ||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # If installation found and not forcing reinstall, abort | ||||||||||||||||||||||||||||||
| if [[ "$installation_found" == true ]] && [[ "$FORCE_REINSTALL" != true ]]; then | ||||||||||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||||||||||
| log_error "Claude Code Hub is already installed on this system!" | ||||||||||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||||||||||
| echo -e "${YELLOW}To manage your existing installation:${NC}" | ||||||||||||||||||||||||||||||
| echo -e " View logs: ${BLUE}cd $DEPLOY_DIR && docker compose logs -f${NC}" | ||||||||||||||||||||||||||||||
| echo -e " Stop: ${BLUE}cd $DEPLOY_DIR && docker compose down${NC}" | ||||||||||||||||||||||||||||||
| echo -e " Restart: ${BLUE}cd $DEPLOY_DIR && docker compose restart${NC}" | ||||||||||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||||||||||
| echo -e "${YELLOW}To completely remove and reinstall:${NC}" | ||||||||||||||||||||||||||||||
| echo -e " 1. Stop services: ${BLUE}cd $DEPLOY_DIR && docker compose down -v${NC}" | ||||||||||||||||||||||||||||||
| echo -e " 2. Remove directory: ${BLUE}rm -rf $DEPLOY_DIR${NC}" | ||||||||||||||||||||||||||||||
| echo -e " 3. Re-run this script" | ||||||||||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||||||||||
| echo -e "${YELLOW}Or use the --force flag to automatically remove and reinstall:${NC}" | ||||||||||||||||||||||||||||||
| echo -e " ${BLUE}$0 --force${NC}" | ||||||||||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # If forcing reinstall, clean up existing installation | ||||||||||||||||||||||||||||||
| if [[ "$installation_found" == true ]] && [[ "$FORCE_REINSTALL" == true ]]; then | ||||||||||||||||||||||||||||||
| log_warning "Force reinstall enabled. Removing existing installation..." | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Stop and remove containers | ||||||||||||||||||||||||||||||
| if [[ ${#existing_containers[@]} -gt 0 ]]; then | ||||||||||||||||||||||||||||||
| log_info "Stopping and removing existing containers..." | ||||||||||||||||||||||||||||||
| if [[ -d "$DEPLOY_DIR" ]] && [[ -f "$DEPLOY_DIR/docker-compose.yaml" ]]; then | ||||||||||||||||||||||||||||||
| cd "$DEPLOY_DIR" | ||||||||||||||||||||||||||||||
| if docker compose version &> /dev/null; then | ||||||||||||||||||||||||||||||
| docker compose down -v 2>/dev/null || true | ||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||
| docker-compose down -v 2>/dev/null || true | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
|
Comment on lines
+285
to
+290
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
建议使用子 shell (subshell)
Suggested change
|
||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Force remove any remaining containers | ||||||||||||||||||||||||||||||
| for container in "${existing_containers[@]}"; do | ||||||||||||||||||||||||||||||
| docker rm -f "$container" 2>/dev/null || true | ||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
|
Comment on lines
+277
to
+297
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 数据丢失风险:
建议:在非交互模式下添加额外确认,或至少在帮助信息中明确警告数据会被删除。 🔧 建议的改进方案 # If forcing reinstall, clean up existing installation
if [[ "$installation_found" == true ]] && [[ "$FORCE_REINSTALL" == true ]]; then
+ if [[ "$NON_INTERACTIVE" != true ]]; then
+ echo ""
+ log_warning "This will DELETE all existing data including the database!"
+ read -p "Are you sure you want to continue? [y/N]: " confirm
+ if [[ "$confirm" != "y" ]] && [[ "$confirm" != "Y" ]]; then
+ log_info "Aborted by user."
+ exit 0
+ fi
+ else
+ log_warning "Force reinstall in non-interactive mode - all existing data will be deleted!"
+ fi
log_warning "Force reinstall enabled. Removing existing installation..."🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Remove deployment directory | ||||||||||||||||||||||||||||||
| if [[ -d "$DEPLOY_DIR" ]]; then | ||||||||||||||||||||||||||||||
| log_info "Removing deployment directory: $DEPLOY_DIR" | ||||||||||||||||||||||||||||||
| rm -rf "$DEPLOY_DIR" | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
|
Comment on lines
+278
to
+303
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Issue: Lines 300-302 delete Fix: Before removing the directory, backup existing credentials from the |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| log_success "Existing installation removed successfully" | ||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||
| log_success "No existing installation found. Proceeding with fresh installation..." | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| select_branch() { | ||||||||||||||||||||||||||||||
| # Skip if branch already set via CLI or non-interactive mode | ||||||||||||||||||||||||||||||
| if [[ -n "$BRANCH_ARG" ]]; then | ||||||||||||||||||||||||||||||
|
|
@@ -748,10 +838,13 @@ main() { | |||||||||||||||||||||||||||||
| print_header | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| detect_os | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Apply CLI overrides after OS detection (for deploy dir) | ||||||||||||||||||||||||||||||
| validate_inputs | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Check for existing installation before proceeding | ||||||||||||||||||||||||||||||
| check_existing_installation | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if ! check_docker; then | ||||||||||||||||||||||||||||||
| log_warning "Docker is not installed. Attempting to install..." | ||||||||||||||||||||||||||||||
| install_docker | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
当前的说明文字有些冗长,并且将操作指引和实现细节的备注混合在了一起,可能会让用户困惑。
建议将更新操作的指引和脚本幂等性的状态说明分开,使信息更清晰。同时,更新说明中引用的章节可以更精确地指向包含升级指南的
部署指南章节,而不是Docker Compose 启动章节。