From 8dd6993ae2184f79d4ee8373e2b80645a9416098 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Fri, 15 Feb 2019 19:44:18 +0100 Subject: [PATCH 1/8] Stuff env version variables together --- Dockerfile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index d157b54..31551c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,14 +8,14 @@ ENV APPDIR /app ENV LANG C.UTF-8 # Versions, and expose labels for external usage -ENV PYTHON_VERSION_27 2.7.15 -ENV PYTHON_VERSION_36 3.6.8 -ENV PYTHON_VERSION_37 3.7.2 -ENV CONDA_VERSION 4.5.12 -LABEL python.version_27=$PYTHON_VERSION_27 -LABEL python.version_36=$PYTHON_VERSION_36 -LABEL python.version_37=$PYTHON_VERSION_37 -LABEL conda.version=$CONDA_VERSION +ENV PYTHON_VERSION_27=2.7.15 \ + PYTHON_VERSION_36=3.6.8 \ + PYTHON_VERSION_37=3.7.2 \ + CONDA_VERSION=4.5.12 +LABEL python.version_27=$PYTHON_VERSION_27 \ + python.version_36=$PYTHON_VERSION_36 \ + python.version_37=$PYTHON_VERSION_37 \ + conda.version=$CONDA_VERSION # System dependencies RUN apt-get -y update From bf792180a09fc99f6141233d147002a0fabca79f Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Fri, 15 Feb 2019 19:46:30 +0100 Subject: [PATCH 2/8] Export DEBIAN_FRONTEND in every installation layer Exporting DEBIAN_FRONTEND via an `ENV` forces every invocation of the docker container to be 'noninteractive'. It's better to force the frontend as an `export` inside the shell every time apt-get is called. --- Dockerfile | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 31551c8..3a6f7f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,6 @@ FROM ubuntu:18.04 LABEL mantainer="Read the Docs " LABEL version="5.0.0rc1" -ENV DEBIAN_FRONTEND noninteractive ENV APPDIR /app ENV LANG C.UTF-8 @@ -18,13 +17,15 @@ LABEL python.version_27=$PYTHON_VERSION_27 \ conda.version=$CONDA_VERSION # System dependencies -RUN apt-get -y update -RUN apt-get -y install \ +RUN export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y update \ + && apt-get -y install \ software-properties-common \ vim # Install requirements -RUN apt-get -y install \ +RUN export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install \ build-essential \ bzr \ curl \ @@ -61,7 +62,8 @@ RUN apt-get -y install \ # pyenv extra requirements # https://github.com/pyenv/pyenv/wiki/Common-build-problems -RUN apt-get install -y \ +RUN export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install \ liblzma-dev \ libncurses5-dev \ libncursesw5-dev \ @@ -74,18 +76,23 @@ RUN apt-get install -y \ xz-utils # LaTeX -- split to reduce image layer size -RUN apt-get -y install \ +RUN export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install \ texlive-fonts-extra -RUN apt-get -y install \ +RUN export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install \ texlive-latex-extra-doc \ texlive-pictures-doc \ texlive-publishers-doc -RUN apt-get -y install \ +RUN export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install \ texlive-lang-english \ texlive-lang-japanese -RUN apt-get -y install \ +RUN export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install \ texlive-full -RUN apt-get -y install \ +RUN export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install \ fonts-symbola \ latex-cjk-chinese-arphic-bkai00mp \ latex-cjk-chinese-arphic-gbsn00lp \ @@ -104,21 +111,24 @@ RUN apt-get -y install \ # # swig: is required for different purposes # https://github.com/rtfd/readthedocs-docker-images/issues/15 -RUN apt-get -y install \ +RUN export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install \ imagemagick \ librsvg2-bin \ plantuml \ swig # Install Python tools/libs -RUN apt-get -y install \ +RUN export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install \ python-pip \ && pip install -U \ auxlib \ virtualenv # sphinx-js dependencies: jsdoc and typedoc (TypeScript support) -RUN apt-get -y install \ +RUN export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install \ nodejs \ npm \ && npm install --global \ From 6d1e898ca50e149504c58d99c8d7e43f33ef8a5d Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Fri, 15 Feb 2019 23:06:53 +0100 Subject: [PATCH 3/8] Put the LaTeX stuff in one image There is no necessity to reduce a single layer's size in a docker image. What matters in a docker image is the overall size and the amount of layers. --- Dockerfile | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3a6f7f4..0b799f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -75,29 +75,21 @@ RUN export DEBIAN_FRONTEND=noninteractive \ wget \ xz-utils -# LaTeX -- split to reduce image layer size -RUN export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install \ - texlive-fonts-extra -RUN export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install \ - texlive-latex-extra-doc \ - texlive-pictures-doc \ - texlive-publishers-doc -RUN export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install \ - texlive-lang-english \ - texlive-lang-japanese -RUN export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install \ - texlive-full +# Install LateX packages RUN export DEBIAN_FRONTEND=noninteractive \ && apt-get -y install \ fonts-symbola \ latex-cjk-chinese-arphic-bkai00mp \ latex-cjk-chinese-arphic-gbsn00lp \ latex-cjk-chinese-arphic-gkai00mp \ - texlive-fonts-recommended + texlive-fonts-extra \ + texlive-fonts-recommended \ + texlive-full \ + texlive-lang-english \ + texlive-lang-japanese \ + texlive-latex-extra-doc \ + texlive-pictures-doc \ + texlive-publishers-doc # plantuml: is to support sphinxcontrib-plantuml # https://pypi.org/project/sphinxcontrib-plantuml/ From e6ff154184af604dd71fc2e855f29d6dfa900023 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Fri, 15 Feb 2019 23:13:59 +0100 Subject: [PATCH 4/8] Remove transient dependencies from texlive-full Removes all the packages in the list, which are actually transient packages of texlive-full. texlive-full depends on: texlive-fonts-recommended texlive-fonts-extra texlive-lang-english texlive-lang-japanese texlive-latex-extra-doc texlive-pictures-doc texlive-publishers-doc latex-cjk-all latex-cjk-chinese-arphic-bkai00mp latex-cjk-chinese-arphic-gbsn00lp latex-cjk-chinese-arphic-gkai00mp --- Dockerfile | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0b799f7..efeb7b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -79,17 +79,7 @@ RUN export DEBIAN_FRONTEND=noninteractive \ RUN export DEBIAN_FRONTEND=noninteractive \ && apt-get -y install \ fonts-symbola \ - latex-cjk-chinese-arphic-bkai00mp \ - latex-cjk-chinese-arphic-gbsn00lp \ - latex-cjk-chinese-arphic-gkai00mp \ - texlive-fonts-extra \ - texlive-fonts-recommended \ - texlive-full \ - texlive-lang-english \ - texlive-lang-japanese \ - texlive-latex-extra-doc \ - texlive-pictures-doc \ - texlive-publishers-doc + texlive-full # plantuml: is to support sphinxcontrib-plantuml # https://pypi.org/project/sphinxcontrib-plantuml/ From c86a528425aaeef66c7641a176d2251d3c455339 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sat, 16 Feb 2019 00:50:03 +0100 Subject: [PATCH 5/8] Flatten conda and pyenv installs --- Dockerfile | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index efeb7b7..ac057ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -125,18 +125,17 @@ USER docs WORKDIR /home/docs # Install Conda -RUN curl -O https://repo.continuum.io/miniconda/Miniconda2-${CONDA_VERSION}-Linux-x86_64.sh -RUN bash Miniconda2-${CONDA_VERSION}-Linux-x86_64.sh -b -p /home/docs/.conda/ -ENV PATH $PATH:/home/docs/.conda/bin -RUN rm -f Miniconda2-${CONDA_VERSION}-Linux-x86_64.sh +RUN curl -O https://repo.continuum.io/miniconda/Miniconda2-${CONDA_VERSION}-Linux-x86_64.sh \ + && bash Miniconda2-${CONDA_VERSION}-Linux-x86_64.sh -b -p /home/docs/.conda/ \ + && rm -f Miniconda2-${CONDA_VERSION}-Linux-x86_64.sh +ENV PATH=$PATH:/home/docs/.conda/bin # Install pyenv -RUN wget https://github.com/pyenv/pyenv/archive/master.zip -RUN unzip master.zip && \ - rm -f master.zip && \ - mv pyenv-master ~docs/.pyenv -ENV PYENV_ROOT /home/docs/.pyenv -ENV PATH /home/docs/.pyenv/shims:$PATH:/home/docs/.pyenv/bin +RUN curl -L https://github.com/pyenv/pyenv/archive/master.tar.gz \ + | tar xz \ + && mv pyenv-master .pyenv +ENV PYENV_ROOT=/home/docs/.pyenv \ + PATH=/home/docs/.pyenv/shims:$PATH:/home/docs/.pyenv/bin # Install supported Python versions RUN pyenv install $PYTHON_VERSION_27 && \ From 48a0d1446b70444d20069a664183423f7f8342e4 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sat, 16 Feb 2019 00:51:45 +0100 Subject: [PATCH 6/8] Add users at the beginning The users should not change at all. So moving the layer to the bottom is the best choice. --- Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index ac057ac..0ceb838 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,10 @@ LABEL python.version_27=$PYTHON_VERSION_27 \ python.version_37=$PYTHON_VERSION_37 \ conda.version=$CONDA_VERSION +# UID and GID from readthedocs/user +RUN groupadd --gid 205 docs \ + && useradd --gid 205 -m --uid 1005 docs + # System dependencies RUN export DEBIAN_FRONTEND=noninteractive \ && apt-get -y update \ @@ -117,10 +121,6 @@ RUN export DEBIAN_FRONTEND=noninteractive \ jsdoc \ typedoc -# UID and GID from readthedocs/user -RUN groupadd --gid 205 docs -RUN useradd -m --uid 1005 --gid 205 docs - USER docs WORKDIR /home/docs From 88ba5ccd725a68bd3f5745ed89a7ec4fa54d493d Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sat, 16 Feb 2019 00:55:40 +0100 Subject: [PATCH 7/8] Move env variable block to the highest possible layer --- Dockerfile | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0ceb838..c5dc7e7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,16 +6,6 @@ LABEL version="5.0.0rc1" ENV APPDIR /app ENV LANG C.UTF-8 -# Versions, and expose labels for external usage -ENV PYTHON_VERSION_27=2.7.15 \ - PYTHON_VERSION_36=3.6.8 \ - PYTHON_VERSION_37=3.7.2 \ - CONDA_VERSION=4.5.12 -LABEL python.version_27=$PYTHON_VERSION_27 \ - python.version_36=$PYTHON_VERSION_36 \ - python.version_37=$PYTHON_VERSION_37 \ - conda.version=$CONDA_VERSION - # UID and GID from readthedocs/user RUN groupadd --gid 205 docs \ && useradd --gid 205 -m --uid 1005 docs @@ -124,6 +114,16 @@ RUN export DEBIAN_FRONTEND=noninteractive \ USER docs WORKDIR /home/docs +# Versions, and expose labels for external usage +ENV PYTHON_VERSION_27=2.7.15 \ + PYTHON_VERSION_36=3.6.8 \ + PYTHON_VERSION_37=3.7.2 \ + CONDA_VERSION=4.5.12 +LABEL python.version_27=$PYTHON_VERSION_27 \ + python.version_36=$PYTHON_VERSION_36 \ + python.version_37=$PYTHON_VERSION_37 \ + conda.version=$CONDA_VERSION + # Install Conda RUN curl -O https://repo.continuum.io/miniconda/Miniconda2-${CONDA_VERSION}-Linux-x86_64.sh \ && bash Miniconda2-${CONDA_VERSION}-Linux-x86_64.sh -b -p /home/docs/.conda/ \ From 8b018e4484d4fad7396d1981f6d618a086b2467a Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sat, 16 Feb 2019 01:14:22 +0100 Subject: [PATCH 8/8] Unite python pip installation in one layer --- Dockerfile | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/Dockerfile b/Dockerfile index c5dc7e7..c54e836 100644 --- a/Dockerfile +++ b/Dockerfile @@ -138,30 +138,28 @@ ENV PYENV_ROOT=/home/docs/.pyenv \ PATH=/home/docs/.pyenv/shims:$PATH:/home/docs/.pyenv/bin # Install supported Python versions -RUN pyenv install $PYTHON_VERSION_27 && \ - pyenv install $PYTHON_VERSION_37 && \ - pyenv install $PYTHON_VERSION_36 && \ - pyenv global \ - $PYTHON_VERSION_27 \ - $PYTHON_VERSION_37 \ - $PYTHON_VERSION_36 - -WORKDIR /tmp - -RUN pyenv local $PYTHON_VERSION_27 && \ - pyenv exec pip install --no-cache-dir -U pip && \ - pyenv exec pip install --no-cache-dir --only-binary numpy,scipy numpy scipy && \ - pyenv exec pip install --no-cache-dir pandas matplotlib virtualenv - -RUN pyenv local $PYTHON_VERSION_37 && \ - pyenv exec pip install --no-cache-dir -U pip && \ - pyenv exec pip install --no-cache-dir --only-binary numpy,scipy numpy scipy && \ - pyenv exec pip install --no-cache-dir pandas matplotlib virtualenv - -RUN pyenv local $PYTHON_VERSION_36 && \ - pyenv exec pip install --no-cache-dir -U pip && \ - pyenv exec pip install --no-cache-dir --only-binary numpy,scipy numpy scipy && \ - pyenv exec pip install --no-cache-dir pandas matplotlib virtualenv +RUN set -x \ + && pyenv install "${PYTHON_VERSION_27}" \ + && pyenv install "${PYTHON_VERSION_37}" \ + && pyenv install "${PYTHON_VERSION_36}" \ + && pyenv global \ + "${PYTHON_VERSION_27}" \ + "${PYTHON_VERSION_37}" \ + "${PYTHON_VERSION_36}" \ + && true + +RUN set -x \ + && cd /tmp \ + && for env in "${PYTHON_VERSION_27}" "${PYTHON_VERSION_37}" "${PYTHON_VERSION_36}"; \ + do pyenv local "${env}" \ + && pyenv exec pip install --no-cache-dir -U pip \ + && pyenv exec pip install --no-cache-dir --only-binary numpy,scipy \ + matplotlib \ + numpy \ + pandas \ + scipy \ + virtualenv \ + ; done WORKDIR /