version: '3.6'

x-aliases:
  - &linux_php_service
      ulimits:
        core: 99999999999
      working_dir: '/home/circleci/app'
      stdin_open: true
      tty: true
      volumes:
        - .:/home/circleci/app
        - .composer:/home/circleci/.composer
        - .scenarios.lock:/home/circleci/app/.scenarios.lock
        - agent-socket:/var/run/datadog
        - .cargo-registry:/rust/cargo/registry
      tmpfs: [ '/home/circleci/app/tmp:uid=3434,gid=3434,exec,size=12G' ]
      depends_on:
        - agent
        #- staging_agent
        - ddagent_integration
        - request-replayer
        - test-agent
        #- elasticsearch2_integration
        - rabbitmq_integration
        - elasticsearch7_integration
        - httpbin_integration
        - redis_integration
        - sqlsrv_integration
        - mongodb_integration
        - mysql_integration
        - memcached_integration
        - googlespanner_integration
        - kafka_integration
      environment:
        - REDIS_HOSTNAME=redis_integration
        - DDAGENT_HOSTNAME=ddagent_integration
        - HTTPBIN_HOSTNAME=httpbin_integration
        - RUSTC_BOOTSTRAP=1
        - COMPOSER_MEMORY_LIMIT=-1
        - PHP_IDE_CONFIG=serverName=docker
        - DD_TRACE_DOCKER_DEBUG
        - DATADOG_HAVE_DEV_ENV=1
        - DD_SPAWN_WORKER_USE_EXEC=1
      cap_add:
        - SYS_PTRACE
      security_opt:
        - seccomp:unconfined
      # Privileged is required to run some pcntl tests locally as well as native profiler.
      privileged: true

  - &windows_php_service
      volumes:
        - .:C:\Users\ContainerAdministrator\app
        - .composer:C:\Users\ContainerAdministrator\.composer
      depends_on:
        - windows-request-replayer
        - windows-httpbin_integration
      environment:
        - DDAGENT_HOSTNAME=ddagent_integration
        - HTTPBIN_HOSTNAME=httpbin_integration
        - COMPOSER_MEMORY_LIMIT=-1
        - PHP_IDE_CONFIG=serverName=docker
        - DD_TRACE_DOCKER_DEBUG
        - DATADOG_HAVE_DEV_ENV=1

services:
  # --- Alpine (Legacy) ---
  '7.0-alpine': { <<: *linux_php_service, image: 'datadog/docker-library:ddtrace_alpine_php-7.0-debug' }
  '7.1-alpine': { <<: *linux_php_service, image: 'datadog/docker-library:ddtrace_alpine_php-7.1-debug' }
  '7.2-alpine': { <<: *linux_php_service, image: 'datadog/docker-library:ddtrace_alpine_php-7.2-debug' }
  '7.3-alpine': { <<: *linux_php_service, image: 'datadog/docker-library:ddtrace_alpine_php-7.3-debug' }
  '7.4-alpine': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-7.4-debug-alpine-3.11' }
  # --- Alpine ---
  '8.0-alpine': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.0_alpine' }
  # --- Buster ---
  '7.0-buster': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-7.0_buster' }
  '7.1-buster': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-7.1_buster' }
  '7.2-buster': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-7.2_buster' }
  '7.3-buster': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-7.3_buster' }
  '7.4-buster': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-7.4_buster' }
  '7.4-buster-shared-ext': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-7.4-shared-ext' }
  '8.0-buster': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.0_buster' }
  '8.0-buster-shared-ext': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.0-shared-ext' }
  '8.1-buster': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.1_buster' }
  '8.2-buster': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.2_buster' }
  '8.3-buster': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.3_buster' }
  '8.4-buster': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.4_buster' }
  'php-master-buster': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-master_buster' }
  # --- Bookworm ---
  '8.2-bookworm': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.2_bookworm-5' }
  '8.3-bookworm': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.3_bookworm-5' }
  '8.4-bookworm': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.4_bookworm-5' }
  # --- CentOS 6 ---
  '7.0-centos7': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-7.0_centos-7' }
  '7.1-centos7': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-7.1_centos-7' }
  '7.2-centos7': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-7.2_centos-7' }
  '7.3-centos7': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-7.3_centos-7' }
  '7.4-centos7': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-7.4_centos-7' }
  '8.0-centos7': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.0_centos-7' }
  '8.1-centos7': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.1_centos-7' }
  '8.2-centos7': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.2_centos-7' }
  '8.3-centos7': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.3_centos-7' }
  '8.4-centos7': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.4_centos-7' }
  # --- Windows ---
  '7.0-windows': { <<: *windows_php_service, image: 'datadog/dd-trace-ci:php-7.0_windows' }
  '7.1-windows': { <<: *windows_php_service, image: 'datadog/dd-trace-ci:php-7.1_windows' }
  '7.2-windows': { <<: *windows_php_service, image: 'datadog/dd-trace-ci:php-7.2_windows' }
  '7.3-windows': { <<: *windows_php_service, image: 'datadog/dd-trace-ci:php-7.3_windows' }
  '7.4-windows': { <<: *windows_php_service, image: 'datadog/dd-trace-ci:php-7.4_windows' }
  '8.0-windows': { <<: *windows_php_service, image: 'datadog/dd-trace-ci:php-8.0_windows' }
  '8.1-windows': { <<: *windows_php_service, image: 'datadog/dd-trace-ci:php-8.1_windows' }
  '8.2-windows': { <<: *windows_php_service, image: 'datadog/dd-trace-ci:php-8.2_windows' }
  '8.3-windows': { <<: *windows_php_service, image: 'datadog/dd-trace-ci:php-8.3_windows' }
  '8.4-windows': { <<: *windows_php_service, image: 'datadog/dd-trace-ci:php-8.4_windows' }

  rabbitmq_integration:
    image: rabbitmq:3.8.9-alpine # 3.8.9 is the latest version that supports Erlang 20
    ports:
      - "5672:5672"
      - "15672:15672"

  mysql_integration:
    image: mysql/mysql-server:8.0
    command: --default-authentication-plugin=mysql_native_password --sql-mode="NO_ENGINE_SUBSTITUTION"
    ports:
      - "3306:3306"
    volumes:
      - ./dockerfiles/services/mysql:/docker-entrypoint-initdb.d
    environment:
      - MYSQL_ROOT_PASSWORD=test
      - MYSQL_PASSWORD=test
      - MYSQL_USER=test
      - MYSQL_DATABASE=test

  sqlsrv_integration:
    image: mcr.microsoft.com/mssql/server:2022-latest
    ports:
      - "1433:1433"
    environment:
      - ACCEPT_EULA=Y
      - MSSQL_SA_PASSWORD=Password12!
      - MSSQL_PID=Developer

  elasticsearch2_integration:
    image: "elasticsearch:2"

  elasticsearch7_integration:
    image: "elasticsearch:7.17.0"
    container_name: "elasticsearch7_integration"
    environment:
      - discovery.type=single-node
      - "ES_JAVA_OPTS=-Xms1g -Xmx1g"
    cap_add:
      - IPC_LOCK
    ports:
      - "9200:9200"
      - "9300:9300"
    ulimits:
        memlock:
            soft: -1
            hard: -1

  googlespanner_integration:
    image: gcr.io/cloud-spanner-emulator/emulator:1.5.25
    ports:
      - "9010:9010"
      - "9020:9020"
    networks:
      default:
        aliases:
          - spanner.local

  kafka_integration:
    image: confluentinc/cp-kafka:7.7.1
    ports:
      - "9092:9092"
    networks:
      default:
        aliases:
          - kafka_integration
    environment:
        - KAFKA_BROKER_ID=111
        - KAFKA_CREATE_TOPICS=test-lowlevel:1:1,test-highlevel:1:1
        - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
        - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka_integration:9092
        - KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT
        - KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT
        - KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1
        - KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1
        - KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1
        - KAFKA_AUTO_CREATE_TOPICS_ENABLE=true
    depends_on:
      - zookeeper

  zookeeper:
    image: confluentinc/cp-zookeeper:7.7.1
    ports:
      - "2181:2181"
    environment:
      - ZOOKEEPER_CLIENT_PORT=2181
      - ZOOKEEPER_TICK_TIME=2000

  mongodb_integration:
    image: "circleci/mongo:4.0"
    ports:
      - "27017:27017"
    environment:
      - MONGO_INITDB_ROOT_USERNAME=test
      - MONGO_INITDB_ROOT_PASSWORD=test

  redis_integration:
    image: "datadog/dd-trace-ci:php-redis-5.0"

  memcached_integration:
    image: "memcached:1.5-alpine"

  httpbin_integration:
    image: kong/httpbin
    ports:
      - "8765:80"

  ddagent_integration:
    image: datadog/agent:latest
    healthcheck:
      test: ["CMD", "curl", "-f", "-X", "HEAD", "http://localhost:8126"]
      interval: 10s
      timeout: 2s
      retries: 2
    environment:
      - DD_APM_ENABLED=true
      - DD_BIND_HOST=0.0.0.0
      - DD_API_KEY=invalid_key_but_its_ok

  request-replayer:
    image: datadog/dd-trace-ci:php-request-replayer-2.0
    ports:
      - "8766:80"

  agent:
    image: datadog/agent:latest
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /proc/:/host/proc/:ro
      - /sys/fs/cgroup/:/host/sys/fs/cgroup:ro
      - agent-socket:/var/run/datadog
    environment:
      - DD_API_KEY=${DATADOG_API_KEY}
      - DD_APM_ENABLED=true
      - DD_DOGSTATSD_NON_LOCAL_TRAFFIC=1
      - DD_APM_RECEIVER_SOCKET=/var/run/datadog/apm.socket
      - DD_REMOTE_CONFIGURATION_ENABLED=true
    ports:
      - "8126:8126"

  staging_agent:
    image: datadog/agent:latest
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /proc/:/host/proc/:ro
      - /sys/fs/cgroup/:/host/sys/fs/cgroup:ro
      - agent-socket:/var/run/datadog
    environment:
      - DD_API_KEY=${DATADOG_STAGING_API_KEY}
      - DD_SITE=datad0g.com
      - DD_APM_ENABLED=true
      - DD_DOGSTATSD_NON_LOCAL_TRAFFIC=1
      - DD_APM_RECEIVER_SOCKET=/var/run/datadog/apm.socket
      - DD_REMOTE_CONFIGURATION_ENABLED=true
      - DD_REMOTE_CONFIGURATION_REFRESH_INTERVAL=5s
      - DD_APM_RECEIVER_PORT=8125
    ports:
      - "8125:8125"

  packager:
    image: datadog/docker-library:ddtrace_php_fpm_packaging
    working_dir: /app
    volumes:
      - .:/app

  test-agent:
    image: ghcr.io/datadog/dd-apm-test-agent/ddapm-test-agent:latest
    ports:
      - "127.0.0.1:9126:8126"
    volumes:
      - ./tests/snapshots:/snapshots
    environment:
      - LOG_LEVEL=DEBUG
      - TRACE_LANGUAGE=php
      - DD_TRACE_AGENT_URL=http://request-replayer:80
      - PORT=9126
      - DD_SUPPRESS_TRACE_PARSE_ERRORS=true
      - DD_POOL_TRACE_CHECK_FAILURES=true
      - DD_DISABLE_ERROR_RESPONSES=true
      - SNAPSHOTS_DIR=/snapshots
      - SNAPSHOT_CI=0
      - SNAPSHOT_REMOVED_ATTRS=start,duration,metrics.php.compilation.total_time_ms,metrics.php.memory.peak_usage_bytes,metrics.php.memory.peak_real_usage_bytes,metrics.process_id
      - ENABLED_CHECKS=trace_stall,trace_peer_service,trace_dd_service


  windows-request-replayer:
    image: datadog/dd-trace-ci:php-request-replayer-2.0-windows
    ports:
      - "8766:80"
    networks:
      default:
        aliases:
          - request-replayer

  windows-httpbin_integration:
    image: datadog/dd-trace-ci:httpbin-windows
    ports:
      - "8765:80"
    networks:
      default:
        aliases:
          - httpbin_integration

volumes:
  agent-socket:
