name: serein-test-02

x-application-environment: &application-environment
  APP_DEBUG: "false"
  APP_ENV: testing
  APP_KEY: base64:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
  DB_CONNECTION: pgsql
  DB_DATABASE: experiment
  DB_HOST: postgres
  DB_PASSWORD: experiment
  DB_PORT: "5432"
  DB_USERNAME: experiment
  LOG_CHANNEL: stderr
  SESSION_DRIVER: array

services:
  postgres:
    image: postgres:17.6-bookworm@sha256:f3bd19c606e442c3d7bdfa8002e03fe260a1023351e0ea4598032022b68dd6e3
    environment:
      POSTGRES_DB: experiment
      POSTGRES_PASSWORD: experiment
      POSTGRES_USER: experiment
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U experiment -d experiment"]
      interval: 1s
      timeout: 3s
      retries: 30

  app:
    image: serein-test-02-php
    build:
      context: .
      dockerfile: Dockerfile
    command: ["php", "-S", "0.0.0.0:8080", "-t", "public", "public/server.php"]
    environment:
      <<: *application-environment
      BROWSER_DEFECT: "${BROWSER_DEFECT:-0}"
    depends_on:
      postgres:
        condition: service_healthy
    healthcheck:
      test:
        [
          "CMD",
          "php",
          "-r",
          "exit(@file_get_contents('http://127.0.0.1:8080/up') === false);",
        ]
      interval: 1s
      timeout: 3s
      retries: 30

  provider:
    image: serein-test-02-php
    build:
      context: .
      dockerfile: Dockerfile
    command: ["php", "-S", "0.0.0.0:8081", "provider/router.php"]
    environment:
      PROVIDER_DEFECT: "${PROVIDER_DEFECT:-0}"
    healthcheck:
      test:
        [
          "CMD",
          "php",
          "-r",
          "exit(@file_get_contents('http://127.0.0.1:8081/health') === false);",
        ]
      interval: 1s
      timeout: 3s
      retries: 30

  test:
    image: serein-test-02-php
    build:
      context: .
      dockerfile: Dockerfile
    environment:
      <<: *application-environment
      INVENTORY_URL: http://provider:8081
    entrypoint: []

  browser:
    build:
      context: .
      dockerfile: Dockerfile.browser
    depends_on:
      app:
        condition: service_healthy
