services:
  network-service:
    image: alpine
    container_name: lobe-network
    restart: always
    ports:
      - ${MINIO_PORT}:${MINIO_PORT}
      - 9001:9001
      - ${CASDOOR_PORT}:${CASDOOR_PORT}
      - ${PANEL_APP_PORT_HTTP}:3210
    command: tail -f /dev/null
    networks:
      - lobe-network
  postgresql:
    image: pgvector/pgvector:pg17
    container_name: lobe-postgres
    ports:
      - 5432:5432
    volumes:
      - ./data:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=${LOBE_DB_NAME}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    healthcheck:
      test:
        - CMD-SHELL
        - pg_isready -U postgres
      interval: 5s
      timeout: 5s
      retries: 5
    restart: always
    networks:
      - lobe-network
  minio:
    image: minio/minio:RELEASE.2025-04-22T22-12-26Z
    container_name: lobe-minio
    network_mode: service:network-service
    volumes:
      - ./s3_data:/etc/minio/data
    environment:
      - MINIO_API_CORS_ALLOW_ORIGIN=*
    env_file:
      - .env
    restart: always
    entrypoint: "/bin/sh -c \"\n  minio server /etc/minio/data --address ':${MINIO_PORT}'\
      \ --console-address ':9001' &\n  MINIO_PID=\\$!\n  while ! curl -s http://localhost:${MINIO_PORT}/minio/health/live;\
      \ do\n    echo 'Waiting for MinIO to start...'\n    sleep 1\n  done\n  sleep\
      \ 5\n  mc alias set myminio http://localhost:${MINIO_PORT} ${MINIO_ROOT_USER}\
      \ ${MINIO_ROOT_PASSWORD}\n  echo 'Creating bucket ${MINIO_LOBE_BUCKET}'\n  mc\
      \ mb myminio/${MINIO_LOBE_BUCKET}\n  wait \\$MINIO_PID\n\"\n"
  casdoor:
    image: casbin/casdoor:v2.13.0
    container_name: lobe-casdoor
    entrypoint: /bin/sh -c './server --createDatabase=true'
    network_mode: service:network-service
    depends_on:
      postgresql:
        condition: service_healthy
    environment:
      httpport: ${CASDOOR_PORT}
      RUNNING_IN_DOCKER: 'true'
      driverName: postgres
      dataSourceName: user=postgres password=${POSTGRES_PASSWORD} host=postgresql
        port=5432 sslmode=disable dbname=casdoor
      runmode: dev
    volumes:
      - ./init_data.json:/init_data.json
    env_file:
      - .env
  searxng:
    image: searxng/searxng
    container_name: lobe-searxng
    volumes:
      - ./searxng-settings.yml:/etc/searxng/settings.yml
    environment:
      - SEARXNG_SETTINGS_FILE=/etc/searxng/settings.yml
    restart: always
    networks:
      - lobe-network
    env_file:
      - .env
  lobe:
    image: lobehub/lobe-chat-database:1.143.3
    container_name: lobe-chat
    network_mode: service:network-service
    depends_on:
      postgresql:
        condition: service_healthy
      network-service:
        condition: service_started
      minio:
        condition: service_started
      casdoor:
        condition: service_started
    environment:
      - NEXT_AUTH_SSO_PROVIDERS=casdoor
      - KEY_VAULTS_SECRET=Kix2wcUONd4CX51E/ZPAd36BqM4wzJgKjPtz2sGztqQ=
      - NEXT_AUTH_SECRET=NX2kaPE923dt6BL2U8e9oSre5RfoT7hg
      - DATABASE_URL=postgresql://postgres:${POSTGRES_PASSWORD}@postgresql:5432/${LOBE_DB_NAME}
      - S3_BUCKET=${MINIO_LOBE_BUCKET}
      - S3_ENABLE_PATH_STYLE=1
      - S3_ACCESS_KEY=${MINIO_ROOT_USER}
      - S3_ACCESS_KEY_ID=${MINIO_ROOT_USER}
      - S3_SECRET_ACCESS_KEY=${MINIO_ROOT_PASSWORD}
      - LLM_VISION_IMAGE_USE_BASE64=1
      - S3_SET_ACL=0
      - SEARXNG_URL=http://searxng:8080
    env_file:
      - .env
    restart: always
    entrypoint: "/bin/sh -c \"\n  /bin/node /app/startServer.js &\n  LOBE_PID=\\$!\n\
      \  sleep 3\n  if [ $(wget --timeout=5 --spider --server-response ${AUTH_CASDOOR_ISSUER}/.well-known/openid-configuration\
      \ 2>&1 | grep -c 'HTTP/1.1 200 OK') -eq 0 ]; then\n    echo '⚠️Warning: Unable\
      \ to fetch OIDC configuration from Casdoor'\n    echo 'Request URL: ${AUTH_CASDOOR_ISSUER}/.well-known/openid-configuration'\n\
      \    echo 'Read more at: https://lobehub.com/docs/self-hosting/server-database/docker-compose#necessary-configuration'\n\
      \    echo ''\n    echo '⚠️注意：无法从 Casdoor 获取 OIDC 配置'\n    echo '请求 URL: ${AUTH_CASDOOR_ISSUER}/.well-known/openid-configuration'\n\
      \    echo '了解更多：https://lobehub.com/zh/docs/self-hosting/server-database/docker-compose#necessary-configuration'\n\
      \    echo ''\n  else\n    if ! wget -O - --timeout=5 ${AUTH_CASDOOR_ISSUER}/.well-known/openid-configuration\
      \ 2>&1 | grep 'issuer' | grep ${AUTH_CASDOOR_ISSUER}; then\n      printf '❌Error:\
      \ The Auth issuer is conflict, Issuer in OIDC configuration is: %s' \\$(wget\
      \ -O - --timeout=5 ${AUTH_CASDOOR_ISSUER}/.well-known/openid-configuration 2>&1\
      \ | grep -E 'issuer.*' | awk -F '\\\"' '{print \\$4}')\n      echo ' , but the\
      \ issuer in .env file is: ${AUTH_CASDOOR_ISSUER} '\n      echo 'Request URL:\
      \ ${AUTH_CASDOOR_ISSUER}/.well-known/openid-configuration'\n      echo 'Read\
      \ more at: https://lobehub.com/docs/self-hosting/server-database/docker-compose#necessary-configuration'\n\
      \      echo ''\n      printf '❌错误：Auth 的 issuer 冲突，OIDC 配置中的 issuer 是：%s' \\\
      $(wget -O - --timeout=5 ${AUTH_CASDOOR_ISSUER}/.well-known/openid-configuration\
      \ 2>&1 | grep -E 'issuer.*' | awk -F '\\\"' '{print \\$4}')\n      echo ' ,\
      \ 但 .env 文件中的 issuer 是：${AUTH_CASDOOR_ISSUER} '\n      echo '请求 URL: ${AUTH_CASDOOR_ISSUER}/.well-known/openid-configuration'\n\
      \      echo '了解更多：https://lobehub.com/zh/docs/self-hosting/server-database/docker-compose#necessary-configuration'\n\
      \      echo ''\n    fi\n  fi\n  if [ $(wget --timeout=5 --spider --server-response\
      \ ${S3_ENDPOINT}/minio/health/live 2>&1 | grep -c 'HTTP/1.1 200 OK') -eq 0 ];\
      \ then\n    echo '⚠️Warning: Unable to fetch MinIO health status'\n    echo\
      \ 'Request URL: ${S3_ENDPOINT}/minio/health/live'\n    echo 'Read more at: https://lobehub.com/docs/self-hosting/server-database/docker-compose#necessary-configuration'\n\
      \    echo ''\n    echo '⚠️注意：无法获取 MinIO 健康状态'\n    echo '请求 URL: ${S3_ENDPOINT}/minio/health/live'\n\
      \    echo '了解更多：https://lobehub.com/zh/docs/self-hosting/server-database/docker-compose#necessary-configuration'\n\
      \    echo ''\n  fi\n  wait \\$LOBE_PID\n\"\n"
volumes:
  data:
    driver: local
  s3_data:
    driver: local
networks:
  lobe-network:
    driver: bridge
