version: '3.8'

services:
  db:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: webcalendar_test
      MYSQL_USER: webcalendar
      MYSQL_PASSWORD: password
    healthcheck:
      test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost", "-u", "root", "-proot"]
      timeout: 20s
      retries: 10

  web:
    build:
      context: ..
      dockerfile: docker/Dockerfile-php8-dev
    volumes:
      - ..:/var/www/html
    environment:
      - WEBCALENDAR_USE_ENV=true
      - WEBCALENDAR_DB_TYPE=mysqli
      - WEBCALENDAR_DB_HOST=db
      - WEBCALENDAR_DB_LOGIN=webcalendar
      - WEBCALENDAR_DB_PASSWORD=password
      - WEBCALENDAR_DB_DATABASE=webcalendar_test
      - WEBCALENDAR_USER_INC=user.php
      - WEBCALENDAR_INSTALL_PASSWORD=2168ad5e463d9accb215edaafa31c8d9 # md5 of 'Test123!'
      - WEBCALENDAR_MODE=dev
    depends_on:
      db:
        condition: service_healthy

  chrome:
    image: selenium/standalone-chrome:latest
    shm_size: 2gb
    depends_on:
      - web

  pytest:
    image: python:3.9
    volumes:
      - ..:/work
    working_dir: /work
    environment:
      - BASE_URL=http://web
      - SELENIUM_URL=http://chrome:4444/wd/hub
      - WEBCALENDAR_DB_HOST=db
      - WEBCALENDAR_DB_LOGIN=webcalendar
      - WEBCALENDAR_DB_PASSWORD=password
      - WEBCALENDAR_DB_DATABASE=webcalendar_test
    depends_on:
      - chrome
    command: >
      bash -c "apt-get update && apt-get install -y default-mysql-client && pip install pytest selenium pymysql cryptography && pytest -s tests/web-install-mysql.py"
