From e70f8e14394f444032e4dabeda6ffdc3cd6ef4a4 Mon Sep 17 00:00:00 2001
From: MD NADEEM <mail2nadeem92@gmail.com>
Date: Thu, 14 Apr 2016 12:08:30 +0530
Subject: [PATCH] Add Dockerfile for congress

Change-Id: I30c4d7929940c751bf88c4bf9a0e200025ebd5c8
Partially-Implements: blueprint enable-congress-container
---
 docker/congress/congress-api/Dockerfile.j2    | 11 +++++
 docker/congress/congress-api/extend_start.sh  |  8 ++++
 docker/congress/congress-base/Dockerfile.j2   | 43 +++++++++++++++++++
 docker/congress/congress-base/extend_start.sh | 10 +++++
 .../congress-datasource/Dockerfile.j2         |  8 ++++
 .../congress-policy-engine/Dockerfile.j2      |  8 ++++
 kolla/common/config.py                        |  7 ++-
 tests/test_build.py                           | 12 +++---
 8 files changed, 100 insertions(+), 7 deletions(-)
 create mode 100644 docker/congress/congress-api/Dockerfile.j2
 create mode 100644 docker/congress/congress-api/extend_start.sh
 create mode 100644 docker/congress/congress-base/Dockerfile.j2
 create mode 100644 docker/congress/congress-base/extend_start.sh
 create mode 100644 docker/congress/congress-datasource/Dockerfile.j2
 create mode 100644 docker/congress/congress-policy-engine/Dockerfile.j2

diff --git a/docker/congress/congress-api/Dockerfile.j2 b/docker/congress/congress-api/Dockerfile.j2
new file mode 100644
index 000000000..b23548746
--- /dev/null
+++ b/docker/congress/congress-api/Dockerfile.j2
@@ -0,0 +1,11 @@
+FROM {{ namespace }}/{{ image_prefix }}congress-base:{{ tag }}
+MAINTAINER {{ maintainer }}
+
+COPY extend_start.sh /usr/local/bin/kolla_congress_extend_start
+RUN chmod 755 /usr/local/bin/kolla_congress_extend_start
+
+{% block congress_api_footer %}{% endblock %}
+{% block footer %}{% endblock %}
+{{ include_footer }}
+
+USER congress
diff --git a/docker/congress/congress-api/extend_start.sh b/docker/congress/congress-api/extend_start.sh
new file mode 100644
index 000000000..b18446d7f
--- /dev/null
+++ b/docker/congress/congress-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
+    congress-db-manage --config-file /etc/congress/congress.conf upgrade head
+    exit 0
+fi
diff --git a/docker/congress/congress-base/Dockerfile.j2 b/docker/congress/congress-base/Dockerfile.j2
new file mode 100644
index 000000000..2a6964387
--- /dev/null
+++ b/docker/congress/congress-base/Dockerfile.j2
@@ -0,0 +1,43 @@
+FROM {{ namespace }}/{{ image_prefix}}openstack-base:{{ tag }}
+MAINTAINER {{ maintainer }}
+{% import "macros.j2" as macros with context %}
+
+{% if install_type == 'binary' %}
+    {% if base_distro in ['ubuntu'] %}
+        {% set congress_base_packages = [
+            'congress-common',
+            'congress-server']
+         %}
+
+# TODO(Md Nadeem): need to add congress binary package when it is available in rpm base distro
+#https://trunk.rdoproject.org/
+    {% elif base_distro in ['centos', 'fedora', 'oraclelinux', 'rhel'] %}
+
+RUN echo '{{ install_type }} not yet available for {{ base_distro }}' \
+    && /bin/false
+
+    {% endif %}
+
+RUN {{ macros.install_packages(congress_base_packages | customizable("packages")) }}
+
+{% elif install_type == 'source' %}
+
+ADD congress-base-archive /congress-base-source
+RUN ln -s congress-base-source/* congress \
+    && useradd --user-group congress \
+    && /var/lib/kolla/venv/bin/pip --no-cache-dir install --upgrade -c requirements/upper-constraints.txt /congress \
+    && mkdir -p /etc/congress /home/congress \
+    && cp -r /congress/etc/* /etc/congress/ \
+    && chown -R congress: /etc/congress /home/congress
+
+{% endif %}
+
+COPY extend_start.sh /usr/local/bin/kolla_extend_start
+
+RUN usermod -a -G kolla congress \
+    && touch /usr/local/bin/kolla_congress_extend_start \
+    && chmod 755 /usr/local/bin/kolla_extend_start /usr/local/bin/kolla_congress_extend_start
+
+{% block congress_base_footer %}{% endblock %}
+{% block footer %}{% endblock %}
+{{ include_footer }}
\ No newline at end of file
diff --git a/docker/congress/congress-base/extend_start.sh b/docker/congress/congress-base/extend_start.sh
new file mode 100644
index 000000000..99e16e1bf
--- /dev/null
+++ b/docker/congress/congress-base/extend_start.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+if [[ ! -d "/var/log/kolla/congress" ]]; then
+    mkdir -p /var/log/kolla/congress
+fi
+if [[ $(stat -c %a /var/log/kolla/congress) != "755" ]]; then
+    chmod 755 /var/log/kolla/congress
+fi
+
+. /usr/local/bin/kolla_congress_extend_start
diff --git a/docker/congress/congress-datasource/Dockerfile.j2 b/docker/congress/congress-datasource/Dockerfile.j2
new file mode 100644
index 000000000..5a62891ec
--- /dev/null
+++ b/docker/congress/congress-datasource/Dockerfile.j2
@@ -0,0 +1,8 @@
+FROM {{ namespace }}/{{ image_prefix }}congress-base:{{ tag }}
+MAINTAINER {{ maintainer }}
+
+{% block congress_datasource_footer %}{% endblock %}
+{% block footer %}{% endblock %}
+{{ include_footer }}
+
+USER congress
diff --git a/docker/congress/congress-policy-engine/Dockerfile.j2 b/docker/congress/congress-policy-engine/Dockerfile.j2
new file mode 100644
index 000000000..6a1a6d056
--- /dev/null
+++ b/docker/congress/congress-policy-engine/Dockerfile.j2
@@ -0,0 +1,8 @@
+FROM {{ namespace }}/{{ image_prefix }}congress-base:{{ tag }}
+MAINTAINER {{ maintainer }}
+
+{% block congress_policy_engine_footer %}{% endblock %}
+{% block footer %}{% endblock %}
+{{ include_footer }}
+
+USER congress
diff --git a/kolla/common/config.py b/kolla/common/config.py
index 9bb51ab6c..2f5c43673 100644
--- a/kolla/common/config.py
+++ b/kolla/common/config.py
@@ -45,7 +45,8 @@ _PROFILE_OPTS = [
                 help='Main images'),
     cfg.ListOpt('aux',
                 default=['aodh', 'designate', 'gnocchi', 'ironic',
-                         'magnum', 'mistral', 'trove,' 'zaqar', 'zookeeper'],
+                         'magnum', 'mistral', 'trove,' 'zaqar', 'zookeeper',
+                         'congress'],
                 help='Aux Images'),
     cfg.ListOpt('default',
                 default=['cron', 'kolla-toolbox', 'glance', 'haproxy',
@@ -178,6 +179,10 @@ SOURCES = {
         'type': 'url',
         'location': ('http://tarballs.openstack.org/cinder/'
                      'cinder-master.tar.gz')},
+    'congress-base': {
+        'type': 'url',
+        'location': ('http://tarballs.openstack.org/congress/'
+                     'congress-master.tar.gz')},
     'designate-base': {
         'type': 'url',
         'location': ('http://tarballs.openstack.org/designate/'
diff --git a/tests/test_build.py b/tests/test_build.py
index 76fabc48f..d0ea83813 100644
--- a/tests/test_build.py
+++ b/tests/test_build.py
@@ -71,8 +71,8 @@ class BuildTestCentosBinary(BuildTest, base.BaseTestCase):
                        "neutron-networking-sfc-agent",
                        "senlin-base",
                        "vmtp",
-                       "watcher-base"
-                       ]
+                       "watcher-base",
+                       "congress-base"]
 
     def setUp(self):
         super(BuildTestCentosBinary, self).setUp()
@@ -93,8 +93,8 @@ class BuildTestCentosSource(BuildTest, base.BaseTestCase):
 class BuildTestUbuntuBinary(BuildTest, base.BaseTestCase):
     excluded_images = ["neutron-networking-sfc-agent",
                        "vmtp",
-                       "zaqar"
-                       ]
+                       "zaqar",
+                       "congress-base"]
 
     def setUp(self):
         super(BuildTestUbuntuBinary, self).setUp()
@@ -116,8 +116,8 @@ class BuildTestOracleLinuxBinary(BuildTest, base.BaseTestCase):
                        "neutron-networking-sfc-agent",
                        "senlin-base",
                        "vmtp",
-                       "watcher-base"
-                       ]
+                       "watcher-base",
+                       "congress-base"]
 
     def setUp(self):
         super(BuildTestOracleLinuxBinary, self).setUp()
-- 
GitLab