version: "3"


services:

  postgres:
    restart: always
    build:
      context: .
      dockerfile: dockerfiles/postgres/Dockerfile
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: $POSTGRES_PASSWORD
      POSTGRES_DB: sprint
    volumes:
      - /sprint-data/postgres-data:/var/lib/postgresql/data
    ports:
      - "5432:5432"

  migrations:
    image: mathwave/sprint-repo:sprint
    command: ./manage.py migrate
    depends_on:
      - postgres

  web:
    image: mathwave/sprint-repo:sprint
    restart: always
    environment:
      PORT: $PORT
      HOST: $HOST
    command: scripts/runserver.sh
    ports:
      - "${PORT}:${PORT}"
    depends_on:
      - migrations
      - rabbitmq
      - storage

  storage:
    restart: always
    image: mathwave/sprint-repo:sprint
    command: python manage.py storage
    ports:
      - "5555:5555"
    volumes:
      - /sprint-data/data:/usr/src/app/data

  bot:
    image: mathwave/sprint-repo:sprint
    restart: always
    environment:
      HOST: $HOST
    command: python manage.py bot
    depends_on:
      - web

  rabbitmq:
    restart: always
    build:
      context: .
      dockerfile: dockerfiles/rabbitmq/Dockerfile
    ports:
      - "15672:15672"
      - "5672:5672"

  worker:
    restart: always
    image: mathwave/sprint-repo:sprint
    privileged: true
    command: python manage.py receive
    environment:
      SOLUTIONS_ROOT_EXTERNAL: "${SOLUTIONS_ROOT_EXTERNAL}"
      HOST: $HOST
    depends_on:
      - web
      - rabbitmq
      - migrations
      - storage
    volumes:
      - /sprint-data/solutions:/usr/src/app/solutions
      - /var/run/docker.sock:/var/run/docker.sock