From b6162f9f1691a992999ff07d0063e4431ae52b68 Mon Sep 17 00:00:00 2001 From: Marcin Juszkiewicz Date: Mon, 13 Nov 2017 14:48:29 +0000 Subject: mongodb: handle "user already exists" error on Debian When we install 'mongodb-server' package in Debian/stable it errors out because 'mongodb' user already exists. It was reported [1] and got resolved in Debian/testing. 1. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=858903 Change-Id: Iabfcbf68a3aea9d7b09b72eb3e8325f09c2f9d31 --- docker/macros.j2 | 29 ++++++++++++++++++----------- docker/mongodb/Dockerfile.j2 | 5 +++++ 2 files changed, 23 insertions(+), 11 deletions(-) (limited to 'docker') diff --git a/docker/macros.j2 b/docker/macros.j2 index dfb85447b..616172ea6 100644 --- a/docker/macros.j2 +++ b/docker/macros.j2 @@ -47,24 +47,31 @@ RUN usermod --append --home {{ homedir }} --groups kolla {{ name }} \ && chown -R {{ user.uid }}:{{ user.gid }} {{ homedir }} {% endmacro %} -{% macro debian_haproxy_existing_user_fix() %} -{# NOTE(SamYaple): The postinst script breaks if the user 'haproxy' already exists #} +{% macro debian_fix_existing_user(package, lines) %} RUN apt-get update \ - && apt-get -y install --no-install-recommends haproxy \ - || sed -i '/^adduser/,+1 d' /var/lib/dpkg/info/haproxy.postinst \ - && apt-get -y install -f \ + && apt-get -y install --no-install-recommends {{ package }} \ + || sed -i '/adduser/,+{{ lines }} d' /var/lib/dpkg/info/{{ package }}.postinst \ + && echo "configuring packages" \ + && dpkg --configure -a \ + && echo "done" \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* {% endmacro %} +{% macro debian_haproxy_existing_user_fix() %} +{# NOTE(SamYaple): The postinst script breaks if the user 'haproxy' already exists #} + {{ debian_fix_existing_user('haproxy', 1) }} +{% endmacro %} + +{% macro debian_mongodb_existing_user_fix() %} +{# NOTE(hrw): The postinst script breaks if the user 'mongodb' already exists #} +{# TODO(hrw): Version in Debian 'testing' checks does user exists #} + {{ debian_fix_existing_user('mongodb-server', 3) }} +{% endmacro %} + {% macro debian_opendaylight_existing_user_fix() %} {# NOTE(egonzalez): The postinst script breaks if the user 'odl' already exists #} -RUN apt-get update \ - && apt-get -y install --no-install-recommends opendaylight \ - || sed -i '/^\s*adduser/,+1 d' /var/lib/dpkg/info/opendaylight.postinst \ - && apt-get -y install -f \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* + {{ debian_fix_existing_user('opendaylight', 1) }} {% endmacro %} {% macro install_kubectl() %} diff --git a/docker/mongodb/Dockerfile.j2 b/docker/mongodb/Dockerfile.j2 index 73d6f265e..cf842f615 100644 --- a/docker/mongodb/Dockerfile.j2 +++ b/docker/mongodb/Dockerfile.j2 @@ -18,6 +18,11 @@ LABEL maintainer="{{ maintainer }}" name="{{ image_name }}" build-date="{{ build ] %} {% endif %} +{% if base_distro in ['debian'] %} + {# NOTE(hrw) Ubuntu does not need that #} + {{ macros.debian_mongodb_existing_user_fix() }} +{% endif %} + {{ macros.install_packages(mongodb_packages | customizable("packages")) }} COPY mongodb_sudoers /etc/sudoers.d/kolla_mongodb_sudoers -- cgit v1.2.3