version: '2'

# XOS bootstrap docker compose
# generated by platform-install/roles/cord-profile

networks:
{% for network in xos_docker_networks %}
  {{ network }}:
    external: true
{% endfor %}

services:
  xos_db:
    image: {{ deploy_docker_registry }}xosproject/xos-postgres:{{ deploy_docker_tag }}
    networks:
{% for network in xos_docker_networks %}
      - {{ network }}
{% endfor %}
    expose:
      - "5432"

{% if use_redis %}
  xos_redis:
    image: {{ deploy_docker_registry }}redis:{{ deploy_docker_tag }}
    networks:
{% for network in xos_docker_networks %}
     - {{ network }}
{% endfor %}
    logging:
      driver: "json-file"
      options:
        max-size: "1000k"
        max-file: "5"
{% endif %}

  xos_bootstrap_ui:
    image: {{ deploy_docker_registry }}xosproject/xos:{{ deploy_docker_tag }}
    command: python /opt/xos/manage.py runserver 0.0.0.0:{{ xos_bootstrap_ui_port }} --insecure --makemigrations
    networks:
{% for network in xos_docker_networks %}
     - {{ network }}
{% endfor %}
    labels:
      org.xosproject.kind: userinterface
      org.xosproject.target: bootstrap
    links:
      - xos_db
{% if use_redis %}
      - xos_redis:redis
{% endif %}
    volumes:
      - .:/opt/cord_profile:ro
      - ./xos_common_config:/opt/xos/xos_configuration/xos_common_config:ro
{% for service in xos_services %}
      - {{ cord_dir }}/{{ service.path }}:/opt/xos_services/{{ service.path | basename }}:ro
{% endfor %}
{% for library in xos_libraries %}
      - {{ cord_dir }}/orchestration/xos_libraries/{{ library }}:/opt/xos_libraries/{{ library }}:ro
{% endfor %}
{% for volume in xos_docker_volumes %}
      - {{ volume.host }}:{{ volume.container }}{{ ":rw" if (volume.read_only is defined and not volume.read_only ) else ":ro" }}
{% endfor %}
    ports:
      - "{{ xos_bootstrap_ui_port }}:{{ xos_bootstrap_ui_port }}"
    logging:
      driver: "json-file"
      options:
        max-size: "1000k"
        max-file: "5"
    depends_on:
      - xos_db
{% if use_redis %}
      - xos_redis
{% endif %}

  xos_synchronizer_onboarding:
    image: {{ deploy_docker_registry }}xosproject/xos:{{ deploy_docker_tag }}
    command: bash -c "cd /opt/xos/synchronizers/onboarding; ./run.sh"
    networks:
{% for network in xos_docker_networks %}
     - {{ network }}
{% endfor %}
    labels:
      org.xosproject.kind: synchronizer
      org.xosproject.target: onboarding
    links:
      - xos_db
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./key_import:/opt/xos/key_import:ro
      - ./onboarding-docker-compose:/opt/xos/synchronizers/onboarding/docker-compose
{% for service in xos_services %}
      - {{ cord_dir }}/{{ service.path }}:/opt/xos_services/{{ service.path | basename }}:ro
{% endfor %}
{% for library in xos_libraries %}
      - {{ cord_dir }}/orchestration/xos_libraries/{{ library }}:/opt/xos_libraries/{{ library }}:ro
{% endfor %}
    logging:
      driver: "json-file"
      options:
        max-size: "1000k"
        max-file: "5"
    depends_on:
      - xos_db
