version: '3.8'

services:
  k6:
    build:
      context: .
      dockerfile: Dockerfile
    image: k6-test:latest
    container_name: k6-test
    network_mode: host  # 使用主機網絡，讓容器可以訪問主機上的服務
    volumes:
      - ./scenarios:/app/scenarios
      - ./tests:/app/tests
      - ./results:/app/results
    environment:
      - BASE_URL=${BASE_URL:-https://localhost:8888}
      - TEST_LOGIN_ID=${TEST_LOGIN_ID:-}
      - TEST_PASSWORD=${TEST_PASSWORD:-}
    # 不自動啟動，通過 make 命令運行
    command: ["run", "tests/smoke/smoke-health-test.js"]

  # 可選：如果需要測試資料庫或其他服務
  # influxdb:
  #   image: influxdb:2.7
  #   container_name: k6-influxdb
  #   ports:
  #     - "8086:8086"
  #   environment:
  #     - DOCKER_INFLUXDB_INIT_MODE=setup
  #     - DOCKER_INFLUXDB_INIT_USERNAME=admin
  #     - DOCKER_INFLUXDB_INIT_PASSWORD=admin123456
  #     - DOCKER_INFLUXDB_INIT_ORG=myorg
  #     - DOCKER_INFLUXDB_INIT_BUCKET=mybucket
  #   volumes:
  #     - influxdb-data:/var/lib/influxdb2
  #   networks:
  #     - test-network

  # grafana:
  #   image: grafana/grafana:latest
  #   container_name: k6-grafana
  #   ports:
  #     - "3000:3000"
  #   environment:
  #     - GF_AUTH_ANONYMOUS_ENABLED=true
  #     - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
  #   volumes:
  #     - grafana-data:/var/lib/grafana
  #     - ./provisioning:/etc/grafana/provisioning
  #   networks:
  #     - test-network
  #   depends_on:
  #     - influxdb

networks:
  test-network:
    driver: bridge

# volumes:
#   influxdb-data:
#   grafana-data:

