
{#
Copyright 2017-present Open Networking Foundation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#}


version: '2'

# XOS docker compose
# generated by cord-profile/templates/docker-compose.yml.j2

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

services:
  consul:
    image: {{ pull_docker_registry }}gliderlabs/consul-server:{{ pull_docker_tag }}
    command: "-advertise=${MYHOST} -server -bootstrap"
    ports:
      - "127.0.0.1:8500:8500"
    networks:
{% for network in xos_docker_networks %}
      - {{ network }}
{% endfor %}
    environment:
      SERVICE_8300_IGNORE: "yes"
      SERVICE_8301_IGNORE: "yes"
      SERVICE_8302_IGNORE: "yes"
      SERVICE_8400_IGNORE: "yes"
      SERVICE_8500_NAME: "consul-rest"
      SERVICE_8600_IGNORE: "yes"
    restart: unless-stopped
  registrator:
    image: {{ pull_docker_registry }}gliderlabs/registrator:{{ pull_docker_tag }}
    command: [
         "-ip=${DOCKER_HOST_IP}",
         "-internal",
         "-retry-attempts", "100",
         "consul://consul:8500"
    ]
    networks:
{% for network in xos_docker_networks %}
      - {{ network }}
{% endfor %}
    links:
      - consul
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock
    depends_on:
      - consul
    restart: unless-stopped
  xos_db:
    image: {{ pull_docker_registry }}xosproject/xos-postgres:{{ pull_docker_tag }}
    networks:
{% for network in xos_docker_networks %}
      - {{ network }}
{% endfor %}
    expose:
      - "5432"
    depends_on:
      - registrator
    environment:
      SERVICE_5432_NAME: "xos-db"
    restart: unless-stopped

{% if use_redis %}
  xos_redis:
    image: {{ pull_docker_registry }}redis:{{ pull_docker_tag }}
    networks:
{% for network in xos_docker_networks %}
     - {{ network }}
{% endfor %}
    logging:
      driver: "json-file"
      options:
        max-size: "1000k"
        max-file: "5"
    depends_on:
      - registrator
    environment:
      SERVICE_NAME: "redis"
    restart: unless-stopped
{% endif %}

  xos_gui:
    image: {{ pull_docker_registry }}xosproject/xos-gui:{{ pull_docker_tag }}
    networks:
{% for network in xos_docker_networks %}
     - {{ network }}
{% endfor %}
    ports:
      - "4000:4000"
    links:
      - xos_ws:xos-ws
      - xos_chameleon:xos-chameleon
    depends_on:
      - xos_ws
      - xos_chameleon
    volumes:
      - {{ head_cord_profile_dir }}/style.config.js:/var/www/dist/style.config.js
      - {{ head_cord_profile_dir }}/app.config.js:/var/www/dist/app.config.js
    volumes_from:
      - gui_extensions_store
    logging:
      driver: "json-file"
      options:
        max-size: "1000k"
        max-file: "5"
    depends_on:
      - registrator
    environment:
      SERVICE_4000_NAME: "xos-gui"
      SERVICE_80_IGNORE: "yes"
    restart: unless-stopped

  xos_tosca:
    image: {{ pull_docker_registry }}xosproject/xos-tosca:{{ pull_docker_tag }}
    networks:
{% for network in xos_docker_networks %}
     - {{ network }}
{% endfor %}
    ports:
      - "9102:9102"
    links:
      - xos_core:xos-core
    volumes:
      - {{ head_cord_profile_dir }}/xos-tosca.config.yaml:/opt/xos-tosca/src/xos-tosca.config.yaml
      - {{ head_cord_profile_dir }}/im_cert_chain.pem:/usr/local/share/ca-certificates/local_certs.crt:ro
    depends_on:
      - xos_core
      - registrator
    logging:
      driver: "json-file"
      options:
        max-size: "1000k"
        max-file: "5"
    environment:
      SERVICE_9102_NAME: "xos-tosca"
    restart: unless-stopped

  xos_chameleon:
    image: {{ pull_docker_registry }}xosproject/chameleon:{{ pull_docker_tag }}
    networks:
{% for network in xos_docker_networks %}
     - {{ network }}
{% endfor %}
    command: python chameleon/chameleon/main.py -R 9101 -G xos-core:50055 --swagger-url /apidocs
    ports:
      - "9101:9101"
    links:
      - xos_core:xos-core
    depends_on:
      - xos_core
    logging:
      driver: "json-file"
      options:
        max-size: "1000k"
        max-file: "5"
    depends_on:
      - registrator
    environment:
      SERVICE_9101_NAME: "xos-rest"
    restart: unless-stopped

  gui_extensions_store:
    image: {{ pull_docker_registry }}node:{{ pull_docker_tag }}
    networks:
{% for network in xos_docker_networks %}
     - {{ network }}
{% endfor %}
    command: /bin/true
    volumes:
      - /var/www/dist/extensions
    logging:
      driver: "json-file"
      options:
        max-size: "1000k"
        max-file: "5"
    depends_on:
      - registrator

  xos_ws:
    image: {{ pull_docker_registry }}xosproject/xos-ws:{{ pull_docker_tag }}
    networks:
{% for network in xos_docker_networks %}
     - {{ network }}
{% endfor %}
    command: npm start -- --config gateway-config.yml
    ports:
      - "3000:3000"
    links:
      - xos_ui:xos
{% if use_redis %}
      - xos_redis:redis
{% endif %}
    depends_on:
      - xos_ui
{% if use_redis %}
      - xos_redis
{% endif %}
    volumes:
      - {{ head_cord_profile_dir }}/gateway-config.yml:/var/www/src/config/gateway-config.yml
    logging:
      driver: "json-file"
      options:
        max-size: "1000k"
        max-file: "5"
    depends_on:
      - registrator
    environment:
      SERVICE_3000_NAME: "xos-ws"
    restart: unless-stopped

  xos_ui:
    image: {{ pull_docker_registry }}xosproject/xos-ui:{{ pull_docker_tag }}
    networks:
{% for network in xos_docker_networks %}
     - {{ network }}
{% endfor %}
    command: python /opt/xos/manage.py runserver 0.0.0.0:9000
    ports:
      - "9000:9000"
    links:
      - xos_db:xos_db
      - consul:consul
{% if use_redis %}
      - xos_redis:redis
{% endif %}
    depends_on:
      - xos_db
{% if use_redis %}
      - xos_redis
{% endif %}
    volumes:
      - {{ head_cord_profile_dir }}/xos_config.yaml:/opt/xos/xos_config.yaml:ro
      - {{ head_cord_profile_dir }}:/opt/cord_profile:ro
      - {{ head_cord_profile_dir }}/im_cert_chain.pem:/usr/local/share/ca-certificates/local_certs.crt:ro
    logging:
      driver: "json-file"
      options:
        max-size: "1000k"
        max-file: "5"
    depends_on:
      - registrator
    environment:
      SERVICE_9000_NAME: "xos-ui-deprecated"
    restart: unless-stopped

  xos_core:
    image: {{ pull_docker_registry }}xosproject/xos-ui:{{ pull_docker_tag }}
    networks:
{% for network in xos_docker_networks %}
     - {{ network }}
{% endfor %}
    command: bash -c "cd coreapi; bash ./start_coreapi.sh"
    ports:
      - "50051:50051"
      - "50055:50055"
    links:
      - xos_db:xos_db
      - consul:consul
{% if use_redis %}
      - xos_redis:redis
{% endif %}
    depends_on:
      - xos_db
      - registrator
{% if use_redis %}
      - xos_redis
{% endif %}
    volumes:
      - {{ head_cord_profile_dir }}/xos_config.yaml:/opt/xos/xos_config.yaml:ro
      - {{ head_cord_profile_dir }}:/opt/cord_profile:ro
      - {{ head_cord_profile_dir }}/im_cert_chain.pem:/usr/local/share/ca-certificates/local_certs.crt:ro
      - {{ head_cord_profile_dir }}/initial_data.yaml:/opt/xos/core/migrations/initial_data.yaml:ro
      - /var/run/docker.sock:/var/run/docker.sock
    logging:
      driver: "json-file"
      options:
        max-size: "1000k"
        max-file: "5"
    environment:
      SERVICE_50051_NAME: "xos-grpc-secure"
      SERVICE_50055_NAME: "xos-grpc-insecure"
    restart: unless-stopped

{% for ext in enabled_gui_extensions %}
  gui-extension-{{ ext.name }}:
    image: {{ pull_docker_registry }}xosproject/gui-extension-{{ ext.name }}:{{ pull_docker_tag }}
    networks:
{% for network in xos_docker_networks %}
     - {{ network }}
{% endfor %}
    command: /bin/sh -c "mkdir -p /var/www/dist/extensions/{{ ext.name }}/ && cp -R /tmp/* /var/www/dist/extensions/{{ ext.name }}/"
    volumes_from:
      - gui_extensions_store
    logging:
      driver: "json-file"
      options:
        max-size: "1000k"
        max-file: "5"
    depends_on:
      - registrator
{% endfor %}

{% if not frontend_only %}
{% for svc in xos_services %}
{% if svc.synchronizer is not defined or svc.synchronizer %}
  {{ svc.name }}-synchronizer:
    image: {{ pull_docker_registry }}xosproject/{{ svc.name }}-synchronizer:{{ pull_docker_tag }}
    networks:
{% for network in xos_docker_networks %}
     - {{ network }}
{% endfor %}
    depends_on:
      - registrator
{% if use_redis %}
      - xos_redis
{% endif %}
    links:
      - consul:consul
{% if use_redis %}
      - xos_redis:redis
{% endif %}
    volumes:
      - {{ head_cord_profile_dir }}/xos_config_synchronizer.yaml:/opt/xos/xos_config.yaml:ro
      - {{ head_cord_profile_dir }}/node_key:/opt/cord_profile/node_key:ro
      - {{ head_credentials_dir }}:/opt/xos/services/{{ svc.name }}/credentials:ro
      - {{ head_cord_profile_dir }}/im_cert_chain.pem:/usr/local/share/ca-certificates/local_certs.crt:ro
{% if svc.keypair is defined %}
      - {{ head_cord_profile_dir }}/key_import/{{ svc.keypair }}:/opt/xos/services/{{ svc.name }}/keys/{{ svc.keypair }}:ro
{% endif %}
{% if svc.name == "openstack" %}
      - {{ head_cord_profile_dir }}/images:/opt/xos/images:ro
{% endif %}
    logging:
      driver: "json-file"
      options:
        max-size: "1000k"
        max-file: "5"
    environment:
      SERVICE_NAME: "xos-{{ svc.name }}-synchronizer"
    restart: unless-stopped

{% endif %}
{% endfor %}
{% endif %}
