chore: use 1panel docker-compose config as default
- Replace docker-compose.yml with docker-compose.1panel.yml content - Better compatibility with 1Panel environment - Simplify future updates and maintenance Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,22 +1,24 @@
|
|||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Sub2API Docker Compose Configuration
|
# TianShuAPI Docker Compose - 1Panel 环境配置
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Quick Start:
|
# 此配置文件适用于已有 1Panel 环境,复用现有 Redis
|
||||||
# 1. Copy .env.example to .env and configure
|
|
||||||
# 2. docker-compose up -d
|
|
||||||
# 3. Check logs: docker-compose logs -f sub2api
|
|
||||||
# 4. Access: http://localhost:8080
|
|
||||||
#
|
|
||||||
# All configuration is done via environment variables.
|
|
||||||
# No Setup Wizard needed - the system auto-initializes on first run.
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
|
|
||||||
services:
|
services:
|
||||||
# ===========================================================================
|
# ===========================================================================
|
||||||
# Sub2API Application
|
# TianShuAPI Application
|
||||||
# ===========================================================================
|
# ===========================================================================
|
||||||
sub2api:
|
sub2api:
|
||||||
image: weishaw/sub2api:latest
|
# 方式1:使用官方镜像(快速部署)
|
||||||
|
# image: weishaw/sub2api:latest
|
||||||
|
|
||||||
|
# 方式2:从本地代码构建(二次开发)
|
||||||
|
build:
|
||||||
|
context: ../
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
args:
|
||||||
|
- BUILD_TAGS=embed
|
||||||
|
image: sub2api:local
|
||||||
container_name: sub2api
|
container_name: sub2api
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ulimits:
|
ulimits:
|
||||||
@@ -26,28 +28,18 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "${BIND_HOST:-0.0.0.0}:${SERVER_PORT:-8080}:8080"
|
- "${BIND_HOST:-0.0.0.0}:${SERVER_PORT:-8080}:8080"
|
||||||
volumes:
|
volumes:
|
||||||
# Data persistence (config.yaml will be auto-generated here)
|
|
||||||
- sub2api_data:/app/data
|
- sub2api_data:/app/data
|
||||||
# Optional: Mount custom config.yaml (uncomment and create the file first)
|
|
||||||
# Copy config.example.yaml to config.yaml, modify it, then uncomment:
|
|
||||||
# - ./config.yaml:/app/data/config.yaml:ro
|
|
||||||
environment:
|
environment:
|
||||||
# =======================================================================
|
# Auto Setup
|
||||||
# Auto Setup (REQUIRED for Docker deployment)
|
|
||||||
# =======================================================================
|
|
||||||
- AUTO_SETUP=true
|
- AUTO_SETUP=true
|
||||||
|
|
||||||
# =======================================================================
|
|
||||||
# Server Configuration
|
# Server Configuration
|
||||||
# =======================================================================
|
|
||||||
- SERVER_HOST=0.0.0.0
|
- SERVER_HOST=0.0.0.0
|
||||||
- SERVER_PORT=8080
|
- SERVER_PORT=8080
|
||||||
- SERVER_MODE=${SERVER_MODE:-release}
|
- SERVER_MODE=${SERVER_MODE:-release}
|
||||||
- RUN_MODE=${RUN_MODE:-standard}
|
- RUN_MODE=${RUN_MODE:-standard}
|
||||||
|
|
||||||
# =======================================================================
|
# Database Configuration
|
||||||
# Database Configuration (PostgreSQL)
|
|
||||||
# =======================================================================
|
|
||||||
- DATABASE_HOST=postgres
|
- DATABASE_HOST=postgres
|
||||||
- DATABASE_PORT=5432
|
- DATABASE_PORT=5432
|
||||||
- DATABASE_USER=${POSTGRES_USER:-sub2api}
|
- DATABASE_USER=${POSTGRES_USER:-sub2api}
|
||||||
@@ -55,74 +47,36 @@ services:
|
|||||||
- DATABASE_DBNAME=${POSTGRES_DB:-sub2api}
|
- DATABASE_DBNAME=${POSTGRES_DB:-sub2api}
|
||||||
- DATABASE_SSLMODE=disable
|
- DATABASE_SSLMODE=disable
|
||||||
|
|
||||||
# =======================================================================
|
# Redis Configuration - 使用外部 Redis
|
||||||
# Redis Configuration
|
- REDIS_HOST=${REDIS_HOST}
|
||||||
# =======================================================================
|
- REDIS_PORT=${REDIS_PORT:-6379}
|
||||||
- REDIS_HOST=redis
|
- REDIS_PASSWORD=${REDIS_PASSWORD}
|
||||||
- REDIS_PORT=6379
|
|
||||||
- REDIS_PASSWORD=${REDIS_PASSWORD:-}
|
|
||||||
- REDIS_DB=${REDIS_DB:-0}
|
- REDIS_DB=${REDIS_DB:-0}
|
||||||
|
|
||||||
# =======================================================================
|
# Admin Account
|
||||||
# Admin Account (auto-created on first run)
|
|
||||||
# =======================================================================
|
|
||||||
- ADMIN_EMAIL=${ADMIN_EMAIL:-admin@sub2api.local}
|
- ADMIN_EMAIL=${ADMIN_EMAIL:-admin@sub2api.local}
|
||||||
- ADMIN_PASSWORD=${ADMIN_PASSWORD:-}
|
- ADMIN_PASSWORD=${ADMIN_PASSWORD:-}
|
||||||
|
|
||||||
# =======================================================================
|
|
||||||
# JWT Configuration
|
# JWT Configuration
|
||||||
# =======================================================================
|
|
||||||
# IMPORTANT: Set a fixed JWT_SECRET to prevent login sessions from being
|
|
||||||
# invalidated after container restarts. If left empty, a random secret
|
|
||||||
# will be generated on each startup.
|
|
||||||
# Generate a secure secret: openssl rand -hex 32
|
|
||||||
- JWT_SECRET=${JWT_SECRET:-}
|
- JWT_SECRET=${JWT_SECRET:-}
|
||||||
- JWT_EXPIRE_HOUR=${JWT_EXPIRE_HOUR:-24}
|
- JWT_EXPIRE_HOUR=${JWT_EXPIRE_HOUR:-24}
|
||||||
|
|
||||||
# =======================================================================
|
# Timezone
|
||||||
# Timezone Configuration
|
|
||||||
# This affects ALL time operations in the application:
|
|
||||||
# - Database timestamps
|
|
||||||
# - Usage statistics "today" boundary
|
|
||||||
# - Subscription expiry times
|
|
||||||
# - Log timestamps
|
|
||||||
# Common values: Asia/Shanghai, America/New_York, Europe/London, UTC
|
|
||||||
# =======================================================================
|
|
||||||
- TZ=${TZ:-Asia/Shanghai}
|
- TZ=${TZ:-Asia/Shanghai}
|
||||||
|
|
||||||
# =======================================================================
|
# Gemini OAuth (可选)
|
||||||
# Gemini OAuth Configuration (for Gemini accounts)
|
|
||||||
# =======================================================================
|
|
||||||
- GEMINI_OAUTH_CLIENT_ID=${GEMINI_OAUTH_CLIENT_ID:-}
|
- GEMINI_OAUTH_CLIENT_ID=${GEMINI_OAUTH_CLIENT_ID:-}
|
||||||
- GEMINI_OAUTH_CLIENT_SECRET=${GEMINI_OAUTH_CLIENT_SECRET:-}
|
- GEMINI_OAUTH_CLIENT_SECRET=${GEMINI_OAUTH_CLIENT_SECRET:-}
|
||||||
- GEMINI_OAUTH_SCOPES=${GEMINI_OAUTH_SCOPES:-}
|
- GEMINI_OAUTH_SCOPES=${GEMINI_OAUTH_SCOPES:-}
|
||||||
- GEMINI_QUOTA_POLICY=${GEMINI_QUOTA_POLICY:-}
|
- GEMINI_QUOTA_POLICY=${GEMINI_QUOTA_POLICY:-}
|
||||||
|
|
||||||
# =======================================================================
|
|
||||||
# Security Configuration (URL Allowlist)
|
|
||||||
# =======================================================================
|
|
||||||
# Enable URL allowlist validation (false to skip allowlist checks)
|
|
||||||
- SECURITY_URL_ALLOWLIST_ENABLED=${SECURITY_URL_ALLOWLIST_ENABLED:-false}
|
|
||||||
# Allow insecure HTTP URLs when allowlist is disabled (default: false, requires https)
|
|
||||||
- SECURITY_URL_ALLOWLIST_ALLOW_INSECURE_HTTP=${SECURITY_URL_ALLOWLIST_ALLOW_INSECURE_HTTP:-false}
|
|
||||||
# Allow private IP addresses for upstream/pricing/CRS (for internal deployments)
|
|
||||||
- SECURITY_URL_ALLOWLIST_ALLOW_PRIVATE_HOSTS=${SECURITY_URL_ALLOWLIST_ALLOW_PRIVATE_HOSTS:-false}
|
|
||||||
# Upstream hosts whitelist (comma-separated, only used when enabled=true)
|
|
||||||
- SECURITY_URL_ALLOWLIST_UPSTREAM_HOSTS=${SECURITY_URL_ALLOWLIST_UPSTREAM_HOSTS:-}
|
|
||||||
|
|
||||||
# =======================================================================
|
|
||||||
# Update Configuration (在线更新配置)
|
|
||||||
# =======================================================================
|
|
||||||
# Proxy for accessing GitHub (online updates + pricing data)
|
|
||||||
# Examples: http://host:port, socks5://host:port
|
|
||||||
- UPDATE_PROXY_URL=${UPDATE_PROXY_URL:-}
|
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
postgres:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
redis:
|
extra_hosts:
|
||||||
condition: service_healthy
|
- "host.docker.internal:host-gateway"
|
||||||
networks:
|
networks:
|
||||||
- sub2api-network
|
- sub2api-network
|
||||||
|
- 1panel-network
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
|
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
|
||||||
interval: 30s
|
interval: 30s
|
||||||
@@ -156,41 +110,6 @@ services:
|
|||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
start_period: 10s
|
start_period: 10s
|
||||||
# 注意:不暴露端口到宿主机,应用通过内部网络连接
|
|
||||||
# 如需调试,可临时添加:ports: ["127.0.0.1:5433:5432"]
|
|
||||||
|
|
||||||
# ===========================================================================
|
|
||||||
# Redis Cache
|
|
||||||
# ===========================================================================
|
|
||||||
redis:
|
|
||||||
image: redis:8-alpine
|
|
||||||
container_name: sub2api-redis
|
|
||||||
restart: unless-stopped
|
|
||||||
ulimits:
|
|
||||||
nofile:
|
|
||||||
soft: 100000
|
|
||||||
hard: 100000
|
|
||||||
volumes:
|
|
||||||
- redis_data:/data
|
|
||||||
command: >
|
|
||||||
sh -c '
|
|
||||||
redis-server
|
|
||||||
--save 60 1
|
|
||||||
--appendonly yes
|
|
||||||
--appendfsync everysec
|
|
||||||
${REDIS_PASSWORD:+--requirepass "$REDIS_PASSWORD"}'
|
|
||||||
environment:
|
|
||||||
- TZ=${TZ:-Asia/Shanghai}
|
|
||||||
# REDISCLI_AUTH is used by redis-cli for authentication (safer than -a flag)
|
|
||||||
- REDISCLI_AUTH=${REDIS_PASSWORD:-}
|
|
||||||
networks:
|
|
||||||
- sub2api-network
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD", "redis-cli", "ping"]
|
|
||||||
interval: 10s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 5
|
|
||||||
start_period: 5s
|
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Volumes
|
# Volumes
|
||||||
@@ -200,8 +119,6 @@ volumes:
|
|||||||
driver: local
|
driver: local
|
||||||
postgres_data:
|
postgres_data:
|
||||||
driver: local
|
driver: local
|
||||||
redis_data:
|
|
||||||
driver: local
|
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Networks
|
# Networks
|
||||||
@@ -209,3 +126,5 @@ volumes:
|
|||||||
networks:
|
networks:
|
||||||
sub2api-network:
|
sub2api-network:
|
||||||
driver: bridge
|
driver: bridge
|
||||||
|
1panel-network:
|
||||||
|
external: true
|
||||||
|
|||||||
Reference in New Issue
Block a user