services:
  logboard:
    build: .
    container_name: logboard
    env_file:
      - .env
    ports:
      - "${LOGBOARD_PORT}:${LOGBOARD_PORT}"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./snapshots:/app/snapshots
      - ./logs:/app/logs
    restart: unless-stopped
    user: 0:0
    networks:
      - iaas
      - infrastructure_iaas
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:${LOGBOARD_PORT}/"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

  # LogBoard клиент для демонстрации
  logboard-client:
    build:
      context: ./client
      dockerfile: Dockerfile
    container_name: logboard-client
    env_file:
      - ./client/.env
    environment:
      - LOGBOARD_SERVER_URL=http://logboard:${LOGBOARD_PORT}
      - LOGBOARD_API_KEY=${LOGBOARD_DEFAULT_API_KEY:-dev-key-123}
      - HOSTNAME=${HOSTNAME:-$(hostname)}
      - LOGBOARD_INTERVAL=30
      - DOCKER_HOST=unix:///var/run/docker.sock
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./client/logs:/var/log
    restart: unless-stopped
    user: 0:0
    depends_on:
      - logboard
    networks:
      - iaas
      - infrastructure_iaas
    healthcheck:
      test: ["CMD", "ps", "aux"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

  # Тестовый контейнер для демонстрации работы клиента
  test-nginx:
    image: nginx:alpine
    container_name: test-nginx
    restart: unless-stopped
    ports:
      - "8080:80"
    volumes:
      - ./client/logs/nginx:/var/log/nginx
    networks:
      - iaas
      - infrastructure_iaas
    command: >
      sh -c "echo 'Test container started at $$(date)' > /var/log/nginx/access.log &&
             echo 'Test error log at $$(date)' > /var/log/nginx/error.log &&
             tail -f /var/log/nginx/access.log /var/log/nginx/error.log"

networks:
  iaas:
    external: true
  infrastructure_iaas:
    external: true
