services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    working_dir: /var/www/html
    volumes:
      - ../laravel-app:/var/www/html
    environment:
      APP_ENV: testing
      DB_CONNECTION: mysql
      DB_HOST: mysql
      DB_PORT: 3306
      DB_DATABASE: vtu_test
      DB_USERNAME: vtu
      DB_PASSWORD: vtu_secret
      CACHE_STORE: redis
      QUEUE_CONNECTION: redis
      REDIS_HOST: redis
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_started
    command: php-fpm

  worker:
    build:
      context: .
      dockerfile: Dockerfile
    working_dir: /var/www/html
    volumes:
      - ../laravel-app:/var/www/html
    environment:
      APP_ENV: testing
      DB_CONNECTION: mysql
      DB_HOST: mysql
      DB_PORT: 3306
      DB_DATABASE: vtu_test
      DB_USERNAME: vtu
      DB_PASSWORD: vtu_secret
      CACHE_STORE: redis
      QUEUE_CONNECTION: redis
      REDIS_HOST: redis
    depends_on:
      - app
    command: php artisan queue:work --sleep=1 --tries=3 --timeout=90

  scheduler:
    build:
      context: .
      dockerfile: Dockerfile
    working_dir: /var/www/html
    volumes:
      - ../laravel-app:/var/www/html
    environment:
      APP_ENV: testing
      DB_CONNECTION: mysql
      DB_HOST: mysql
      DB_PORT: 3306
      DB_DATABASE: vtu_test
      DB_USERNAME: vtu
      DB_PASSWORD: vtu_secret
      CACHE_STORE: redis
      QUEUE_CONNECTION: redis
      REDIS_HOST: redis
    depends_on:
      - app
    command: sh -lc 'while true; do php artisan schedule:run --verbose --no-interaction; sleep 60; done'

  mysql:
    image: mysql:8.4
    environment:
      MYSQL_DATABASE: vtu_test
      MYSQL_USER: vtu
      MYSQL_PASSWORD: vtu_secret
      MYSQL_ROOT_PASSWORD: root_secret
    ports:
      - "33067:3306"
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-proot_secret"]
      interval: 5s
      timeout: 5s
      retries: 20
    volumes:
      - mysql_data:/var/lib/mysql

  redis:
    image: redis:7-alpine
    ports:
      - "6380:6379"

volumes:
  mysql_data:
