version: '3.8'

services:
  mysql:
    image: mysql:8.0
    container_name: knowledge_base_mysql
    environment:
      MYSQL_ROOT_PASSWORD: 42d3da6bb45212fc63923140bf487cdb
      MYSQL_DATABASE: knowledge_base
      MYSQL_USER: knowledge_user
      MYSQL_PASSWORD: 42d3da6bb45212fc63923140bf487cdb
      MYSQL_CHARACTER_SET_SERVER: utf8mb4
      MYSQL_COLLATION_SERVER: utf8mb4_unicode_ci
    volumes:
      - ./storage/mysql:/var/lib/mysql
    ports:
      - "3306:3306"
    restart: unless-stopped
    command: --default-authentication-plugin=mysql_native_password --bind-address=0.0.0.0

  redis:
    image: redis:7-alpine
    container_name: knowledge_base_redis
    volumes:
      - ./storage/redis:/data
    ports:
      - "6379:6379"
    restart: unless-stopped
    command: redis-server --appendonly yes --bind 0.0.0.0

  meilisearch:
    image: getmeili/meilisearch:v1.5
    container_name: knowledge_base_meilisearch
    environment:
      MEILI_MASTER_KEY: ae1f17f49ccacf3d62c031fdcec8d2c8f89cb9d7949fbad00ae4f592517e400a
      MEILI_ENV: production
    volumes:
      - ./storage/meilisearch:/meili_data
    ports:
      - "7700:7700"
    restart: unless-stopped

  app:
    image: knowledge-base-app:latest
    container_name: knowledge_base_app
    environment:
      APP_NAME: "知识库系统"
      APP_ENV: production
      APP_KEY: base64:35mzQaN6bI37mRDJy36NnkWLIbruftVNMH4q6ZTesQM=
      APP_DEBUG: "false"
      APP_URL: http://192.168.1.33:8000
      DB_CONNECTION: mysql
      DB_HOST: 127.0.0.1
      DB_PORT: 3306
      DB_DATABASE: knowledge_base
      DB_USERNAME: knowledge_user
      DB_PASSWORD: 42d3da6bb45212fc63923140bf487cdb
      REDIS_HOST: 127.0.0.1
      REDIS_PORT: 6379
      REDIS_PASSWORD: ""
      CACHE_STORE: redis
      SESSION_DRIVER: redis
      QUEUE_CONNECTION: redis
      SCOUT_DRIVER: meilisearch
      MEILISEARCH_HOST: http://127.0.0.1:7700
      MEILISEARCH_KEY: ae1f17f49ccacf3d62c031fdcec8d2c8f89cb9d7949fbad00ae4f592517e400a
      LOG_CHANNEL: stack
      FILESYSTEM_DISK: local
      SESSION_DOMAIN: ""
      SESSION_SECURE: "false"
      # Swoole/Octane 配置
      OCTANE_SERVER: swoole
      OCTANE_HOST: 0.0.0.0
      OCTANE_PORT: 8000
      OCTANE_WORKERS: 8
      OCTANE_TASK_WORKERS: 4
      OCTANE_MAX_REQUESTS: 1000
      OCTANE_WATCH: "false"
    volumes:
      - ./:/var/www/html
      - ./storage/app:/var/www/html/storage
    ports:
      - "8000:8000"
    restart: unless-stopped
    depends_on:
      - mysql
      - redis
      - meilisearch
    network_mode: host
    healthcheck:
      test: ["CMD", "/bin/sh", "/var/www/html/docker/swoole-health-check.sh"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s