version: '3.8'

services:
  mysql:
    image: mysql:8.0
    container_name: kaopeilian-mysql
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: kaopeilian
      MYSQL_CHARACTER_SET: utf8mb4
      MYSQL_COLLATION: utf8mb4_unicode_ci
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
      - ./scripts/init.sql:/docker-entrypoint-initdb.d/init.sql
    command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    networks:
      - kaopeilian-network

  redis:
    image: redis:7-alpine
    container_name: kaopeilian-redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - kaopeilian-network

  backend:
    build:
      context: .
      dockerfile: Dockerfile.dev
    container_name: kaopeilian-backend
    depends_on:
      - mysql
      - redis
    environment:
      DATABASE_URL: mysql+aiomysql://root:Kaopeilian2025%21%40%23@120.79.247.16:3306/kaopeilian?charset=utf8mb4
      REDIS_URL: redis://redis:6379/0
    ports:
      - "8000:8000"
    volumes:
      - ./app:/app/app
      - ./tests:/app/tests
      - ./scripts:/app/scripts
      - ./.env:/app/.env
    command: uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
    networks:
      - kaopeilian-network

volumes:
  mysql_data:
  redis_data:

networks:
  kaopeilian-network:
    driver: bridge
