version: '3'

services:

  master:
    build:
      context: ..
      dockerfile: integration_tests/Dockerfile.Master
    command: >
      bash -c "
      dockerize -wait tcp://mq:5672 -wait tcp://postgres:5432 -timeout 60s && 
      echo '########################################################' &&
      echo '  Running compat tests Master latest - Replica v1.3.1   ' &&
      echo '########################################################' &&
      ./run_integration_tests.sh
      "
    depends_on:
      - mq
      - replica
    volumes:
      - ./tests/:/master/integration_tests/tests
      - ../dj_cqrs:/master/dj_cqrs
    environment:
      - CQRS_MASTER_TRANSPORT=dj_cqrs.transport.RabbitMQTransport
      - CQRS_BROKER_URL=amqp://mq:5672/

  replica:
    build:
      context: ..
      dockerfile: integration_tests/Dockerfile.ReplicaV1
    image: django_cqrs_test_replica_v1
    command: >
      bash -c "
      dockerize -wait tcp://mq:5672 -wait tcp://postgres:5432 -timeout 60s && 
      python manage.py makemigrations --settings=integration_tests.replica_settings &&
      python manage.py makemigrations dj_replica --settings=integration_tests.replica_settings &&
      python manage.py migrate --settings=integration_tests.replica_settings &&
      python manage.py cqrs_consume -w 2 --settings=integration_tests.replica_settings
      "
    depends_on:
      - mq
      - postgres
    volumes:
      - ../dj_cqrs:/replica/dj_cqrs
    environment:
      - POSTGRES_HOST=postgres
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD=pswd
      - POSTGRES_DB=replica
      - CQRS_REPLICA_TRANSPORT=tests.dj.transport.RabbitMQTransportWithEvents
      - CQRS_BROKER_URL=amqp://mq:5672/