|
| 1 | +FROM alpine:3.4 |
| 2 | + |
| 3 | +# ensure local python is used over alpine 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 | +# install ca-certificates so that HTTPS works consistently |
| 11 | +# the other runtime dependencies for Python are installed later |
| 12 | +RUN apk add --no-cache ca-certificates |
| 13 | + |
| 14 | +ENV GPG_KEY %%PLACEHOLDER%% |
| 15 | +ENV PYTHON_VERSION %%PLACEHOLDER%% |
| 16 | + |
| 17 | +# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'" |
| 18 | +ENV PYTHON_PIP_VERSION %%PLACEHOLDER%% |
| 19 | + |
| 20 | +RUN set -ex \ |
| 21 | + && apk add --no-cache --virtual .fetch-deps \ |
| 22 | + gnupg \ |
| 23 | + openssl \ |
| 24 | + tar \ |
| 25 | + xz \ |
| 26 | + \ |
| 27 | + && wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \ |
| 28 | + && wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \ |
| 29 | + && export GNUPGHOME="$(mktemp -d)" \ |
| 30 | + && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \ |
| 31 | + && gpg --batch --verify python.tar.xz.asc python.tar.xz \ |
| 32 | + && rm -r "$GNUPGHOME" python.tar.xz.asc \ |
| 33 | + && mkdir -p /usr/src/python \ |
| 34 | + && tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \ |
| 35 | + && rm python.tar.xz \ |
| 36 | + \ |
| 37 | + && apk add --no-cache --virtual .build-deps \ |
| 38 | + bzip2-dev \ |
| 39 | + gcc \ |
| 40 | + libc-dev \ |
| 41 | + linux-headers \ |
| 42 | + make \ |
| 43 | + ncurses-dev \ |
| 44 | + openssl \ |
| 45 | + openssl-dev \ |
| 46 | + pax-utils \ |
| 47 | + readline-dev \ |
| 48 | + sqlite-dev \ |
| 49 | + tcl-dev \ |
| 50 | + tk \ |
| 51 | + tk-dev \ |
| 52 | + xz-dev \ |
| 53 | + zlib-dev \ |
| 54 | +# add build deps before removing fetch deps in case there's overlap |
| 55 | + && apk del .fetch-deps \ |
| 56 | + \ |
| 57 | + && cd /usr/src/python \ |
| 58 | + && ./configure \ |
| 59 | + --enable-loadable-sqlite-extensions \ |
| 60 | + --enable-shared \ |
| 61 | + && make -j$(getconf _NPROCESSORS_ONLN) \ |
| 62 | + && make install \ |
| 63 | + \ |
| 64 | +# explicit path to "pip3" to ensure Debian "pip3" cannot interfere |
| 65 | + && if [ ! -e /usr/local/bin/pip3 ]; then : \ |
| 66 | + && wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \ |
| 67 | + && python3 /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION" \ |
| 68 | + && rm /tmp/get-pip.py \ |
| 69 | + ; fi \ |
| 70 | + && pip3 install --no-cache-dir --upgrade "pip==$PYTHON_PIP_VERSION" \ |
| 71 | + && [ "$(pip list |tac|tac| awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \ |
| 72 | + \ |
| 73 | + && find /usr/local -depth \ |
| 74 | + \( \ |
| 75 | + \( -type d -a -name test -o -name tests \) \ |
| 76 | + -o \ |
| 77 | + \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \ |
| 78 | + \) -exec rm -rf '{}' + \ |
| 79 | + && runDeps="$( \ |
| 80 | + scanelf --needed --nobanner --recursive /usr/local \ |
| 81 | + | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \ |
| 82 | + | sort -u \ |
| 83 | + | xargs -r apk info --installed \ |
| 84 | + | sort -u \ |
| 85 | + )" \ |
| 86 | + && apk add --virtual .python-rundeps $runDeps \ |
| 87 | + && apk del .build-deps \ |
| 88 | + && rm -rf /usr/src/python ~/.cache |
| 89 | + |
| 90 | +# make some useful symlinks that are expected to exist |
| 91 | +RUN cd /usr/local/bin \ |
| 92 | + && { [ -e easy_install ] || ln -s easy_install-* easy_install; } \ |
| 93 | + && ln -s idle3 idle \ |
| 94 | + && ln -s pydoc3 pydoc \ |
| 95 | + && ln -s python3 python \ |
| 96 | + && ln -s python3-config python-config |
| 97 | + |
| 98 | +CMD ["python3"] |
0 commit comments