From 30c538790ab8bc52f86b25f04ae876290baeb335 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Sun, 8 Nov 2015 18:44:41 +0000 Subject: [PATCH] Removed parts of Dockerfile, simplifying it and reducing the image size. Modified and simplified the docker entrypoint script. Tweaked the cleanup actions of docker/run. - Legacy-Id: 10455 --- docker/Dockerfile | 38 +++++++++++++------------------------- docker/docker-init.sh | 40 +++++++++++----------------------------- docker/run | 2 +- 3 files changed, 25 insertions(+), 55 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 514468ccf..72e16a51a 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,3 +1,4 @@ +# -*- shell-mode -*- # This file is a docker (https://www.docker.com/what-docker) recipe, which can be used to build # a docker image which is ready to run a datatracker in development mode. # @@ -32,7 +33,6 @@ ENV DEBIAN_FRONTEND=noninteractive # Install needed packages RUN apt-get update && apt-get install -qy \ - apt-utils \ ca-certificates \ gawk \ less \ @@ -45,45 +45,33 @@ RUN apt-get update && apt-get install -qy \ pv \ python \ python-dev \ + python-m2crypto \ subversion/wheezy-backports \ wget \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* +# Set up root password +RUN echo "root:codesprint" | chpasswd + # MySQL VOLUME /var/lib/mysql # Pip ENV PYTHONWARNINGS="ignore:a true SSLContext object" WORKDIR /usr/src -RUN wget -q https://bootstrap.pypa.io/get-pip.py -RUN python get-pip.py -RUN pip --version +RUN wget -q https://bootstrap.pypa.io/get-pip.py && python get-pip.py && rm get-pip.py RUN pip install virtualenv # idnits and dependencies -RUN wget -q -P /usr/local/bin/ https://tools.ietf.org/tools/idnits/idnits -RUN chmod +x /usr/local/bin/idnits +RUN wget -q -P /usr/local/bin/ https://tools.ietf.org/tools/idnits/idnits && chmod +x /usr/local/bin/idnits -# A default user -RUN useradd -m -s /bin/bash -u 500 django -USER django -WORKDIR /home/django - -# Check out trunk, in order to verify setup by running tests -RUN mkdir -p ~/src -WORKDIR /home/django/src -RUN svn co https://svn.tools.ietf.org/svn/tools/ietfdb/trunk trunk - -# Set up a virtualenv, install requirements, run tests -WORKDIR /home/django/src/trunk -RUN virtualenv . -RUN . bin/activate; pip install -r requirements.txt -COPY settings_local.py ./settings_local.py -RUN . bin/activate; ietf/manage.py test --settings=settings_sqlitetest - -USER root -WORKDIR / +ENV DDIR="/usr/local/share/datatracker" +RUN mkdir -p $DDIR +WORKDIR $DDIR +COPY requirements.txt ./ +COPY settings_local.py ./ +RUN pip install -r requirements.txt COPY docker-init.sh /docker-init.sh ENTRYPOINT ["/docker-init.sh"] diff --git a/docker/docker-init.sh b/docker/docker-init.sh index d14c3c457..51d4366fa 100755 --- a/docker/docker-init.sh +++ b/docker/docker-init.sh @@ -41,7 +41,7 @@ fi if ! id -u "$USER" &> /dev/null; then echo "Creating user '$USER' ..." - useradd -ms /bin/bash $USER + useradd -s /bin/bash -G staff $USER fi if [ ! -d /opt/home/$USER ]; then @@ -49,45 +49,27 @@ if [ ! -d /opt/home/$USER ]; then mkdir -p /opt/home/$USER chown $USER /opt/home/$USER mkdir /opt/home/$USER/datatracker - virtualenv /opt/home/$USER/datatracker + virtualenv --system-site-packages /opt/home/$USER/datatracker fi -echo "Activating virtual python environment" +echo "Activating a virtual python environment ..." cat /opt/home/$USER/datatracker/bin/activate >> /etc/bash.bashrc . /opt/home/$USER/datatracker/bin/activate - -if [ ! -d /opt/home/$USER/datatracker/lib/python2.7/site-packages/django ]; then - echo "Installing requirements (based on trunk)" - pip install -r /home/django/src/trunk/requirements.txt +if ! python -c "import django"; then + echo "Installing requirements ..." + pip install -r /usr/local/share/datatracker/requirements.txt fi if [ ! -f /opt/home/$USER/datatracker/lib/site-python/settings_local.py ]; then - echo "Setting up a default settings_local.py" + echo "Setting up a default settings_local.py ..." mkdir -p /opt/home/$USER/datatracker/lib/site-python/ - cp /home/django/src/trunk/settings_local.py /opt/home/$USER/datatracker/lib/site-python/ -fi - -echo "Done." - -FLAG1=/opt/home/$USER/.docker-init-flag-1 -if [ ! -f $FLAG1 ]; then - touch $FLAG1 - cat <<-EOT - - ****************************************************************************** - - You should now cd to your svn working directory and update the datatracker - prerequisites according to the requirements given in 'requirements.txt': - - $ pip install -r requirements.txt - - Happy coding! - - ****************************************************************************** -EOT + cp /usr/local/share/datatracker/settings_local.py /opt/home/$USER/datatracker/lib/site-python/ fi chown -R $USER /opt/home/$USER cd /home/$USER + +echo "Done!" + su $USER diff --git a/docker/run b/docker/run index 58d00457c..e6697159b 100755 --- a/docker/run +++ b/docker/run @@ -136,5 +136,5 @@ docker commit $latest levkowetz/datatracker:latest echo "Cleaning up containers and images" docker rm $latest -docker rmi -f $(docker images -f dangling=true -q) +docker images -f dangling=true -q | xargs docker rmi -f