|
2 | 2 |
|
3 | 3 | **Convert GeminiCLI to OpenAI and GEMINI API interfaces**
|
4 | 4 |
|
5 |
| ---- |
| 5 | +[中文](../README.md) | English |
| 6 | + |
| 7 | +## 🚀 Quick Deploy |
6 | 8 |
|
7 |
| -[](https://zeabur.com/templates/FIBY1S?referralCode=su-kaka) |
| 9 | +[](https://zeabur.com/templates/2QLQC2?referralCode=su-kaka) |
| 10 | +--- |
8 | 11 |
|
9 | 12 | ## ⚠️ License Declaration
|
10 | 13 |
|
@@ -287,6 +290,173 @@ docker run -d --name gcli2api --network host -e API_PASSWORD=api_pwd -e PANEL_PA
|
287 | 290 | - `x-goog-api-key: your_api_password`
|
288 | 291 | - URL parameter: `?key=your_api_password`
|
289 | 292 |
|
| 293 | +## 💾 Distributed Storage Mode |
| 294 | + |
| 295 | +### 🌟 Storage Backend Priority |
| 296 | + |
| 297 | +gcli2api supports multiple storage backends, automatically selecting by priority: **Redis > MongoDB > Local Files** |
| 298 | + |
| 299 | +### ⚡ Redis Distributed Storage Mode |
| 300 | + |
| 301 | +### ⚙️ Enable Redis Mode |
| 302 | + |
| 303 | +**Step 1: Configure Redis Connection** |
| 304 | +```bash |
| 305 | +# Local Redis |
| 306 | +export REDIS_URI="redis://localhost:6379" |
| 307 | +
|
| 308 | +# Redis with password |
| 309 | +export REDIS_URI="redis://:password@localhost:6379" |
| 310 | +
|
| 311 | +# SSL connection (recommended for production) |
| 312 | +export REDIS_URI="rediss://default:password@host:6380" |
| 313 | +
|
| 314 | +# Upstash Redis (free cloud service) |
| 315 | +export REDIS_URI="rediss://default:token@your-host.upstash.io:6379" |
| 316 | +
|
| 317 | +# Optional: Custom database index (default: 0) |
| 318 | +export REDIS_DATABASE="1" |
| 319 | +``` |
| 320 | + |
| 321 | +**Step 2: Start Application** |
| 322 | +```bash |
| 323 | +# Application will automatically detect Redis configuration and prioritize Redis storage |
| 324 | +python web.py |
| 325 | +``` |
| 326 | + |
| 327 | +### 🍃 MongoDB Distributed Storage Mode |
| 328 | + |
| 329 | +### 🌟 Alternative Storage Solution |
| 330 | + |
| 331 | +If Redis is not configured, gcli2api will attempt to use **MongoDB storage mode**. |
| 332 | + |
| 333 | +### ⚙️ Enable MongoDB Mode |
| 334 | + |
| 335 | +**Step 1: Configure MongoDB Connection** |
| 336 | +```bash |
| 337 | +# Local MongoDB |
| 338 | +export MONGODB_URI="mongodb://localhost:27017" |
| 339 | +
|
| 340 | +# MongoDB Atlas cloud service |
| 341 | +export MONGODB_URI="mongodb+srv://username:password@cluster.mongodb.net" |
| 342 | +
|
| 343 | +# MongoDB with authentication |
| 344 | +export MONGODB_URI="mongodb://admin:password@localhost:27017/admin" |
| 345 | +
|
| 346 | +# Optional: Custom database name (default: gcli2api) |
| 347 | +export MONGODB_DATABASE="my_gcli_db" |
| 348 | +``` |
| 349 | + |
| 350 | +**Step 2: Start Application** |
| 351 | +```bash |
| 352 | +# Application will automatically detect MongoDB configuration and use MongoDB storage |
| 353 | +python web.py |
| 354 | +``` |
| 355 | + |
| 356 | +**Docker Environment using MongoDB** |
| 357 | +```bash |
| 358 | +# Single MongoDB deployment |
| 359 | +docker run -d --name gcli2api \ |
| 360 | + -e MONGODB_URI="mongodb://mongodb:27017" \ |
| 361 | + -e API_PASSWORD=your_password \ |
| 362 | + --network your_network \ |
| 363 | + ghcr.io/su-kaka/gcli2api:latest |
| 364 | +
|
| 365 | +# Using MongoDB Atlas |
| 366 | +docker run -d --name gcli2api \ |
| 367 | + -e MONGODB_URI="mongodb+srv://user:pass@cluster.mongodb.net/gcli2api" \ |
| 368 | + -e API_PASSWORD=your_password \ |
| 369 | + -p 7861:7861 \ |
| 370 | + ghcr.io/su-kaka/gcli2api:latest |
| 371 | +``` |
| 372 | + |
| 373 | +**Docker Compose Example** |
| 374 | +```yaml |
| 375 | +version: '3.8' |
| 376 | +
|
| 377 | +services: |
| 378 | + mongodb: |
| 379 | + image: mongo:7 |
| 380 | + container_name: gcli2api-mongodb |
| 381 | + restart: unless-stopped |
| 382 | + environment: |
| 383 | + MONGO_INITDB_ROOT_USERNAME: admin |
| 384 | + MONGO_INITDB_ROOT_PASSWORD: password123 |
| 385 | + volumes: |
| 386 | + - mongodb_data:/data/db |
| 387 | + ports: |
| 388 | + - "27017:27017" |
| 389 | +
|
| 390 | + gcli2api: |
| 391 | + image: ghcr.io/su-kaka/gcli2api:latest |
| 392 | + container_name: gcli2api |
| 393 | + restart: unless-stopped |
| 394 | + depends_on: |
| 395 | + - mongodb |
| 396 | + environment: |
| 397 | + - MONGODB_URI=mongodb://admin:password123@mongodb:27017/admin |
| 398 | + - MONGODB_DATABASE=gcli2api |
| 399 | + - API_PASSWORD=your_api_password |
| 400 | + - PORT=7861 |
| 401 | + ports: |
| 402 | + - "7861:7861" |
| 403 | +
|
| 404 | +volumes: |
| 405 | + mongodb_data: |
| 406 | +``` |
| 407 | + |
| 408 | +### 🛠️ Troubleshooting |
| 409 | + |
| 410 | +**Common Issue Solutions** |
| 411 | + |
| 412 | +```bash |
| 413 | +# Check MongoDB connection |
| 414 | +python mongodb_setup.py check |
| 415 | +
|
| 416 | +# View detailed status information |
| 417 | +python mongodb_setup.py status |
| 418 | +
|
| 419 | +# Verify data migration results |
| 420 | +python -c " |
| 421 | +import asyncio |
| 422 | +from src.storage_adapter import get_storage_adapter |
| 423 | +
|
| 424 | +async def test(): |
| 425 | + storage = await get_storage_adapter() |
| 426 | + info = await storage.get_backend_info() |
| 427 | + print(f'Current mode: {info[\"backend_type\"]}') |
| 428 | + if info['backend_type'] == 'mongodb': |
| 429 | + print(f'Database: {info.get(\"database_name\", \"Unknown\")}') |
| 430 | +
|
| 431 | +asyncio.run(test()) |
| 432 | +" |
| 433 | +``` |
| 434 | + |
| 435 | +**Migration Failure Handling** |
| 436 | +```bash |
| 437 | +# If migration is interrupted, re-run |
| 438 | +python mongodb_setup.py migrate |
| 439 | +
|
| 440 | +# To rollback to file mode, remove MONGODB_URI environment variable |
| 441 | +unset MONGODB_URI |
| 442 | +# Then export data from MongoDB |
| 443 | +python mongodb_setup.py export |
| 444 | +``` |
| 445 | + |
| 446 | +### 🔧 Advanced Configuration |
| 447 | + |
| 448 | +**MongoDB Connection Optimization** |
| 449 | +```bash |
| 450 | +# Connection pool and timeout configuration |
| 451 | +export MONGODB_URI="mongodb://localhost:27017?maxPoolSize=10&serverSelectionTimeoutMS=5000" |
| 452 | +
|
| 453 | +# Replica set configuration |
| 454 | +export MONGODB_URI="mongodb://host1:27017,host2:27017,host3:27017/gcli2api?replicaSet=myReplicaSet" |
| 455 | +
|
| 456 | +# Read-write separation configuration |
| 457 | +export MONGODB_URI="mongodb://localhost:27017/gcli2api?readPreference=secondaryPreferred" |
| 458 | +``` |
| 459 | + |
290 | 460 | ## 🏗️ Technical Architecture
|
291 | 461 |
|
292 | 462 | ### Core Module Description
|
@@ -378,6 +548,19 @@ docker run -d --name gcli2api --network host -e API_PASSWORD=api_pwd -e PANEL_PA
|
378 | 548 | - `LOG_LEVEL`: Log level (DEBUG/INFO/WARNING/ERROR, default: INFO)
|
379 | 549 | - `LOG_FILE`: Log file path (default: gcli2api.log)
|
380 | 550 |
|
| 551 | +**Storage Configuration (by priority)** |
| 552 | + |
| 553 | +**Redis Configuration (Highest Priority)** |
| 554 | +- `REDIS_URI`: Redis connection string (enables Redis mode when set) |
| 555 | + - Local: `redis://localhost:6379` |
| 556 | + - With password: `redis://:password@host:6379` |
| 557 | + - SSL: `rediss://default:password@host:6380` |
| 558 | +- `REDIS_DATABASE`: Redis database index (0-15, default: 0) |
| 559 | + |
| 560 | +**MongoDB Configuration (Second Priority)** |
| 561 | +- `MONGODB_URI`: MongoDB connection string (enables MongoDB mode when set) |
| 562 | +- `MONGODB_DATABASE`: MongoDB database name (default: gcli2api) |
| 563 | + |
381 | 564 | **Credential Configuration**
|
382 | 565 |
|
383 | 566 | Support importing multiple credentials using `GCLI_CREDS_*` environment variables:
|
|
0 commit comments