---

services:

  lint-and-test:
    build:
      context: .
      target: lint-and-test
    volumes:
      - ./build:/var/app/build
    depends_on:
      test-ows-db:
        condition: service_healthy
      test-ar-db:
        condition: service_healthy
    environment:
      SKIP_LINT: 0
      Environment: dev
      AR_DB_USER: dbuser
      AR_DB_PASSWORD: dbpass
      AR_DB_HOST: test-ar-db
      DB_USER: rdsuser
      DB_PASSWORD: rdspass
      DB_HOST: test-ows-db
      DELIVERY_XML_S3_BUCKET_NAME: test-bucket
  dev:
    env_file: .env
    # Pass through host AWS credentials so boto3 (e.g. the S3 delivery-XML
    # reader) can authenticate locally. In qa/prod the task IAM role provides
    # these, so they are only needed for local runs.
    environment:
      AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
      AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
      AWS_SESSION_TOKEN: ${AWS_SESSION_TOKEN}
    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"
  deploy:
    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"

  test-ows-db:
    platform: linux/amd64
    image:
      086679231553.dkr.ecr.us-east-1.amazonaws.com/docker-database-images:ows-delivery-history
    pull_policy: always
    environment:
      DB_USER: rdsuser
      DB_PASSWORD: rdspass
    command: >
      --disable-log-bin
    tmpfs:
      - /var/lib/mysql
    healthcheck:
      interval: 1s
      timeout: 5s
      retries: 180

  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: dbuser
      DB_PASSWORD: dbpass
    command: >
      --disable-log-bin
    tmpfs:
      - /var/lib/mysql
    healthcheck:
      interval: 1s
      timeout: 5s
      retries: 180
