From a159c686d7fbbf71a21a28a09608d000b99471e0 Mon Sep 17 00:00:00 2001 From: Eduardo Gonzalez Date: Wed, 12 Apr 2017 16:17:43 +0100 Subject: [PATCH] Fix zun images Zun uses wsgi to start process. Rework zun-base image to make use of wsgi. Create zun user with macros to maintain static uids. Zun compute need root to connect docker Change-Id: Idd417e1b804148543ee5f403a836fa1f3e6f7fb0 Closes-Bug: #1682142 --- docker/zun/zun-api/Dockerfile.j2 | 2 -- docker/zun/zun-api/extend_start.sh | 10 +++++++ docker/zun/zun-base/Dockerfile.j2 | 42 ++++++++++++++++++++++++---- docker/zun/zun-compute/Dockerfile.j2 | 2 -- kolla/common/config.py | 4 +++ 5 files changed, 50 insertions(+), 10 deletions(-) diff --git a/docker/zun/zun-api/Dockerfile.j2 b/docker/zun/zun-api/Dockerfile.j2 index a23e8d67de..c28df1c400 100644 --- a/docker/zun/zun-api/Dockerfile.j2 +++ b/docker/zun/zun-api/Dockerfile.j2 @@ -15,5 +15,3 @@ RUN chmod 755 /usr/local/bin/kolla_zun_extend_start {% block zun_api_footer %}{% endblock %} {% block footer %}{% endblock %} - -USER zun diff --git a/docker/zun/zun-api/extend_start.sh b/docker/zun/zun-api/extend_start.sh index eaed680e2d..92f6690648 100644 --- a/docker/zun/zun-api/extend_start.sh +++ b/docker/zun/zun-api/extend_start.sh @@ -1,5 +1,15 @@ #!/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 + . /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 diff --git a/docker/zun/zun-base/Dockerfile.j2 b/docker/zun/zun-base/Dockerfile.j2 index fe0e97a08a..cecea50eec 100644 --- a/docker/zun/zun-base/Dockerfile.j2 +++ b/docker/zun/zun-base/Dockerfile.j2 @@ -5,6 +5,8 @@ MAINTAINER {{ maintainer }} {% import "macros.j2" as macros with context %} +{{ macros.configure_user(name='zun') }} + {% if install_type == 'binary' %} RUN echo '{{ install_type }} not yet available for {{ base_distro }}' \ @@ -12,6 +14,33 @@ RUN echo '{{ install_type }} not yet available for {{ base_distro }}' \ {% elif install_type == 'source' %} + {% if base_distro in ['centos', 'oraclelinux', 'rhel'] %} + + {% set zun_base_packages = [ + 'httpd', + 'mod_wsgi', + 'mod_ssl', + 'python-ldappool' + ] %} + +{{ macros.install_packages(zun_base_packages | customizable("packages")) }} +RUN mkdir -p /var/www/cgi-bin/zun \ + && sed -i -r 's,^(Listen 80),#\1,' /etc/httpd/conf/httpd.conf \ + && sed -i -r 's,^(Listen 443),#\1,' /etc/httpd/conf.d/ssl.conf + + {% elif base_distro in ['debian', 'ubuntu'] %} + + {% set zun_base_packages = [ + 'apache2', + 'libapache2-mod-wsgi', + 'python-ldappool' + ] %} + +{{ macros.install_packages(zun_base_packages | customizable("packages")) }} +RUN mkdir -p /var/www/cgi-bin/zun \ + && echo > /etc/apache2/ports.conf + {% endif %} + ADD zun-base-archive /zun-base-source {% set zun_base_pip_packages = [ @@ -19,18 +48,19 @@ ADD zun-base-archive /zun-base-source ] %} RUN ln -s zun-base-source/* zun \ - && useradd --user-group --create-home --home-dir /var/lib/zun zun \ && {{ macros.install_pip(zun_base_pip_packages | customizable("pip_packages")) }} \ - && mkdir -p /etc/zun \ - && cp -r /zun/etc/* /etc/zun/ \ - && chown -R zun: /etc/zun + && mkdir -p /etc/zun /var/www/cgi-bin/zun \ + && cp -r /zun/etc/zun/* /etc/zun/ \ + && cp /zun/zun/api/app.wsgi /var/www/cgi-bin/zun \ + && cp -r /zun/etc/nova /etc/zun/ \ + && chown -R zun: /etc/zun /var/www/cgi-bin/zun {% endif %} COPY extend_start.sh /usr/local/bin/kolla_extend_start -RUN usermod -a -G kolla zun \ - && touch /usr/local/bin/kolla_zun_extend_start \ +RUN touch /usr/local/bin/kolla_zun_extend_start \ + && chmod 755 /var/www/cgi-bin/zun \ && chmod 755 /usr/local/bin/kolla_extend_start /usr/local/bin/kolla_zun_extend_start {% block zun_base_footer %}{% endblock %} diff --git a/docker/zun/zun-compute/Dockerfile.j2 b/docker/zun/zun-compute/Dockerfile.j2 index 7d6fc41fd7..f7badbf1c5 100644 --- a/docker/zun/zun-compute/Dockerfile.j2 +++ b/docker/zun/zun-compute/Dockerfile.j2 @@ -12,5 +12,3 @@ RUN echo '{{ install_type }} not yet available for {{ base_distro }}' \ {% block zun_compute_footer %}{% endblock %} {% block footer %}{% endblock %} - -USER zun diff --git a/kolla/common/config.py b/kolla/common/config.py index 6001c0c643..d2c2e5df0b 100755 --- a/kolla/common/config.py +++ b/kolla/common/config.py @@ -812,6 +812,10 @@ USERS = { 'opendaylight-user': { 'uid': 42462, 'gid': 42462, + }, + 'zun-user': { + 'uid': 42463, + 'gid': 42463, } }