version: '3.3'

services:
  ui:
    image: registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-ui:latest
    ports:
      - ${SERVICE_PORT:-1081}:80
    restart: unless-stopped
    depends_on:
      service:
        condition: service_healthy
    networks:
      - orion-visor-net

  service:
    image: registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-service:latest
    privileged: true
    environment:
      - SPRING_PROFILES_ACTIVE=${SPRING_PROFILES_ACTIVE:-prod}
      - MYSQL_HOST=${MYSQL_HOST:-mysql}
      - MYSQL_PORT=${MYSQL_PORT:-3306}
      - MYSQL_DATABASE=${MYSQL_DATABASE:-orion_visor}
      - MYSQL_USER=${MYSQL_USER:-root}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD:-Data@123456}
      - REDIS_HOST=${REDIS_HOST:-redis}
      - REDIS_PASSWORD=${REDIS_PASSWORD:-Data@123456}
      - SECRET_KEY=${SECRET_KEY:-uQeacXV8b3isvKLK}
      - DEMO_MODE=${DEMO_MODE:-false}
    volumes:
      - ${VOLUME_BASE:-/data/orion-visor-space/docker-volumes}/service/root-orion:/root/orion
    restart: unless-stopped
    healthcheck:
      test: [ "CMD", "curl", "http://127.0.0.1:9200/orion-visor/api/server/bootstrap/health" ]
      interval: 15s
      timeout: 5s
      retries: 10
      start_period: 15s
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - orion-visor-net

  mysql:
    image: registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-mysql:latest
    privileged: true
    ports:
      - 3307:3306
    environment:
      - MYSQL_DATABASE=${MYSQL_DATABASE:-orion_visor}
      - MYSQL_USER=${MYSQL_USER:-orion}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD:-Data@123456}
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-Data@123456}
    volumes:
      - ${VOLUME_BASE:-/data/orion-visor-space/docker-volumes}/mysql/var-lib-mysql:/var/lib/mysql
      - ${VOLUME_BASE:-/data/orion-visor-space/docker-volumes}/mysql/var-lib-mysql-files:/var/lib/mysql-files
    restart: unless-stopped
    healthcheck:
      test: [ "CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/3306" ]
      interval: 15s
      timeout: 5s
      retries: 10
      start_period: 5s
    networks:
      - orion-visor-net

  redis:
    image: registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-redis:latest
    privileged: true
    ports:
      - 6380:6379
    environment:
      - REDIS_PASSWORD=${REDIS_PASSWORD:-Data@123456}
    volumes:
      - ${VOLUME_BASE:-/data/orion-visor-space/docker-volumes}/redis/data:/data
    command: sh -c "redis-server /usr/local/redis.conf --requirepass $${REDIS_PASSWORD}"
    restart: unless-stopped
    healthcheck:
      test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
      interval: 15s
      timeout: 5s
      retries: 10
      start_period: 5s
    networks:
      - orion-visor-net

  adminer:
    image: registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-adminer:latest
    ports:
      - 8081:8080
    environment:
      - ADMINER_DEFAULT_SERVER=${MYSQL_HOST:-mysql}
    depends_on:
      mysql:
        condition: service_healthy
    networks:
      - orion-visor-net

networks:
  orion-visor-net:
    driver: bridge