{% include 'roles/docker-compose/templates/base.yml.j2' %}

{% set service_name = TAIGA_SERVICE %}
  {{ service_name }}:
    container_name: {{ TAIGA_CONTAINER }}
    hostname:       {{ TAIGA_HOSTNAME }}
{% include 'roles/docker-container/templates/base.yml.j2' %}
    healthcheck:
      test: ["CMD", "python", "-c", "import socket; socket.create_connection(('127.0.0.1',8000),5).close()"]
      interval: 30s
      timeout: 5s
      retries: 5
      start_period: 40s
    image: "{{ TAIGA_DOCKER_IMAGE_BACKEND }}:{{ TAIGA_VERSION }}"
    volumes:
      # These volumens will be used by taiga-back and taiga-async.
      - static-data:{{ TAIGA_VOLUME_STATIC }}
      - media-data:{{ TAIGA_VOLUME_MEDIA }}
      # - ./config.py:/taiga-back/settings/config.py
{% if TAIGA_TAIGAIO_ENABLED | bool %}
      - {{ docker_compose.directories.config }}taiga-local.py:/taiga-back/settings/local.py:ro
{% endif %}
{% include 'roles/docker-container/templates/networks.yml.j2' %}
      taiga:
{% include 'roles/docker-container/templates/depends_on/dmbs_incl.yml.j2' %}
      {{ TAIGA_EVENTS_RABBITMQ_SERVICE }}:
        condition: service_started
      {{ TAIGA_ASYNC_RABBITMQ_SERVICE }}:
        condition: service_started
{% if TAIGA_TAIGAIO_ENABLED | bool %}
    command: >
      /bin/sh -c "
        pip install taiga-contrib-oidc-auth &&
        /taiga-back/docker/entrypoint.sh"
{% endif %}

{% set service_name = TAIGA_ASYNC_SERVICE %}
  {{ service_name }}:
    container_name: {{ TAIGA_CONTAINER }}-{{ service_name }}
{% include 'roles/docker-container/templates/base.yml.j2' %}
    healthcheck:
      test: ["CMD-SHELL", "tr '\\0' ' ' </proc/1/cmdline | grep -qi celery"]
      interval: 30s
      timeout: 5s
      retries: 5
      start_period: 60s
    image: "{{ TAIGA_DOCKER_IMAGE_BACKEND }}:{{ TAIGA_VERSION }}"
    entrypoint: ["/taiga-back/docker/async_entrypoint.sh"]
    volumes:
      # These volumens will be used by backend and async service
      - static-data:{{ TAIGA_VOLUME_STATIC }}
      - media-data:{{ TAIGA_VOLUME_MEDIA }}
      # - ./config.py:/taiga-back/settings/config.py
{% if TAIGA_TAIGAIO_ENABLED | bool %}
{% for item in TAIGA_SETTING_FILES %}
      - {{ docker_compose.directories.config }}taiga-{{ item }}.py:/taiga-back/settings/{{ item }}.py:ro
{% endfor %}
{% endif %}
{% include 'roles/docker-container/templates/networks.yml.j2' %}
      taiga:
{% include 'roles/docker-container/templates/depends_on/dmbs_incl.yml.j2' %}
      {{ TAIGA_EVENTS_RABBITMQ_SERVICE }}:
        condition: service_started
      {{ TAIGA_ASYNC_RABBITMQ_SERVICE }}:
        condition: service_started
{% if TAIGA_TAIGAIO_ENABLED | bool %}
    command: >
      /bin/sh -c "
        pip install taiga-contrib-oidc-auth &&
        /taiga-back/docker/entrypoint.sh"
{% endif %}

{% set service_name = TAIGA_ASYNC_RABBITMQ_SERVICE %}
  {{ service_name }}:
    container_name: {{ TAIGA_CONTAINER }}-{{ service_name }}
    image: rabbitmq:3.8-management-alpine
    hostname: "{{ TAIGA_ASYNC_RABBITMQ_SERVICE }}"
    volumes:
      - async-rabbitmq-data:/var/lib/rabbitmq
{% include 'roles/docker-container/templates/base.yml.j2' %}
    healthcheck:
      test: ["CMD", "rabbitmq-diagnostics", "-q", "ping"]
      interval: 30s
      timeout: 5s
      retries: 5
      start_period: 20s
{% include 'roles/docker-container/templates/networks.yml.j2' %}
      taiga:

{% set service_name = TAIGA_FRONT_SERVICE %}
{% set container_port = 80 %}
  {{ service_name }}:
    container_name: {{ TAIGA_CONTAINER }}-{{ service_name }}
    image: "{{TAIGA_DOCKER_IMAGE_FRONTEND}}:{{ TAIGA_VERSION }}"
{% include 'roles/docker-container/templates/base.yml.j2' %}
{% filter indent(4) %}
    {% include 'roles/docker-container/templates/healthcheck/http.yml.j2' %}
{% endfilter %}

{% include 'roles/docker-container/templates/networks.yml.j2' %}
      taiga:
#    volumes:
#      - {{ TAIGA_FRONTEND_CONF_PATH }}:/usr/share/nginx/html/conf.json:ro

{% set service_name = TAIGA_EVENTS_SERVICE %}
  {{ service_name }}:
    container_name: {{ TAIGA_CONTAINER }}-{{ service_name }}
    image: taigaio/taiga-events:latest
{% include 'roles/docker-container/templates/base.yml.j2' %}
    healthcheck:
      test: ["CMD-SHELL", "nc -z 127.0.0.1 8888"]
      interval: 30s
      timeout: 5s
      retries: 5
      start_period: 30s
{% include 'roles/docker-container/templates/networks.yml.j2' %}
      taiga:
    depends_on:
      {{ TAIGA_EVENTS_RABBITMQ_SERVICE }}:
        condition: service_started

{% set service_name = TAIGA_EVENTS_RABBITMQ_SERVICE %}
  {{ service_name }}:
    container_name: {{ TAIGA_CONTAINER }}-{{ service_name }}
    image: rabbitmq:3.8-management-alpine
    hostname: {{ service_name }}
    volumes:
      - events-rabbitmq-data:/var/lib/rabbitmq
{% include 'roles/docker-container/templates/base.yml.j2' %}
    healthcheck:
      test: ["CMD", "rabbitmq-diagnostics", "-q", "ping"]
      interval: 30s
      timeout: 5s
      retries: 5
      start_period: 20s
{% include 'roles/docker-container/templates/networks.yml.j2' %}
      taiga:

{% set service_name = 'protected' %}
  {{ service_name }}:
    container_name: {{ TAIGA_CONTAINER }}-{{ service_name }}
    image: taigaio/taiga-protected:latest
{% include 'roles/docker-container/templates/base.yml.j2' %}
    healthcheck:
      test: ["CMD", "python", "-c", "import socket; socket.create_connection(('127.0.0.1',8003),5).close()"]
      interval: 30s
      timeout: 5s
      retries: 5
      start_period: 20s
{% include 'roles/docker-container/templates/networks.yml.j2' %}
      taiga:

{% set service_name = 'gateway' %}
{% set container_port = 80 %}
  {{ service_name }}:
    container_name: {{ TAIGA_CONTAINER }}-{{ service_name }}
    image: nginx:alpine
    ports:
      - "127.0.0.1:{{ ports.localhost.http[application_id] }}:{{ container_port }}"
    volumes:
      - {{ docker_repository_path }}taiga-gateway/taiga.conf:/etc/nginx/conf.d/default.conf
      - static-data:/taiga/static
      - media-data:/taiga/media
{% include 'roles/docker-container/templates/base.yml.j2' %}
{% filter indent(4) %}
    {% include 'roles/docker-container/templates/healthcheck/http.yml.j2' %}
{% endfilter %}

{% include 'roles/docker-container/templates/networks.yml.j2' %}
      taiga:
    depends_on:
      - {{ TAIGA_FRONT_SERVICE }}
      - {{ TAIGA_SERVICE }}
      - {{ TAIGA_EVENTS_SERVICE }}
{% include 'roles/docker-compose/templates/volumes.yml.j2' %}
  static-data:
  media-data:
  async-rabbitmq-data:
  events-rabbitmq-data:

{% include 'roles/docker-compose/templates/networks.yml.j2' %}
  taiga: