---
services:
  web-deploy:
    build:
      context: .
      dockerfile: Dockerfile
      target: app
      secrets:
        - COMPOSER_AUTH
    ports:
      - "80:80"
    healthcheck:
      test: ["CMD-SHELL", "curl", "-f", "http://localhost:80/healthchk.php"]
      interval: 30s
      timeout: 5s
      retries: 5
    platform: linux/amd64
    environment:
      - APPLICATION_ENV=testing
      - Environment=dev
      - PHP_DISPLAY_ERRORS=true
      - PHP_SESSION_COOKIE_HTTPONLY=0
      - PHP_SESSION_COOKIE_SECURE=0
      - AWS_ACCESS_KEY_ID
      - AWS_SECRET_ACCESS_KEY
      - AWS_SESSION_TOKEN
      - AWS_PROFILE
      - AWS_REGION
      - AWS_KEY=$AWS_ACCESS_KEY_ID
      - AWS_SECRET=$AWS_SECRET_ACCESS_KEY
      - DD_TRACE_ANALYTICS_ENABLED=true
      - DD_TRACE_APP_NAME=dev-ows-metadata
      - DD_TRACE_DEBUG=false
      - DD_TRACE_GLOBAL_TAGS=env:dev-ows-metadata
    env_file:
      - path: .env
        required: false
    volumes:
      - ./config:/var/www/html/config
      - ./library/:/var/www/html/library
      - ./metadata:/var/www/html/metadata
      - ./src:/var/www/html/src
    depends_on:
      redis:
        condition: service_started
      ha-proxy:
        condition: service_healthy
  redis:
    image: redis:7.2.4
  ha-proxy:
    image: haproxy:2.9.6
    ports:
      - 3306:3306
      - 3307:3307
      - 8080:8080
    volumes:
      - ./haproxy_mysql.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
    healthcheck:
      interval: '1s'
      retries: 60
      # yamllint disable rule:line-length
      test: |
        bash -c 'exec 3<>/dev/tcp/127.0.0.1/8081; echo -e "GET / HTTP/1.1\nConnection: close\n" >&3; cat <&3 | grep -q "200 OK"'
      # yamllint enable rule:line-length
  unit-lint:
    extends:
      file: docker-compose.unit-lint.yml
      service: unit-lint
    environment:
      # Fail tests with missing snapshot files. To create or refresh
      # snapshots, run `docker compose run --rm --build update-snapshots`.
      - CREATE_SNAPSHOTS=false
  update-snapshots:
    extends:
      file: docker-compose.unit-lint.yml
      service: unit-lint
    environment:
      - SKIP_LINT=true
      - SKIP_COVERAGE=true
      - SKIP_FULL_STYLE_CHECK=true
      - UPDATE_SNAPSHOTS=true
    volumes:
      - ./tests:/var/www/html/tests
  format:
    build:
      context: .
      target: format
      secrets:
        - COMPOSER_AUTH
    platform: linux/amd64
    environment:
      - COMPOSER_AUTH
    volumes:
      - ./config:/var/www/html/config
      - ./library:/var/www/html/library
      - ./metadata:/var/www/html/metadata
      - ./src:/var/www/html/src
      - ./tests:/var/www/html/tests
  update-lockfile:
    platform: linux/amd64
    build:
      context: .
      target: update-lockfile
      secrets:
        - COMPOSER_AUTH
    environment:
      - COMPOSER_AUTH
    volumes:
      - ./composer.lock:/var/www/html/composer.lock
secrets:
  COMPOSER_AUTH:
    environment: "COMPOSER_AUTH"
