From 5aba4ca1b129067defd20ffc5ab934764a8a3498 Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Sun, 7 Sep 2025 11:35:54 +0800 Subject: [PATCH] Refactor docker-compose config for simplicity and consistency --- README.md | 8 ++++---- README_CN.md | 8 ++++---- docker-build.ps1 | 29 ++++++++++++++++------------- docker-build.sh | 29 ++++++++++++++++------------- docker-compose.override.yml | 10 ---------- docker-compose.remote.yml | 3 --- docker-compose.yml | 9 +++++++++ 7 files changed, 49 insertions(+), 47 deletions(-) delete mode 100644 docker-compose.override.yml delete mode 100644 docker-compose.remote.yml diff --git a/README.md b/README.md index 779291c6..5aadbd24 100644 --- a/README.md +++ b/README.md @@ -505,7 +505,7 @@ docker run --rm -p 8317:8317 -v /path/to/your/config.yaml:/CLIProxyAPI/config.ya 2. Create a `config.yaml` from `config.example.yaml` and customize it. -3. Build and start the services using the interactive build scripts: +3. Run the interactive script to start the service: - For Windows (PowerShell): ```powershell .\docker-build.ps1 @@ -514,9 +514,9 @@ docker run --rm -p 8317:8317 -v /path/to/your/config.yaml:/CLIProxyAPI/config.ya ```bash bash docker-build.sh ``` - The script will prompt you to choose an environment: - - **Option 1: Local Development**: Builds the Docker image from the source and starts the services. - - **Option 2: Remote Deployment**: Pulls the pre-built image specified in `docker-compose.remote.yml` and starts the services. + The script will prompt you to choose how to run the application: + - **Option 1: Run using Pre-built Image (Recommended)**: Pulls the latest official image from the registry and starts the container. This is the easiest way to get started. + - **Option 2: Build from Source and Run (For Developers)**: Builds the image from the local source code, tags it as `cli-proxy-api:local`, and then starts the container. This is useful if you are making changes to the source code. 4. To authenticate with providers, run the login command inside the container: - **Gemini**: `docker compose exec cli-proxy-api /CLIProxyAPI/CLIProxyAPI -no-browser --login` diff --git a/README_CN.md b/README_CN.md index 2ec62dac..59461d02 100644 --- a/README_CN.md +++ b/README_CN.md @@ -520,7 +520,7 @@ docker run --rm -p 8317:8317 -v /path/to/your/config.yaml:/CLIProxyAPI/config.ya 2. 从 `config.example.yaml` 创建一个 `config.yaml` 文件并进行自定义。 -3. 使用交互式构建脚本构建并启动服务: +3. 运行交互式脚本以启动服务: - Windows (PowerShell): ```powershell .\docker-build.ps1 @@ -529,9 +529,9 @@ docker run --rm -p 8317:8317 -v /path/to/your/config.yaml:/CLIProxyAPI/config.ya ```bash bash docker-build.sh ``` - 脚本将提示您选择一个环境: - - **选项 1:本地开发 (Local Development)**:从源代码构建 Docker 镜像并启动服务。 - - **选项 2:远程部署 (Remote Deployment)**:拉取 `docker-compose.remote.yml` 中指定的预构建镜像并启动服务。 + 脚本将提示您选择运行方式: + - **选项 1:使用预构建的镜像运行 (推荐)**:从镜像仓库拉取最新的官方镜像并启动容器。这是最简单的开始方式。 + - **选项 2:从源码构建并运行 (适用于开发者)**:从本地源代码构建镜像,将其标记为 `cli-proxy-api:local`,然后启动容器。如果您需要修改源代码,此选项很有用。 4. 要在容器内运行登录命令进行身份验证: - **Gemini**: `docker compose exec cli-proxy-api /CLIProxyAPI/CLIProxyAPI -no-browser --login` diff --git a/docker-build.ps1 b/docker-build.ps1 index 6f479bb0..d42a0d04 100644 --- a/docker-build.ps1 +++ b/docker-build.ps1 @@ -7,15 +7,21 @@ $ErrorActionPreference = "Stop" # --- Step 1: Choose Environment --- -Write-Host "Please select your environment:" -Write-Host "1) Local Development (Build and Run)" -Write-Host "2) Remote Deployment (Run from Image)" +Write-Host "Please select an option:" +Write-Host "1) Run using Pre-built Image (Recommended)" +Write-Host "2) Build from Source and Run (For Developers)" $choice = Read-Host -Prompt "Enter choice [1-2]" # --- Step 2: Execute based on choice --- switch ($choice) { "1" { - Write-Host "--- Starting Local Development Environment ---" + Write-Host "--- Running with Pre-built Image ---" + docker compose up -d --remove-orphans --no-build + Write-Host "Services are starting from remote image." + Write-Host "Run 'docker compose logs -f' to see the logs." + } + "2" { + Write-Host "--- Building from Source and Running ---" # Get Version Information $VERSION = (git describe --tags --always --dirty) @@ -28,21 +34,18 @@ switch ($choice) { Write-Host " Build Date: $BUILD_DATE" Write-Host "----------------------------------------" - # Build the Docker Image + # Build and start the services with a local-only image tag + $env:CLI_PROXY_IMAGE = "cli-proxy-api:local" + + Write-Host "Building the Docker image..." docker compose build --build-arg VERSION=$VERSION --build-arg COMMIT=$COMMIT --build-arg BUILD_DATE=$BUILD_DATE - # Start the Services - docker compose up -d --remove-orphans + Write-Host "Starting the services..." + docker compose up -d --remove-orphans --pull never Write-Host "Build complete. Services are starting." Write-Host "Run 'docker compose logs -f' to see the logs." } - "2" { - Write-Host "--- Starting Remote Deployment Environment ---" - docker compose -f docker-compose.yml -f docker-compose.remote.yml up -d - Write-Host "Services are starting from remote image." - Write-Host "Run 'docker compose logs -f' to see the logs." - } default { Write-Host "Invalid choice. Please enter 1 or 2." exit 1 diff --git a/docker-build.sh b/docker-build.sh index 79067f13..edfd5ead 100644 --- a/docker-build.sh +++ b/docker-build.sh @@ -9,15 +9,21 @@ set -euo pipefail # --- Step 1: Choose Environment --- -echo "Please select your environment:" -echo "1) Local Development (Build and Run)" -echo "2) Remote Deployment (Run from Image)" +echo "Please select an option:" +echo "1) Run using Pre-built Image (Recommended)" +echo "2) Build from Source and Run (For Developers)" read -r -p "Enter choice [1-2]: " choice # --- Step 2: Execute based on choice --- case "$choice" in 1) - echo "--- Starting Local Development Environment ---" + echo "--- Running with Pre-built Image ---" + docker compose up -d --remove-orphans --no-build + echo "Services are starting from remote image." + echo "Run 'docker compose logs -f' to see the logs." + ;; + 2) + echo "--- Building from Source and Running ---" # Get Version Information VERSION="$(git describe --tags --always --dirty)" @@ -30,24 +36,21 @@ case "$choice" in echo " Build Date: ${BUILD_DATE}" echo "----------------------------------------" - # Build the Docker Image + # Build and start the services with a local-only image tag + export CLI_PROXY_IMAGE="cli-proxy-api:local" + + echo "Building the Docker image..." docker compose build \ --build-arg VERSION="${VERSION}" \ --build-arg COMMIT="${COMMIT}" \ --build-arg BUILD_DATE="${BUILD_DATE}" - # Start the Services - docker compose up -d --remove-orphans + echo "Starting the services..." + docker compose up -d --remove-orphans --pull never echo "Build complete. Services are starting." echo "Run 'docker compose logs -f' to see the logs." ;; - 2) - echo "--- Starting Remote Deployment Environment ---" - docker compose -f docker-compose.yml -f docker-compose.remote.yml up -d - echo "Services are starting from remote image." - echo "Run 'docker compose logs -f' to see the logs." - ;; *) echo "Invalid choice. Please enter 1 or 2." exit 1 diff --git a/docker-compose.override.yml b/docker-compose.override.yml deleted file mode 100644 index c99e9090..00000000 --- a/docker-compose.override.yml +++ /dev/null @@ -1,10 +0,0 @@ -services: - cli-proxy-api: - image: cli-proxy-api:latest - build: - context: . - dockerfile: Dockerfile - args: - VERSION: ${VERSION:-dev} - COMMIT: ${COMMIT:-none} - BUILD_DATE: ${BUILD_DATE:-unknown} \ No newline at end of file diff --git a/docker-compose.remote.yml b/docker-compose.remote.yml deleted file mode 100644 index 143d552b..00000000 --- a/docker-compose.remote.yml +++ /dev/null @@ -1,3 +0,0 @@ -services: - cli-proxy-api: - image: eceasy/cli-proxy-api:latest \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index f3a56534..7984eaae 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,14 @@ services: cli-proxy-api: + image: ${CLI_PROXY_IMAGE:-eceasy/cli-proxy-api:latest} + pull_policy: always + build: + context: . + dockerfile: Dockerfile + args: + VERSION: ${VERSION:-dev} + COMMIT: ${COMMIT:-none} + BUILD_DATE: ${BUILD_DATE:-unknown} container_name: cli-proxy-api ports: - "8317:8317"