|
| 1 | +FROM buildpack-deps:jessie |
| 2 | + |
| 3 | +# ensure local python is preferred over distribution python |
| 4 | +ENV PATH /usr/local/bin:$PATH |
| 5 | + |
| 6 | +# http://bugs.python.org/issue19846 |
| 7 | +# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK. |
| 8 | +ENV LANG C.UTF-8 |
| 9 | + |
| 10 | +# runtime dependencies |
| 11 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 12 | + tcl \ |
| 13 | + tk \ |
| 14 | + && rm -rf /var/lib/apt/lists/* |
| 15 | + |
| 16 | +ENV GPG_KEY A74B06BF |
| 17 | +ENV PYTHON_VERSION 2.6.9 |
| 18 | + |
| 19 | +# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'" |
| 20 | +ENV PYTHON_PIP_VERSION 9.0.1 |
| 21 | + |
| 22 | +RUN set -ex \ |
| 23 | + && buildDeps=' \ |
| 24 | + tcl-dev \ |
| 25 | + tk-dev \ |
| 26 | + ' \ |
| 27 | + && apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \ |
| 28 | + \ |
| 29 | + && wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \ |
| 30 | + && wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \ |
| 31 | + && export GNUPGHOME="$(mktemp -d)" \ |
| 32 | + && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \ |
| 33 | + && gpg --batch --verify python.tar.xz.asc python.tar.xz \ |
| 34 | + && rm -r "$GNUPGHOME" python.tar.xz.asc \ |
| 35 | + && mkdir -p /usr/src/python \ |
| 36 | + && tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \ |
| 37 | + && rm python.tar.xz \ |
| 38 | + \ |
| 39 | + && cd /usr/src/python \ |
| 40 | + && ./configure \ |
| 41 | + --enable-shared \ |
| 42 | + --enable-unicode=ucs4 \ |
| 43 | + && make -j$(nproc) \ |
| 44 | + && make install \ |
| 45 | + && ldconfig \ |
| 46 | + \ |
| 47 | + && wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \ |
| 48 | + && python2 /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION" \ |
| 49 | + && rm /tmp/get-pip.py \ |
| 50 | +# we use "--force-reinstall" for the case where the version of pip we're trying to install is the same as the version bundled with Python |
| 51 | +# ("Requirement already up-to-date: pip==8.1.2 in /usr/local/lib/python3.6/site-packages") |
| 52 | +# https://github.com/docker-library/python/pull/143#issuecomment-241032683 |
| 53 | + && pip install --no-cache-dir --upgrade --force-reinstall "pip==$PYTHON_PIP_VERSION" \ |
| 54 | +# then we use "pip list" to ensure we don't have more than one pip version installed |
| 55 | +# https://github.com/docker-library/python/pull/100 |
| 56 | + && [ "$(pip list |tac|tac| awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \ |
| 57 | + \ |
| 58 | + && find /usr/local -depth \ |
| 59 | + \( \ |
| 60 | + \( -type d -a -name test -o -name tests \) \ |
| 61 | + -o \ |
| 62 | + \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \ |
| 63 | + \) -exec rm -rf '{}' + \ |
| 64 | + && apt-get purge -y --auto-remove $buildDeps \ |
| 65 | + && rm -rf /usr/src/python ~/.cache |
| 66 | + |
| 67 | +# install "virtualenv", since the vast majority of users of this image will want it |
| 68 | +RUN pip install --no-cache-dir virtualenv |
| 69 | + |
| 70 | +CMD ["python2"] |
0 commit comments