---
services:
  dev:
    platform: linux/amd64
    build:
      context: .
      target: dev
    env_file:
      - path: ./.env
        required: false
    volumes:
      - ./carveouts:/var/app/carveouts
      - ./application.py:/var/app/application.py
      - ./tests:/var/app/tests
    ports:
      - "5000:5000"

  integration:
    platform: linux/amd64
    build:
      context: .
      target: integration
    environment:
      - TEST_ARGS=-v
      - QA_BASE_URL=${QA_BASE_URL:-https://qa-ows-carveouts-python.theorchard.io}
      - REQUEST_TIMEOUT=${REQUEST_TIMEOUT:-30}

  unit-lint:
    platform: linux/amd64
    build:
      context: .
      target: unit-lint
    environment:
      - AR_USER=${TEST_DB_USER}
      - AR_PASS=${TEST_DB_PASS}
      - AR_HOST=${TEST_DB_HOST}
      - AR_DBNAME=${TEST_DB_NAME}
      - TEST_ARGS=-v
      - SKIP_TYPE_CHECKS
    depends_on:
      test-ar-db:
        condition: service_healthy

  deploy:
    platform: linux/amd64
    build:
      context: .
      target: deploy
    env_file:
      - path: ./.env
        required: false
    environment:
      - AWS_ACCESS_KEY_ID
      - AWS_SECRET_ACCESS_KEY
      - AWS_SESSION_TOKEN
      - AWS_REGION
      - DD_TRACE_ENABLED=false
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/hello/"]
      interval: 1m30s
      timeout: 10s
      retries: 3
      start_period: 40s
    ports:
      - "8080:8080"

  update-lockfile:
    platform: linux/amd64
    build:
      context: .
      target: update-lockfile
    volumes:
      - ./poetry.lock:/var/app/poetry.lock

  test-ar-db:
    platform: linux/amd64
    image:
      086679231553.dkr.ecr.us-east-1.amazonaws.com/docker-database-images:art-relations
    pull_policy: always
    environment:
      DB_USER: ${TEST_DB_USER}
      DB_PASSWORD: ${TEST_DB_PASS}
    command: >
      --disable-log-bin
    tmpfs:
      - /var/lib/mysql
    healthcheck:
      interval: 1s
      timeout: 5s
      retries: 180

  format:
    platform: linux/amd64
    build:
      context: .
      target: format
    volumes:
      - ./:/var/app
