From ec71665e080be1c7e378eb6429b3f3b6f07219d1 Mon Sep 17 00:00:00 2001 From: Sam Yaple Date: Mon, 9 Oct 2017 13:42:32 -0400 Subject: [PATCH] Plugin support in generic Dockerfile This would allow us to sitck with the single Dockerfile without much duplication. We do need to handle plugins in some form. docker build --build-arg PROJECT=neutron --tag loci-neutron . docker build --build-arg PROJECT=neutron-fwaas --build-arg PLUGIN=true --build-arg FROM=loci-neutron . Change-Id: I997750970a3ccab33ad832cf7408a3c52a60831e --- Dockerfile | 1 + scripts/cleanup.sh | 30 ++++++++++++++++++ scripts/create_user.sh | 9 ++++++ scripts/install.sh | 61 ++++++++----------------------------- scripts/install_packages.sh | 20 ++++++++++++ 5 files changed, 72 insertions(+), 49 deletions(-) create mode 100755 scripts/cleanup.sh create mode 100755 scripts/create_user.sh create mode 100755 scripts/install_packages.sh diff --git a/Dockerfile b/Dockerfile index 4675627..09d7459 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ ARG PROJECT_REF=master ARG DISTRO ARG PROFILES ARG PIP_PACKAGES +ARG PLUGIN=no COPY scripts /opt/loci/scripts COPY bindep.txt /opt/loci/ diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh new file mode 100755 index 0000000..2230a31 --- /dev/null +++ b/scripts/cleanup.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -ex + +case ${distro} in + debian|ubuntu) + apt-get purge -y --auto-remove \ + git \ + virtualenv + rm -rf /var/lib/apt/lists/* + ;; + centos) + yum -y autoremove \ + git \ + python-virtualenv + yum clean all + ;; + *) + echo "Unknown distro: ${distro}" + exit 1 + ;; +esac + +# NOTE(SamYaple): Removing this file allows python to use libraries outside of +# the virtualenv if they do not exist inside the venv. This is a requirement +# for using python-rbd which is not pip installable and is only available in +# packaged form. +rm /var/lib/openstack/lib/python*/no-global-site-packages.txt +rm -rf /tmp/* /root/.cache +find /usr/ /var/ -type f -name "*.pyc" -delete diff --git a/scripts/create_user.sh b/scripts/create_user.sh new file mode 100755 index 0000000..7ba28af --- /dev/null +++ b/scripts/create_user.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -ex + +groupadd -g 42424 ${PROJECT} +useradd -u 42424 -g ${PROJECT} -M -d /var/lib/${PROJECT} -s /usr/sbin/nologin -c "${PROJECT} user" ${PROJECT} + +mkdir -p /etc/${PROJECT} /var/log/${PROJECT} /var/lib/${PROJECT} /var/cache/${PROJECT} +chown ${PROJECT}:${PROJECT} /etc/${PROJECT} /var/log/${PROJECT} /var/lib/${PROJECT} /var/cache/${PROJECT} diff --git a/scripts/install.sh b/scripts/install.sh index 784c002..e29c2bf 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -33,61 +33,24 @@ case ${distro} in ;; esac -if [[ "${PROJECT}" == 'requirements' ]]; then +if [[ "${PROJECT}" == "requirements" ]]; then $(dirname $0)/requirements.sh exit 0 fi $(dirname $0)/fetch_wheels.sh -$(dirname $0)/setup_pip.sh -$(dirname $0)/clone_project.sh -$(dirname $0)/pip_install.sh \ - /tmp/${PROJECT} \ +if [[ "${PLUGIN}" == "no" ]]; then + $(dirname $0)/create_user.sh + $(dirname $0)/setup_pip.sh + $(dirname $0)/pip_install.sh \ + bindep \ pycrypto \ pymysql \ python-memcached \ - uwsgi \ - bindep \ - ${PIP_PACKAGES} + uwsgi +fi -PACKAGES=($(bindep -f /opt/loci/bindep.txt -b ${PROJECT} ${PROFILES} || :)) - -groupadd -g 42424 ${PROJECT} -useradd -u 42424 -g ${PROJECT} -M -d /var/lib/${PROJECT} -s /usr/sbin/nologin -c "${PROJECT} user" ${PROJECT} - -mkdir -p /etc/${PROJECT} /var/log/${PROJECT} /var/lib/${PROJECT} /var/cache/${PROJECT} -chown ${PROJECT}:${PROJECT} /etc/${PROJECT} /var/log/${PROJECT} /var/lib/${PROJECT} /var/cache/${PROJECT} - -case ${distro} in - debian|ubuntu) - if [[ ! -z ${PACKAGES} ]]; then - apt-get install -y --no-install-recommends ${PACKAGES[@]} - fi - apt-get purge -y --auto-remove \ - git \ - python-pip - rm -rf /var/lib/apt/lists/* - ;; - centos) - if [[ ! -z ${PACKAGES} ]]; then - yum -y --setopt=skip_missing_names_on_install=False install ${PACKAGES[@]} - fi - yum -y autoremove \ - git \ - python-pip - yum clean all - ;; - *) - echo "Unknown distro: ${distro}" - exit 1 - ;; -esac - -# NOTE(SamYaple): Removing this file allows python to use libraries outside of -# the virtualenv if they do not exist inside the venv. This is a requirement -# for using python-rbd which is not pip installable and is only available in -# packaged form. -rm /var/lib/openstack/lib/python*/no-global-site-packages.txt - -rm -rf /tmp/* /root/.cache -find /usr/ /var/ -type f -name "*.pyc" -delete +$(dirname $0)/clone_project.sh +$(dirname $0)/pip_install.sh /tmp/${PROJECT} ${PIP_PACKAGES} +$(dirname $0)/install_packages.sh +$(dirname $0)/cleanup.sh diff --git a/scripts/install_packages.sh b/scripts/install_packages.sh new file mode 100755 index 0000000..58f318d --- /dev/null +++ b/scripts/install_packages.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -ex + +PACKAGES=($(bindep -f /opt/loci/bindep.txt -b ${PROJECT} ${PROFILES} || :)) + +if [[ ! -z ${PACKAGES} ]]; then + case ${distro} in + debian|ubuntu) + apt-get install -y --no-install-recommends ${PACKAGES[@]} + ;; + centos) + yum -y --setopt=skip_missing_names_on_install=False install ${PACKAGES[@]} + ;; + *) + echo "Unknown distro: ${distro}" + exit 1 + ;; + esac +fi