---
services:
  function:
    platform: linux/amd64
    build:
      context: .
      args:
        version: "local-dev"
    volumes:
      - ./src:/var/task/src
      - ./config.py:/var/task/config.py
      - ./scripts:/var/task/scripts
    ports:
      - "9000:8080"
    environment:
      - DD_ENV=dev
      - DD_SERVICE=sanitise-rds-data
      - DD_TRACE_ENABLED=false
      - DD_ENHANCED_METRICS=false
      - PYTHONDONTWRITEBYTECODE=1
      - AWS_ACCESS_KEY_ID
      - AWS_SECRET_ACCESS_KEY
      - AWS_SESSION_TOKEN
      - LOGGER_LEVEL=INFO
  lint-and-test:
    platform: linux/amd64
    build:
      context: .
      dockerfile: Dockerfile.tests
    ports:
      - "8000:8000"
    environment:
      - SKIP_LINT=0
      - TEST_ARGS=-v
      - COV_REPORT=term  # --cov-report pytest-cov option or OFF (try html!)
      - PYTHONDONTWRITEBYTECODE=1
    volumes:
      - ./src:/var/task/src
      - ./tests:/var/task/tests
  # Local PostgreSQL instances backing the integration tests. They stand in for
  # the source and target RDS clusters so the role-copy logic runs against a
  # real database rather than mocks.
  postgres-source:
    image: postgres:16
    environment:
      - POSTGRES_USER=master
      - POSTGRES_PASSWORD=masterpw
    # The data dir is throwaway; keep it in RAM to speed up the test run.
    tmpfs:
      - /var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U master"]
      interval: 2s
      timeout: 5s
      retries: 15
  postgres-target:
    image: postgres:16
    environment:
      - POSTGRES_USER=master
      - POSTGRES_PASSWORD=masterpw
    # The data dir is throwaway; keep it in RAM to speed up the test run.
    tmpfs:
      - /var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U master"]
      interval: 2s
      timeout: 5s
      retries: 15
  integration-test:
    platform: linux/amd64
    build:
      context: .
      dockerfile: Dockerfile.tests
    environment:
      - PYTHONDONTWRITEBYTECODE=1
      - TEST_ARGS=-v
      - SOURCE_DB_HOST=postgres-source
      - TARGET_DB_HOST=postgres-target
      - DB_MASTER_USER=master
      - DB_MASTER_PASSWORD=masterpw
    entrypoint: ["/var/task/integration-test.sh"]
    depends_on:
      postgres-source:
        condition: service_healthy
      postgres-target:
        condition: service_healthy
    volumes:
      - ./src:/var/task/src
      - ./tests:/var/task/tests
