From 55b184a865776be10c039f17bc91038d8ebbdf52 Mon Sep 17 00:00:00 2001 From: zhubingbing <1392607554@qq.com> Date: Thu, 28 Jul 2016 14:28:20 +0000 Subject: [PATCH] repair gnocchi dockerfile 1. Add the missing packages in the gnocchi image packages: lz4 sqlalchemy_utils gnocchiclient 2. gnocchi config path is error gnocchi config path is /gnocchi/etc/gnocchi 3. gnocchi sync db command is error sync db command is: gnocchi-upgrade Reference link: http://docs.openstack.org/developer/gnocchi/install.html 4. gnocchi log directory is /var/log/kolla/gnocchi 5. Add gnocchi-api running as a mod_wsgi Reference link: http://docs.openstack.org/developer/gnocchi/running.html 6. Add gnocchi sudoers file Closes-Bug: #1607332 Change-Id: Id3aded82706ffd204373c97a020980d0d9b72663 --- docker/gnocchi/gnocchi-api/Dockerfile.j2 | 2 - docker/gnocchi/gnocchi-api/extend_start.sh | 12 +++- docker/gnocchi/gnocchi-base/Dockerfile.j2 | 74 ++++++++++++++++++--- docker/gnocchi/gnocchi-base/extend_start.sh | 15 +++++ docker/gnocchi/gnocchi-base/gnocchi_sudoers | 1 + tests/test_build.py | 3 +- 6 files changed, 92 insertions(+), 15 deletions(-) create mode 100644 docker/gnocchi/gnocchi-base/extend_start.sh create mode 100644 docker/gnocchi/gnocchi-base/gnocchi_sudoers diff --git a/docker/gnocchi/gnocchi-api/Dockerfile.j2 b/docker/gnocchi/gnocchi-api/Dockerfile.j2 index 29482f237a..64517108bb 100644 --- a/docker/gnocchi/gnocchi-api/Dockerfile.j2 +++ b/docker/gnocchi/gnocchi-api/Dockerfile.j2 @@ -21,5 +21,3 @@ RUN chmod 755 /usr/local/bin/kolla_gnocchi_extend_start {% block gnocchi_api_footer %}{% endblock %} {% block footer %}{% endblock %} {{ include_footer }} - -USER gnocchi diff --git a/docker/gnocchi/gnocchi-api/extend_start.sh b/docker/gnocchi/gnocchi-api/extend_start.sh index aeb3d07d03..ac06893c86 100644 --- a/docker/gnocchi/gnocchi-api/extend_start.sh +++ b/docker/gnocchi/gnocchi-api/extend_start.sh @@ -1,8 +1,18 @@ #!/bin/bash +# NOTE(pbourke): httpd will not clean up after itself in some cases which +# results in the container not being able to restart. (bug #1489676, 1557036) +if [[ "${KOLLA_BASE_DISTRO}" =~ debian|ubuntu ]]; then + # Loading Apache2 ENV variables + source /etc/apache2/envvars + rm -rf /var/run/apache2/* +else + rm -rf /var/run/httpd/* /run/httpd/* /tmp/httpd* +fi + # 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 - gnocchi-manage db_sync + gnocchi-upgrade --logfile /var/log/kolla/gnocchi/gnocchi-upgrade.log exit 0 fi diff --git a/docker/gnocchi/gnocchi-base/Dockerfile.j2 b/docker/gnocchi/gnocchi-base/Dockerfile.j2 index 740a9815c4..eeb566ddd4 100644 --- a/docker/gnocchi/gnocchi-base/Dockerfile.j2 +++ b/docker/gnocchi/gnocchi-base/Dockerfile.j2 @@ -4,24 +4,78 @@ MAINTAINER {{ maintainer }} {% import "macros.j2" as macros with context %} {% if install_type == 'binary' %} + {% if base_distro in ['fedora', 'centos', 'oraclelinux', 'rhel'] %} + + {% set gnocchi_base_packages = [ + 'openstack-gnocchi-common', + 'python-gnocchiclient', + 'httpd', + 'mod_wsgi', + 'python-ldappool' + ] %} -{% if base_distro in ['centos', 'fedora', 'oraclelinux', 'rhel'] %} - {% set gnocchi_base_packages = ['openstack-gnocchi-common'] %} -{% elif base_distro in ['ubuntu'] %} - {% set gnocchi_base_packages = ['gnocchi-common'] %} -{% endif %} {{ macros.install_packages(gnocchi_base_packages | customizable("packages")) }} +RUN mkdir -p /var/www/cgi-bin/gnocchi \ + && cp -a /usr/lib/python2.7/site-packages/gnocchi/rest/app.wsgi /var/www/cgi-bin/gnocchi/app \ + && sed -i -r 's,^(Listen 80),#\1,' /etc/httpd/conf/httpd.conf + {% elif base_distro in ['ubuntu'] %} + + {% set gnocchi_base_packages = [ + 'gnocchi-common', + 'apache2', + 'libapache2-mod-wsgi', + 'python-ldappool' + ] %} +{{ macros.install_packages(gnocchi_base_packages | customizable("packages")) }} +RUN mkdir -p /var/www/cgi-bin/gnocchi \ + && cp -a /usr/share/gnocchi-common/app.wsgi /var/www/cgi-bin/gnocchi/app \ + && echo > /etc/apache2/ports.conf + + {% endif %} {% elif install_type == 'source' %} + {% if base_distro in ['fedora', 'centos', 'oraclelinux', 'rhel'] %} + + {% set gnocchi_base_packages = [ + 'httpd', + 'mod_wsgi', + 'python-ldappool' + ] %} +{{ macros.install_packages(gnocchi_base_packages | customizable("packages")) }} +RUN mkdir -p /var/www/cgi-bin/gnocchi \ + && sed -i -r 's,^(Listen 80),#\1,' /etc/httpd/conf/httpd.conf + {% elif base_distro in ['ubuntu', 'debian'] %} + + {% set gnocchi_base_packages = [ + 'apache2', + 'libapache2-mod-wsgi', + 'python-ldappool' + ] %} +{{ macros.install_packages(gnocchi_base_packages | customizable("packages")) }} +RUN echo > /etc/apache2/ports.conf + + {% endif %} ADD gnocchi-base-archive /gnocchi-base-source + RUN ln -s gnocchi-base-source/* gnocchi \ && useradd --user-group gnocchi \ - && /var/lib/kolla/venv/bin/pip --no-cache-dir install --upgrade -c requirements/upper-constraints.txt tooz /gnocchi \ - && mkdir -p /etc/gnocchi /var/log/gnocchi /home/gnocchi \ - && cp -r /gnocchi/etc/* /etc/gnocchi/ \ - && chown -R gnocchi: /etc/gnocchi /var/log/gnocchi /home/gnocchi + && /var/lib/kolla/venv/bin/pip --no-cache-dir install --upgrade -c requirements/upper-constraints.txt tooz lz4 sqlalchemy_utils gnocchiclient /gnocchi \ + && mkdir -p /etc/gnocchi /var/log/kolla/gnocchi /home/gnocchi /var/www/cgi-bin/gnocchi \ + && cp -r /gnocchi/etc/gnocchi/* /etc/gnocchi/ \ + && cp /gnocchi/gnocchi/rest/app.wsgi /var/www/cgi-bin/gnocchi/ \ + && chown -R gnocchi: /etc/gnocchi /var/log/kolla/gnocchi /var/www/cgi-bin/gnocchi {% endif %} -RUN usermod -a -G kolla gnocchi +COPY extend_start.sh /usr/local/bin/kolla_extend_start +COPY gnocchi_sudoers /etc/sudoers.d/kolla_gnocchi_sudoers + +RUN usermod -a -G kolla gnocchi \ + && chmod 750 /etc/sudoers.d \ + && chmod 640 /etc/sudoers.d/kolla_gnocchi_sudoers \ + && chmod 755 /var/www/cgi-bin/gnocchi \ + && touch /usr/local/bin/kolla_gnocchi_extend_start \ + && chmod 755 /usr/local/bin/kolla_extend_start /usr/local/bin/kolla_gnocchi_extend_start + +{% block gnocchi_base_footer %}{% endblock %} diff --git a/docker/gnocchi/gnocchi-base/extend_start.sh b/docker/gnocchi/gnocchi-base/extend_start.sh new file mode 100644 index 0000000000..366487d381 --- /dev/null +++ b/docker/gnocchi/gnocchi-base/extend_start.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Create log dir for Gnocchi logs +GNOCCHI_LOG_DIR="/var/log/kolla/gnocchi" +if [[ ! -d "${GNOCCHI_LOG_DIR}" ]]; then + mkdir -p ${GNOCCHI_LOG_DIR} +fi +if [[ $(stat -c %U:%G ${GNOCCHI_LOG_DIR}) != "gnocchi:kolla" ]]; then + chown gnocchi:kolla ${GNOCCHI_LOG_DIR} +fi +if [[ $(stat -c %a ${GNOCCHI_LOG_DIR}) != "755" ]]; then + chmod 755 ${GNOCCHI_LOG_DIR} +fi + +source /usr/local/bin/kolla_gnocchi_extend_start diff --git a/docker/gnocchi/gnocchi-base/gnocchi_sudoers b/docker/gnocchi/gnocchi-base/gnocchi_sudoers new file mode 100644 index 0000000000..c2a01d7098 --- /dev/null +++ b/docker/gnocchi/gnocchi-base/gnocchi_sudoers @@ -0,0 +1 @@ +%kolla ALL=(root) NOPASSWD: /usr/bin/chown -R gnocchi\: /var/lib/gnocchi/, /bin/chown -R gnocchi\: /var/lib/gnocchi/ diff --git a/tests/test_build.py b/tests/test_build.py index 87763ff4ae..464cd19f75 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -80,8 +80,7 @@ class BuildTestCentosBinary(BuildTest, base.BaseTestCase): class BuildTestCentosSource(BuildTest, base.BaseTestCase): - excluded_images = ["gnocchi-base", - "mistral-base"] + excluded_images = ["mistral-base"] def setUp(self): super(BuildTestCentosSource, self).setUp()