From 1fe4513623eaa56f50744f8d5c000057d60a8e6a Mon Sep 17 00:00:00 2001
From: liyingjun <yingjun.li@kylin-cloud.com>
Date: Tue, 27 Sep 2016 09:54:28 +0800
Subject: [PATCH] Support Searchlight Docker container

This patch adds Searchlight Dockerfile to build container from source.

Change-Id: Ia28f54ddd9793699153e254b6379f3b6334482b0
Partial-implements: bp support-searchlight-deployment
---
 .../searchlight/searchlight-api/Dockerfile.j2 | 20 +++++++++++++
 .../searchlight-api/extend_start.sh           |  8 +++++
 .../searchlight-base/Dockerfile.j2            | 30 +++++++++++++++++++
 .../searchlight-base/extend_start.sh          | 10 +++++++
 .../searchlight-listener/Dockerfile.j2        | 17 +++++++++++
 kolla/common/config.py                        |  7 ++++-
 tests/test_build.py                           |  3 ++
 7 files changed, 94 insertions(+), 1 deletion(-)
 create mode 100644 docker/searchlight/searchlight-api/Dockerfile.j2
 create mode 100644 docker/searchlight/searchlight-api/extend_start.sh
 create mode 100644 docker/searchlight/searchlight-base/Dockerfile.j2
 create mode 100644 docker/searchlight/searchlight-base/extend_start.sh
 create mode 100644 docker/searchlight/searchlight-listener/Dockerfile.j2

diff --git a/docker/searchlight/searchlight-api/Dockerfile.j2 b/docker/searchlight/searchlight-api/Dockerfile.j2
new file mode 100644
index 0000000000..1f4797e039
--- /dev/null
+++ b/docker/searchlight/searchlight-api/Dockerfile.j2
@@ -0,0 +1,20 @@
+FROM {{ namespace }}/{{ image_prefix }}searchlight-base:{{ tag }}
+MAINTAINER {{ maintainer }}
+
+{% block searchlight_api_header %}{% endblock %}
+
+{% if install_type == 'binary' %}
+
+RUN echo '{{ install_type }} not yet available for {{ base_distro }}' \
+    && /bin/false
+
+{% endif %}
+
+COPY extend_start.sh /usr/local/bin/kolla_searchlight_extend_start
+RUN chmod 755 /usr/local/bin/kolla_searchlight_extend_start
+
+{% block searchlight_api_footer %}{% endblock %}
+{% block footer %}{% endblock %}
+{{ include_footer }}
+
+USER searchlight
diff --git a/docker/searchlight/searchlight-api/extend_start.sh b/docker/searchlight/searchlight-api/extend_start.sh
new file mode 100644
index 0000000000..3b6339dc67
--- /dev/null
+++ b/docker/searchlight/searchlight-api/extend_start.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+# Bootstrap and exit if KOLLA_BOOTSTRAP variable is set. This catches all cases
+# of the KOLLA_BOOTSTRAP variable being set, including empty.
+if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then
+    searchlight-manage index sync --force
+    exit 0
+fi
diff --git a/docker/searchlight/searchlight-base/Dockerfile.j2 b/docker/searchlight/searchlight-base/Dockerfile.j2
new file mode 100644
index 0000000000..a5fa4995fc
--- /dev/null
+++ b/docker/searchlight/searchlight-base/Dockerfile.j2
@@ -0,0 +1,30 @@
+FROM {{ namespace }}/{{ image_prefix }}openstack-base:{{ tag }}
+MAINTAINER {{ maintainer }}
+
+{% block searchlight_base_header %}{% endblock %}
+
+{% if install_type == 'binary' %}
+
+RUN echo '{{ install_type }} not yet available for {{ base_distro }}' \
+    && /bin/false
+
+{% elif install_type == 'source' %}
+
+ADD searchlight-base-archive /searchlight-base-source
+RUN ln -s searchlight-base-source/* searchlight \
+    && useradd --user-group searchlight \
+    && /var/lib/kolla/venv/bin/pip --no-cache-dir install --upgrade -c requirements/upper-constraints.txt /searchlight \
+    && mkdir -p /etc/searchlight \
+    && cp -r /searchlight/etc/* /etc/searchlight \
+    && chown -R searchlight: /etc/searchlight
+
+{% endif %}
+
+COPY extend_start.sh /usr/local/bin/kolla_extend_start
+
+RUN usermod -a -G kolla searchlight \
+    && touch /usr/local/bin/kolla_searchlight_extend_start \
+    && chmod 755 /usr/local/bin/kolla_extend_start /usr/local/bin/kolla_searchlight_extend_start
+
+{% block searchlight_base_footer %}{% endblock %}
+{% block footer %}{% endblock %}
diff --git a/docker/searchlight/searchlight-base/extend_start.sh b/docker/searchlight/searchlight-base/extend_start.sh
new file mode 100644
index 0000000000..d1a8ea4fb5
--- /dev/null
+++ b/docker/searchlight/searchlight-base/extend_start.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+if [[ ! -d "/var/log/kolla/searchlight" ]]; then
+    mkdir -p /var/log/kolla/searchlight
+fi
+if [[ $(stat -c %a /var/log/kolla/searchlight) != "755" ]]; then
+    chmod 755 /var/log/kolla/searchlight
+fi
+
+. /usr/local/bin/kolla_searchlight_extend_start
diff --git a/docker/searchlight/searchlight-listener/Dockerfile.j2 b/docker/searchlight/searchlight-listener/Dockerfile.j2
new file mode 100644
index 0000000000..ddba8713b9
--- /dev/null
+++ b/docker/searchlight/searchlight-listener/Dockerfile.j2
@@ -0,0 +1,17 @@
+FROM {{ namespace }}/{{ image_prefix }}searchlight-base:{{ tag }}
+MAINTAINER {{ maintainer }}
+
+{% block searchlight_listener_header %}{% endblock %}
+
+{% if install_type == 'binary' %}
+
+RUN echo '{{ install_type }} not yet available for {{ base_distro }}' \
+    && /bin/false
+
+{% endif %}
+
+{% block searchlight_listener_footer %}{% endblock %}
+{% block footer %}{% endblock %}
+{{ include_footer }}
+
+USER searchlight
diff --git a/kolla/common/config.py b/kolla/common/config.py
index 0067d106da..6ffcdd53f1 100644
--- a/kolla/common/config.py
+++ b/kolla/common/config.py
@@ -48,7 +48,8 @@ _PROFILE_OPTS = [
                 default=['aodh', 'cloudkitty', 'congress', 'designate',
                          'gnocchi', 'influxdb', 'ironic', 'kuryr', 'magnum',
                          'manila', 'mistral', 'murano', 'rally', 'sahara',
-                         'senlin', 'telegraf', 'trove', 'zaqar'],
+                         'searchlight', 'senlin', 'telegraf', 'trove',
+                         'zaqar'],
                 help='Aux Images'),
     cfg.ListOpt('default',
                 default=['cron', 'kolla-toolbox', 'glance', 'haproxy',
@@ -281,6 +282,10 @@ SOURCES = {
         'type': 'url',
         'location': ('http://tarballs.openstack.org/sahara/'
                      'sahara-5.0.0.tar.gz')},
+    'searchlight-base': {
+        'type': 'url',
+        'location': ('http://tarballs.openstack.org/searchlight/'
+                     'searchlight-1.0.0.tar.gz')},
     'senlin-base': {
         'type': 'url',
         'location': ('http://tarballs.openstack.org/senlin/'
diff --git a/tests/test_build.py b/tests/test_build.py
index a225f73011..1a89821e06 100644
--- a/tests/test_build.py
+++ b/tests/test_build.py
@@ -67,6 +67,7 @@ class BuildTest(object):
 class BuildTestCentosBinary(BuildTest, base.BaseTestCase):
     excluded_images = ["kuryr-base",
                        "neutron-sfc-agent",
+                       "searchlight-base",
                        "senlin-base",
                        "vmtp",
                        "watcher-base",
@@ -92,6 +93,7 @@ class BuildTestCentosSource(BuildTest, base.BaseTestCase):
 class BuildTestUbuntuBinary(BuildTest, base.BaseTestCase):
     excluded_images = ["kuryr-base",
                        "neutron-sfc-agent",
+                       "searchlight-base",
                        "senlin-base",
                        "vmtp",
                        "zaqar",
@@ -118,6 +120,7 @@ class BuildTestUbuntuSource(BuildTest, base.BaseTestCase):
 class BuildTestOracleLinuxBinary(BuildTest, base.BaseTestCase):
     excluded_images = ["kuryr-base",
                        "neutron-sfc-agent",
+                       "searchlight-base",
                        "senlin-base",
                        "vmtp",
                        "watcher-base",