services:
  app:
    build:
      context: .
      dockerfile: Dockerfile.ci
      args:
        PHP_IMAGE: ${PHP_IMAGE:-php:8.2-cli}
        COMPOSER_IMAGE: ${COMPOSER_IMAGE:-composer:2}
    container_name: alrahma_ci_app
    working_dir: /app
    environment:
      APP_ENV: testing
      APP_KEY: ${APP_KEY:-}
      DB_CONNECTION: mysql
      DB_HOST: ${DB_HOST:-db}
      DB_PORT: ${DB_PORT:-3306}
      DB_DATABASE: ${DB_DATABASE:-school_api}
      DB_USERNAME: ${DB_USERNAME:-school}
      DB_PASSWORD: ${DB_PASSWORD:-school}
      CACHE_DRIVER: array
      QUEUE_CONNECTION: sync
      SESSION_DRIVER: array
      MAIL_MAILER: log
    depends_on:
      db:
        condition: service_healthy
  keygen:
    build:
      context: .
      dockerfile: Dockerfile.ci
      args:
        PHP_IMAGE: ${PHP_IMAGE:-php:8.2-cli}
        COMPOSER_IMAGE: ${COMPOSER_IMAGE:-composer:2}
    entrypoint:
      - sh
      - -lc
      - php -r 'echo "base64:" . base64_encode(random_bytes(32));'
  db:
    image: ${MYSQL_IMAGE:-mysql:8.0}
    environment:
      MYSQL_DATABASE: ${DB_DATABASE:-school_api}
      MYSQL_USER: ${DB_USERNAME:-school}
      MYSQL_PASSWORD: ${DB_PASSWORD:-school}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root}
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-uroot", "-p${MYSQL_ROOT_PASSWORD:-root}"]
      interval: 5s
      timeout: 5s
      retries: 20
