services:
  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"

  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: connecthub
      POSTGRES_USER: connecthub
      POSTGRES_PASSWORD: connecthub_pwd_change_me
    volumes:
      - ./data/pgdata:/var/lib/postgresql/data
    # 如需宿主机直连可打开该映射
    # ports:
    #   - "5432:5432"

  backend:
    build:
      context: .
      dockerfile: docker/Dockerfile
    env_file:
      - .env
    volumes:
      - ./data:/data
    ports:
      - "8000:8000"
    command: >
      sh -c "if [ \"${DEV_MODE:-0}\" = \"1\" ]; then uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload; else uvicorn app.main:app --host 0.0.0.0 --port 8000; fi"
    depends_on:
      - redis
      - postgres

  worker:
    build:
      context: .
      dockerfile: docker/Dockerfile
    env_file:
      - .env
    volumes:
      - ./data:/data
    command: >
      sh -c "celery -A app.tasks.celery_app:celery_app worker --loglevel=INFO"
    depends_on:
      - redis
      - postgres

  beat:
    build:
      context: .
      dockerfile: docker/Dockerfile
    env_file:
      - .env
    volumes:
      - ./data:/data
    command: >
      sh -c "celery -A app.tasks.celery_app:celery_app beat --loglevel=INFO"
    depends_on:
      - redis
      - postgres


