Refactor docker-compose config for simplicity and consistency

This commit is contained in:
hkfires
2025-09-07 11:35:54 +08:00
parent 47b5ebfc43
commit 5aba4ca1b1
7 changed files with 49 additions and 47 deletions

View File

@@ -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. 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): - For Windows (PowerShell):
```powershell ```powershell
.\docker-build.ps1 .\docker-build.ps1
@@ -514,9 +514,9 @@ docker run --rm -p 8317:8317 -v /path/to/your/config.yaml:/CLIProxyAPI/config.ya
```bash ```bash
bash docker-build.sh bash docker-build.sh
``` ```
The script will prompt you to choose an environment: The script will prompt you to choose how to run the application:
- **Option 1: Local Development**: Builds the Docker image from the source and starts the services. - **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: Remote Deployment**: Pulls the pre-built image specified in `docker-compose.remote.yml` and starts the services. - **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: 4. To authenticate with providers, run the login command inside the container:
- **Gemini**: `docker compose exec cli-proxy-api /CLIProxyAPI/CLIProxyAPI -no-browser --login` - **Gemini**: `docker compose exec cli-proxy-api /CLIProxyAPI/CLIProxyAPI -no-browser --login`

View File

@@ -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` 文件并进行自定义。 2. 从 `config.example.yaml` 创建一个 `config.yaml` 文件并进行自定义。
3. 使用交互式构建脚本构建并启动服务: 3. 运行交互式脚本以启动服务:
- Windows (PowerShell): - Windows (PowerShell):
```powershell ```powershell
.\docker-build.ps1 .\docker-build.ps1
@@ -529,9 +529,9 @@ docker run --rm -p 8317:8317 -v /path/to/your/config.yaml:/CLIProxyAPI/config.ya
```bash ```bash
bash docker-build.sh bash docker-build.sh
``` ```
脚本将提示您选择一个环境 脚本将提示您选择运行方式
- **选项 1本地开发 (Local Development)**:从源代码构建 Docker 镜像并启动服务 - **选项 1使用预构建的镜像运行 (推荐)**:从镜像仓库拉取最新的官方镜像并启动容器。这是最简单的开始方式
- **选项 2远程部署 (Remote Deployment)**:拉取 `docker-compose.remote.yml` 中指定的预构建镜像并启动服务 - **选项 2从源码构建并运行 (适用于开发者)**:从本地源代码构建镜像,将其标记为 `cli-proxy-api:local`,然后启动容器。如果您需要修改源代码,此选项很有用
4. 要在容器内运行登录命令进行身份验证: 4. 要在容器内运行登录命令进行身份验证:
- **Gemini**: `docker compose exec cli-proxy-api /CLIProxyAPI/CLIProxyAPI -no-browser --login` - **Gemini**: `docker compose exec cli-proxy-api /CLIProxyAPI/CLIProxyAPI -no-browser --login`

View File

@@ -7,15 +7,21 @@
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
# --- Step 1: Choose Environment --- # --- Step 1: Choose Environment ---
Write-Host "Please select your environment:" Write-Host "Please select an option:"
Write-Host "1) Local Development (Build and Run)" Write-Host "1) Run using Pre-built Image (Recommended)"
Write-Host "2) Remote Deployment (Run from Image)" Write-Host "2) Build from Source and Run (For Developers)"
$choice = Read-Host -Prompt "Enter choice [1-2]" $choice = Read-Host -Prompt "Enter choice [1-2]"
# --- Step 2: Execute based on choice --- # --- Step 2: Execute based on choice ---
switch ($choice) { switch ($choice) {
"1" { "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 # Get Version Information
$VERSION = (git describe --tags --always --dirty) $VERSION = (git describe --tags --always --dirty)
@@ -28,21 +34,18 @@ switch ($choice) {
Write-Host " Build Date: $BUILD_DATE" Write-Host " Build Date: $BUILD_DATE"
Write-Host "----------------------------------------" 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 docker compose build --build-arg VERSION=$VERSION --build-arg COMMIT=$COMMIT --build-arg BUILD_DATE=$BUILD_DATE
# Start the Services Write-Host "Starting the services..."
docker compose up -d --remove-orphans docker compose up -d --remove-orphans --pull never
Write-Host "Build complete. Services are starting." Write-Host "Build complete. Services are starting."
Write-Host "Run 'docker compose logs -f' to see the logs." 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 { default {
Write-Host "Invalid choice. Please enter 1 or 2." Write-Host "Invalid choice. Please enter 1 or 2."
exit 1 exit 1

View File

@@ -9,15 +9,21 @@
set -euo pipefail set -euo pipefail
# --- Step 1: Choose Environment --- # --- Step 1: Choose Environment ---
echo "Please select your environment:" echo "Please select an option:"
echo "1) Local Development (Build and Run)" echo "1) Run using Pre-built Image (Recommended)"
echo "2) Remote Deployment (Run from Image)" echo "2) Build from Source and Run (For Developers)"
read -r -p "Enter choice [1-2]: " choice read -r -p "Enter choice [1-2]: " choice
# --- Step 2: Execute based on choice --- # --- Step 2: Execute based on choice ---
case "$choice" in case "$choice" in
1) 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 # Get Version Information
VERSION="$(git describe --tags --always --dirty)" VERSION="$(git describe --tags --always --dirty)"
@@ -30,24 +36,21 @@ case "$choice" in
echo " Build Date: ${BUILD_DATE}" echo " Build Date: ${BUILD_DATE}"
echo "----------------------------------------" 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 \ docker compose build \
--build-arg VERSION="${VERSION}" \ --build-arg VERSION="${VERSION}" \
--build-arg COMMIT="${COMMIT}" \ --build-arg COMMIT="${COMMIT}" \
--build-arg BUILD_DATE="${BUILD_DATE}" --build-arg BUILD_DATE="${BUILD_DATE}"
# Start the Services echo "Starting the services..."
docker compose up -d --remove-orphans docker compose up -d --remove-orphans --pull never
echo "Build complete. Services are starting." echo "Build complete. Services are starting."
echo "Run 'docker compose logs -f' to see the logs." 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." echo "Invalid choice. Please enter 1 or 2."
exit 1 exit 1

View File

@@ -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}

View File

@@ -1,3 +0,0 @@
services:
cli-proxy-api:
image: eceasy/cli-proxy-api:latest

View File

@@ -1,5 +1,14 @@
services: services:
cli-proxy-api: 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 container_name: cli-proxy-api
ports: ports:
- "8317:8317" - "8317:8317"