File size: 2,024 Bytes
954be92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# ========================================
# 汇率换算服务 Docker Compose 配置
# ========================================

version: "3.8"

services:
  # 汇率换算服务
  exchange-rates:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: exchange-rates
    restart: unless-stopped
    
    # 端口映射
    ports:
      - "${SERVER_PORT:-8000}:8000"
    
    # 环境变量配置
    environment:
      # API Keys - 多个 key 用逗号分隔
      - API_KEYS=${API_KEYS:-your_api_key_here}
      # 基准货币
      - BASE_CURRENCY=${BASE_CURRENCY:-CNY}
      # 缓存更新间隔(秒)
      - CACHE_UPDATE_INTERVAL=${CACHE_UPDATE_INTERVAL:-3600}
      # API 请求超时时间(秒)
      - REQUEST_TIMEOUT=${REQUEST_TIMEOUT:-10}
      # 最大重试次数
      - MAX_RETRIES=${MAX_RETRIES:-3}
      # 服务端口
      - SERVER_PORT=8000
      # 时区设置
      - TZ=Asia/Shanghai
    
    # 使用 .env 文件加载环境变量
    env_file:
      - .env
    
    # 健康检查
    healthcheck:
      test: ["CMD", "python", "-c", "import httpx; httpx.get('http://localhost:8000/health', timeout=5)"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s
    
    # 日志配置
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"
    
    # 资源限制(可选)
    deploy:
      resources:
        limits:
          cpus: "1.0"
          memory: 512M
        reservations:
          cpus: "0.25"
          memory: 128M

# ========================================
# 使用说明:
# ========================================
# 1. 确保已配置 .env 文件(参考 .env.example)
# 2. 构建并启动服务:
#    docker-compose up -d --build
# 3. 查看日志:
#    docker-compose logs -f
# 4. 停止服务:
#    docker-compose down
# 5. 访问服务:
#    - 首页: http://localhost:8000
#    - API 文档: http://localhost:8000/docs
# ========================================