oauth-db-cli 0.1.0

Command-line tool for managing OAuth-DB platform
Documentation
# OAuth-DB CLI E2E Test Environment
# 用途:CLI E2E 测试 + gsc-debugger 调试
# 特性:零源码容器(全部 volume 挂载)+ 用户视角仿真

version: "3.8"

services:
  # ============================================
  # PostgreSQL: 元数据存储
  # ============================================
  e2e-postgresql:
    image: postgres:15-alpine
    container_name: oauth-db-cli-e2e-postgresql
    environment:
      POSTGRES_DB: oauth_db
      POSTGRES_USER: oauth
      POSTGRES_PASSWORD: oauth123
      PGDATA: /var/lib/postgresql/data/pgdata
    ports:
      - "25432:5432"  # 避免与主环境冲突
    volumes:
      # 使用 tmpfs 实现测试数据隔离(容器销毁时自动清理)
      - type: tmpfs
        target: /var/lib/postgresql/data
      # 挂载迁移脚本(零源码原则)
      - ../apps/migrations:/docker-entrypoint-initdb.d:ro
    networks:
      - cli-e2e-net
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U oauth -d oauth_db"]
      interval: 5s
      timeout: 5s
      retries: 5
      start_period: 10s

  # ============================================
  # Redis: 缓存和限流
  # ============================================
  e2e-redis:
    image: redis:7-alpine
    container_name: oauth-db-cli-e2e-redis
    command: redis-server --appendonly no --save ""
    ports:
      - "26379:6379"
    networks:
      - cli-e2e-net
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 5

  # ============================================
  # SurrealDB: 用户数据存储
  # ============================================
  e2e-surrealdb:
    image: surrealdb/surrealdb:latest
    container_name: oauth-db-cli-e2e-surrealdb
    command: >
      start
      --log info
      --user root
      --pass root
      --bind 0.0.0.0:8000
    ports:
      - "28000:8000"
    volumes:
      # tmpfs 实现数据隔离
      - type: tmpfs
        target: /data
    networks:
      - cli-e2e-net

  # ============================================
  # OAuth-DB Backend: 后端服务
  # ============================================
  e2e-oauth-db:
    image: oauth-db:latest
    container_name: oauth-db-cli-e2e-backend
    environment:
      RUST_LOG: info
      RUST_BACKTRACE: 1
    ports:
      - "28080:8080"  # HTTP API
      - "25555:5555"  # gsc-debugger 端口
    volumes:
      # 零源码原则:挂载配置和密钥
      - ../config.e2e.yaml:/app/config.yaml:ro
      - ../keys:/app/keys:ro
    depends_on:
      e2e-postgresql:
        condition: service_healthy
      e2e-redis:
        condition: service_healthy
      e2e-surrealdb:
        condition: service_started
    networks:
      - cli-e2e-net
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s

  # ============================================
  # CLI Test Runner: CLI 测试容器
  # ============================================
  cli-test-runner:
    build:
      context: .
      dockerfile: Dockerfile.e2e
    container_name: oauth-db-cli-test-runner
    environment:
      # 测试环境变量
      OAUTH_DB_SERVER: "http://e2e-oauth-db:8080"
      RUST_LOG: debug
      RUST_BACKTRACE: 1
      # 禁用交互式输入
      CI: "true"
    volumes:
      # 零源码原则:挂载源代码和测试
      - ./src:/workspace/src:ro
      - ./tests:/workspace/tests:ro
      - ./Cargo.toml:/workspace/Cargo.toml:ro
      - ../Cargo.toml:/workspace-root/Cargo.toml:ro
      - ../Cargo.lock:/workspace-root/Cargo.lock:ro
      # 挂载 target 目录(加速编译)
      - cli-target-cache:/workspace/target
      # 挂载测试配置目录
      - cli-test-config:/tmp/test-config
    depends_on:
      e2e-oauth-db:
        condition: service_healthy
    networks:
      - cli-e2e-net
    # 默认不启动,由测试脚本按需启动
    profiles:
      - test

networks:
  cli-e2e-net:
    driver: bridge
    name: oauth-db-cli-e2e-network

volumes:
  # 编译缓存(加速测试)
  cli-target-cache:
    name: oauth-db-cli-target-cache
  # 测试配置目录
  cli-test-config:
    name: oauth-db-cli-test-config