---
services:

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

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

  unit-lint:
    extends:
      file: docker-compose.unit-lint.yml
      service: unit-lint

  update-snapshots:
    extends:
      file: docker-compose.unit-lint.yml
      service: unit-lint
    volumes:
      - ./tests:/var/app/tests
    environment:
      - SKIP_LINT=1
      - SKIP_TYPE_CHECKS=1
      - TEST_ARGS=--snapshot-update

  integration:
    platform: linux/amd64
    build:
      context: .
      target: integration
    environment:
      - TEST_ARGS=-v

  dev:
    platform: linux/amd64
    build:
      context: .
      target: dev
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:5000/hello/"]
      interval: 1m30s
      timeout: 10s
      retries: 3
      start_period: 40s
    ports:
      - "8888:5000"
    env_file:
      - path: ./.env
        required: false
    environment:
      - AWS_ACCESS_KEY_ID
      - AWS_SECRET_ACCESS_KEY
      - AWS_SESSION_TOKEN
      - AWS_REGION
    volumes:
      - ./delivery_metadata:/var/app/delivery_metadata
    stdin_open: true
    tty: true

  deploy:
    platform: linux/amd64
    build:
      context: .
      target: deploy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/hello/"]
      interval: 1m30s
      timeout: 10s
      retries: 3
      start_period: 40s
    deploy:
      resources:
        limits:
          cpus: "1.0"
          memory: 2048M
    ports:
      - "8888:8080"
    env_file:
      - path: ./.env
        required: false
    environment:
      - Environment=dev
      - AWS_ACCESS_KEY_ID
      - AWS_SECRET_ACCESS_KEY
      - AWS_SESSION_TOKEN
      - AWS_REGION
      - DD_ENV=dev
      - DD_SERVICE=ows-delivery-metadata
      - DD_AGENT_HOST=dev-datadog-agent.dev.theorchard.io
      - DD_TRACE_ENABLED=1
      - DD_PROFILING_ENABLED=1

  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

  test-dd-db:
    platform: linux/amd64
    image:
      086679231553.dkr.ecr.us-east-1.amazonaws.com/docker-database-images:direct-delivery-cluster
    pull_policy: always
    environment:
      DB_USER: ${TEST_DD_USER}
      DB_PASSWORD: ${TEST_DD_PASS}
    command: >
      --disable-log-bin
    tmpfs:
      - /var/lib/mysql
    healthcheck:
      interval: 1s
      timeout: 5s
      retries: 120
    deploy:
      resources:
        limits:
          cpus: '1.5'
