mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
Modify docker compose for remote image and local build
This commit is contained in:
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
# Docker and CI/CD related files
|
# Docker and CI/CD related files
|
||||||
docker-compose.yml
|
docker-compose.yml
|
||||||
|
docker-compose.override.yml
|
||||||
|
docker-compose.remote.yml
|
||||||
.dockerignore
|
.dockerignore
|
||||||
.gitignore
|
.gitignore
|
||||||
.goreleaser.yml
|
.goreleaser.yml
|
||||||
|
|||||||
@@ -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 build scripts:
|
3. Build and start the services using the interactive build scripts:
|
||||||
- For Windows (PowerShell):
|
- For Windows (PowerShell):
|
||||||
```powershell
|
```powershell
|
||||||
.\docker-build.ps1
|
.\docker-build.ps1
|
||||||
@@ -514,6 +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:
|
||||||
|
- **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.
|
||||||
|
|
||||||
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`
|
||||||
|
|||||||
@@ -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,6 +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 镜像并启动服务。
|
||||||
|
- **选项 2:远程部署 (Remote Deployment)**:拉取 `docker-compose.remote.yml` 中指定的预构建镜像并启动服务。
|
||||||
|
|
||||||
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`
|
||||||
|
|||||||
@@ -6,31 +6,45 @@
|
|||||||
# Stop script execution on any error
|
# Stop script execution on any error
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
# --- Step 1: Get Version Information ---
|
# --- Step 1: Choose Environment ---
|
||||||
# Get the latest git tag or commit hash as the version string.
|
Write-Host "Please select your environment:"
|
||||||
|
Write-Host "1) Local Development (Build and Run)"
|
||||||
|
Write-Host "2) Remote Deployment (Run from Image)"
|
||||||
|
$choice = Read-Host -Prompt "Enter choice [1-2]"
|
||||||
|
|
||||||
|
# --- Step 2: Execute based on choice ---
|
||||||
|
switch ($choice) {
|
||||||
|
"1" {
|
||||||
|
Write-Host "--- Starting Local Development Environment ---"
|
||||||
|
|
||||||
|
# Get Version Information
|
||||||
$VERSION = (git describe --tags --always --dirty)
|
$VERSION = (git describe --tags --always --dirty)
|
||||||
|
|
||||||
# Get the short commit hash.
|
|
||||||
$COMMIT = (git rev-parse --short HEAD)
|
$COMMIT = (git rev-parse --short HEAD)
|
||||||
|
|
||||||
# Get the current UTC date and time in ISO 8601 format.
|
|
||||||
$BUILD_DATE = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
|
$BUILD_DATE = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
|
||||||
|
|
||||||
Write-Host "--- Building with the following info ---"
|
Write-Host "Building with the following info:"
|
||||||
Write-Host " Version: $VERSION"
|
Write-Host " Version: $VERSION"
|
||||||
Write-Host " Commit: $COMMIT"
|
Write-Host " Commit: $COMMIT"
|
||||||
Write-Host " Build Date: $BUILD_DATE"
|
Write-Host " Build Date: $BUILD_DATE"
|
||||||
Write-Host "----------------------------------------"
|
Write-Host "----------------------------------------"
|
||||||
|
|
||||||
# --- Step 2: Build the Docker Image ---
|
# Build the Docker Image
|
||||||
# Pass the version information as build arguments to 'docker compose build'.
|
|
||||||
# These arguments are then used by the Dockerfile to inject them into the Go binary.
|
|
||||||
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
|
||||||
|
|
||||||
# --- Step 3: Start the Services ---
|
# Start the Services
|
||||||
# Start the services in detached mode using the newly built image.
|
|
||||||
# '--remove-orphans' cleans up any containers for services that are no longer defined.
|
|
||||||
docker compose up -d --remove-orphans
|
docker compose up -d --remove-orphans
|
||||||
|
|
||||||
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 {
|
||||||
|
Write-Host "Invalid choice. Please enter 1 or 2."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,34 +8,48 @@
|
|||||||
# Exit immediately if a command exits with a non-zero status.
|
# Exit immediately if a command exits with a non-zero status.
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# --- Step 1: Get Version Information ---
|
# --- Step 1: Choose Environment ---
|
||||||
# Get the latest git tag or commit hash as the version string.
|
echo "Please select your environment:"
|
||||||
|
echo "1) Local Development (Build and Run)"
|
||||||
|
echo "2) Remote Deployment (Run from Image)"
|
||||||
|
read -r -p "Enter choice [1-2]: " choice
|
||||||
|
|
||||||
|
# --- Step 2: Execute based on choice ---
|
||||||
|
case "$choice" in
|
||||||
|
1)
|
||||||
|
echo "--- Starting Local Development Environment ---"
|
||||||
|
|
||||||
|
# Get Version Information
|
||||||
VERSION="$(git describe --tags --always --dirty)"
|
VERSION="$(git describe --tags --always --dirty)"
|
||||||
|
|
||||||
# Get the short commit hash.
|
|
||||||
COMMIT="$(git rev-parse --short HEAD)"
|
COMMIT="$(git rev-parse --short HEAD)"
|
||||||
|
|
||||||
# Get the current UTC date and time in ISO 8601 format.
|
|
||||||
BUILD_DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
BUILD_DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
||||||
|
|
||||||
echo "--- Building with the following info ---"
|
echo "Building with the following info:"
|
||||||
echo " Version: ${VERSION}"
|
echo " Version: ${VERSION}"
|
||||||
echo " Commit: ${COMMIT}"
|
echo " Commit: ${COMMIT}"
|
||||||
echo " Build Date: ${BUILD_DATE}"
|
echo " Build Date: ${BUILD_DATE}"
|
||||||
echo "----------------------------------------"
|
echo "----------------------------------------"
|
||||||
|
|
||||||
# --- Step 2: Build the Docker Image ---
|
# Build the Docker Image
|
||||||
# Pass the version information as build arguments to 'docker compose build'.
|
|
||||||
# These arguments are then used by the Dockerfile to inject them into the Go binary.
|
|
||||||
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}"
|
||||||
|
|
||||||
# --- Step 3: Start the Services ---
|
# Start the Services
|
||||||
# Start the services in detached mode using the newly built image.
|
|
||||||
# '--remove-orphans' cleans up any containers for services that are no longer defined.
|
|
||||||
docker compose up -d --remove-orphans
|
docker compose up -d --remove-orphans
|
||||||
|
|
||||||
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."
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
10
docker-compose.override.yml
Normal file
10
docker-compose.override.yml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
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}
|
||||||
3
docker-compose.remote.yml
Normal file
3
docker-compose.remote.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
services:
|
||||||
|
cli-proxy-api:
|
||||||
|
image: eceasy/cli-proxy-api:latest
|
||||||
@@ -1,13 +1,5 @@
|
|||||||
services:
|
services:
|
||||||
cli-proxy-api:
|
cli-proxy-api:
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
args:
|
|
||||||
VERSION: ${VERSION:-dev}
|
|
||||||
COMMIT: ${COMMIT:-none}
|
|
||||||
BUILD_DATE: ${BUILD_DATE:-unknown}
|
|
||||||
image: cli-proxy-api:latest
|
|
||||||
container_name: cli-proxy-api
|
container_name: cli-proxy-api
|
||||||
ports:
|
ports:
|
||||||
- "8317:8317"
|
- "8317:8317"
|
||||||
|
|||||||
Reference in New Issue
Block a user