---
services:
  dev:
    platform: linux/amd64
    build:
      context: .
      target: dev
    volumes:
      - ./gridgen:/var/app/gridgen
      - ~/.ssh/snowflake:/var/app/.ssh/snowflake:ro
    ports:
     - "5000:5000"
    env_file:
      - path: ./.env
        required: false
    environment:
      - AWS_ACCESS_KEY_ID
      - AWS_SECRET_ACCESS_KEY
      - AWS_SESSION_TOKEN
      - AWS_REGION

  unit-lint:
    platform: linux/amd64
    build:
      context: .
      target: unit-lint
    environment:
      - Environment=test
      - SKIP_LINT=0
      - TEST_ARGS=-vv
      - AR_USER=${TEST_DB_USER}
      - AR_PASS=${TEST_DB_PASS}
      - AR_HOST=${TEST_DB_HOST}
      - AR_NAME
      - AR_PORT
    depends_on:
      test-ar-db:
        condition: service_healthy

  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
    ports:
      - "8889:8080"

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

  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
