---
services:

  test-integration:
    build:
      context: .
      target: test-integration
    volumes:
      - .:/var/app
    environment:
      - MYSQL_HOST=test-db
      - MYSQL_USER=user
      - MYSQL_PASSWORD=pass
      - MYSQL_DB=public
      - AUTH0_CLIENT_ID
      - AUTH0_CLIENT_SECRET
      - AUTH0_DOMAIN
      - AUTH0_AUDIENCE
      - AUTH0_ISSUER
      - AUTH0_ALGORITHMS
      - AUTH0_REDIRECT_URI
      - SNOWFLAKE_PRIVATE_KEY
      - YTCMS_PROJECT_ID
      - YTCMS_PRIVATE_KEY_ID
      - YTCMS_PRIVATE
      - YTCMS_CLIENT_EMAIL
      - YTCMS_CLIENT_ID
    depends_on:
      test-db:
        condition: service_healthy

  unit-lint:
    build:
      context: .
      target: unit-lint
    volumes:
      - .:/var/app

  yt_audits-deploy:
    build:
      context: .
      target: deploy
    depends_on:
      test-db:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/"]
      interval: 1m30s
      timeout: 10s
      retries: 3
      start_period: 40s
    ports:
      - "8889:8000"

  test-db:
    platform: linux/amd64
    image: mysql:8.2
    environment:
      MYSQL_USER: user
      MYSQL_PASSWORD: pass
      MYSQL_DATABASE: public
      MYSQL_RANDOM_ROOT_PASSWORD: true
    healthcheck:
      # litters mysql logs with warnings http not valid (netcat not installed)
      test: ["CMD", "curl", "-sf", "http://localhost:3306"]
      interval: 1s
      timeout: 5s
      retries: 30
    volumes:
      - type: bind
        source: db.sql
        target: /docker-entrypoint-initdb.d/db.sql
        read_only: true
