---
services:
  moto:
    image: motoserver/moto:5.1.2
    ports:
      - "5000:5000"
    environment:
      - AWS_DEFAULT_REGION=us-east-1
      - AWS_ACCESS_KEY_ID=test
      - AWS_SECRET_ACCESS_KEY=test

  fmt:
    platform: linux/amd64
    build:
      context: .
      target: unit-lint
    volumes:
      - ./src:/var/app/src
      - ./tests:/var/app/tests
    entrypoint: []
    command:
      - sh
      - -c
      - "ruff check src tests --fix && ruff format src tests"

  unit-lint:
    platform: linux/amd64
    build:
      context: .
      target: unit-lint
    volumes:
      - ./src:/var/app/src
      - ./tests:/var/app/tests
    environment:
      SKIP_LINT: 0
      SKIP_TESTS: 0
      TEST_ARGS: -v
      SKIP_COV: 0
    entrypoint: []
    command: ./lint-and-test.sh

  lockfile:
    platform: linux/amd64
    build:
      context: .
      target: base
    entrypoint: []
    command: ["poetry", "update"]
    volumes:
      - ./pyproject.toml:/var/app/pyproject.toml
      - ./poetry.lock:/var/app/poetry.lock

  function:
    platform: linux/amd64
    build:
      context: .
      target: deploy
    environment:
      - DD_ENV=dev
      - DD_SERVICE=renew-manager
      - DD_TRACE_ENABLED=false
      - DD_ENHANCED_METRICS=false
      - AWS_ACCESS_KEY_ID
      - AWS_SECRET_ACCESS_KEY
      - AWS_SESSION_TOKEN
      - AWS_PROFILE
      - AWS_REGION
      # Override only the SQS endpoint
      - AWS_ENDPOINT_URL_SQS=http://moto:5000
    env_file:
      - path: .env
        required: false
    depends_on:
      - moto
