version: '3.9'

services:
  # Apache container for the log4shell module
  log4shell:
    build:
      context: ./test_mod_log4shell/tomcat/
      dockerfile: Dockerfile.tomcat
      args:
        TOMCAT_HASH_TAG: ${TOMCAT_TAG}
    healthcheck:
      test: "nc -z localhost 80"
      interval: ${DEFAULT_HEALTHCHECKS_INTERVAL}
      timeout: ${DEFAULT_HEALTHCHECKS_TIMEOUT}
      retries: ${DEFAULT_HEALTHCHECKS_RETRIES}
      start_period: ${DEFAULT_HEALTHCHECKS_START_PERIOD}
    networks:
      - test-network

  unifi:
    image: jacobalberty/unifi:v6.5.53
    volumes:
      - ./test_mod_log4shell/unifi.system.properties:/unifi/data/system.properties
    healthcheck:
      test: [ "CMD", "/usr/local/bin/docker-healthcheck.sh" ]
      interval: ${DEFAULT_HEALTHCHECKS_INTERVAL}
      timeout: ${DEFAULT_HEALTHCHECKS_TIMEOUT}
      retries: ${DEFAULT_HEALTHCHECKS_RETRIES}
      start_period: ${DEFAULT_HEALTHCHECKS_START_PERIOD}
    networks:
      - test-network

  dns-endpoint:
    build:
      context: ./dns-endpoint
      dockerfile: Dockerfile.dns-endpoint
    healthcheck:
      test: [ "CMD", "ruby", "/usr/local/bin/healthcheck.rb" ]
      interval: ${DEFAULT_HEALTHCHECKS_INTERVAL}
      timeout: ${DEFAULT_HEALTHCHECKS_TIMEOUT}
      retries: ${DEFAULT_HEALTHCHECKS_RETRIES}
      start_period: ${DEFAULT_HEALTHCHECKS_START_PERIOD}
    networks:
      - test-network

  # Wapiti container 
  # requires all the targets containers to work perfectly
  wapiti:
    build:
      context: "../../"
      dockerfile: "./tests/integration/wapiti/Dockerfile.integration"
      no_cache: true
    container_name: wapiti
    volumes:
      - ./.test:/home/
    networks:
      - test-network
    command: "${TESTS}"
    depends_on:
      log4shell:
        condition: service_healthy
      unifi:
        condition: service_healthy
      dns-endpoint:
        condition: service_healthy

networks:
  test-network:
