version: '3.8'

services:
  postgres:
    image: postgres:15-alpine
    container_name: jiachenlong-db-test
    restart: unless-stopped
    environment:
      POSTGRES_DB: zodiac
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 5s
      retries: 5

  backend:
    image: python:3.11-slim
    container_name: jiachenlong-backend-test
    restart: unless-stopped
    working_dir: /app
    command: >
      bash -c "pip install fastapi uvicorn sqlalchemy psycopg2-binary pydantic python-jose bcrypt python-multipart pillow dashscope alibabacloud-dysmsapi20170525 -q && uvicorn app.main:app --host 0.0.0.0 --port 3000"
    ports:
      - "3000:3000"
    volumes:
      - /root/jiachenlong/backend:/app
    environment:
      - DATABASE_URL=postgresql://postgres:postgres@postgres:5432/zodiac
      - SECRET_KEY=test-secret-key-for-sms
      - ACCESS_TOKEN_EXPIRE_MINUTES=60
      - OSS_ACCESS_KEY_ID=LTAI5t6HUnpFBLEK9194kPVG
      - OSS_ACCESS_KEY_SECRET=LEr4Q8yRxb8D5b24cKfCwlt4MMoke1
      - OSS_BUCKET=jiachenlong-oss
      - OSS_ENDPOINT=oss-cn-hangzhou.aliyuncs.com
      - SMS_ACCESS_KEY_ID=LTAI5tQAx5niD7JQVqGE5acE
      - SMS_ACCESS_KEY_SECRET=QsQFAEKBkaNynIoKyvdIi3BUyWVZu1
      - SMS_SIGN_NAME=苏州算力
      - SMS_TEMPLATE_CODE=SMS_501590956
    depends_on:
      postgres:
        condition: service_healthy

volumes:
  postgres_data:
