|
| 1 | +FROM alpine:3.8 |
| 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 | +# https://github.com/docker-library/python/issues/147 |
| 10 | +ENV PYTHONIOENCODING UTF-8 |
| 11 | + |
| 12 | +# install ca-certificates so that HTTPS works consistently |
| 13 | +# the other runtime dependencies for Python are installed later |
| 14 | +RUN apk add --no-cache ca-certificates |
| 15 | + |
| 16 | +ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF |
| 17 | +ENV PYTHON_VERSION 2.7.15 |
| 18 | + |
| 19 | +RUN set -ex \ |
| 20 | + && apk add --no-cache --virtual .fetch-deps \ |
| 21 | + gnupg \ |
| 22 | + libressl \ |
| 23 | + tar \ |
| 24 | + xz \ |
| 25 | + \ |
| 26 | + && wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \ |
| 27 | + && wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \ |
| 28 | + && export GNUPGHOME="$(mktemp -d)" \ |
| 29 | + && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \ |
| 30 | + && gpg --batch --verify python.tar.xz.asc python.tar.xz \ |
| 31 | + && rm -rf "$GNUPGHOME" python.tar.xz.asc \ |
| 32 | + && mkdir -p /usr/src/python \ |
| 33 | + && tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \ |
| 34 | + && rm python.tar.xz \ |
| 35 | + \ |
| 36 | + && apk add --no-cache --virtual .build-deps \ |
| 37 | + bzip2-dev \ |
| 38 | + coreutils \ |
| 39 | + dpkg-dev dpkg \ |
| 40 | + gcc \ |
| 41 | + gdbm-dev \ |
| 42 | + libc-dev \ |
| 43 | + libnsl-dev \ |
| 44 | + libressl \ |
| 45 | + libressl-dev \ |
| 46 | + libtirpc-dev \ |
| 47 | + linux-headers \ |
| 48 | + make \ |
| 49 | + ncurses-dev \ |
| 50 | + pax-utils \ |
| 51 | + readline-dev \ |
| 52 | + sqlite-dev \ |
| 53 | + tcl-dev \ |
| 54 | + tk \ |
| 55 | + tk-dev \ |
| 56 | + zlib-dev \ |
| 57 | +# add build deps before removing fetch deps in case there's overlap |
| 58 | + && apk del .fetch-deps \ |
| 59 | + \ |
| 60 | + && cd /usr/src/python \ |
| 61 | + && gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \ |
| 62 | + && ./configure \ |
| 63 | + --build="$gnuArch" \ |
| 64 | + --enable-shared \ |
| 65 | + --enable-unicode=ucs4 \ |
| 66 | + && make -j "$(nproc)" \ |
| 67 | +# set thread stack size to 1MB so we don't segfault before we hit sys.getrecursionlimit() |
| 68 | +# https://github.com/alpinelinux/aports/commit/2026e1259422d4e0cf92391ca2d3844356c649d0 |
| 69 | + EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000" \ |
| 70 | + && make install \ |
| 71 | + \ |
| 72 | + && runDeps="$( \ |
| 73 | + scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \ |
| 74 | + | tr ',' '\n' \ |
| 75 | + | sort -u \ |
| 76 | + | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \ |
| 77 | + )" \ |
| 78 | + && apk add --virtual .python-rundeps $runDeps \ |
| 79 | + && apk del .build-deps \ |
| 80 | + \ |
| 81 | + && find /usr/local -depth \ |
| 82 | + \( \ |
| 83 | + \( -type d -a \( -name test -o -name tests \) \) \ |
| 84 | + -o \ |
| 85 | + \( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \ |
| 86 | + \) -exec rm -rf '{}' + \ |
| 87 | + && rm -rf /usr/src/python |
| 88 | + |
| 89 | +# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'" |
| 90 | +ENV PYTHON_PIP_VERSION 10.0.1 |
| 91 | + |
| 92 | +RUN set -ex; \ |
| 93 | + \ |
| 94 | + apk add --no-cache --virtual .fetch-deps libressl; \ |
| 95 | + \ |
| 96 | + wget -O get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \ |
| 97 | + \ |
| 98 | + apk del .fetch-deps; \ |
| 99 | + \ |
| 100 | + python get-pip.py \ |
| 101 | + --disable-pip-version-check \ |
| 102 | + --no-cache-dir \ |
| 103 | + "pip==$PYTHON_PIP_VERSION" \ |
| 104 | + ; \ |
| 105 | + pip --version; \ |
| 106 | + \ |
| 107 | + find /usr/local -depth \ |
| 108 | + \( \ |
| 109 | + \( -type d -a \( -name test -o -name tests \) \) \ |
| 110 | + -o \ |
| 111 | + \( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \ |
| 112 | + \) -exec rm -rf '{}' +; \ |
| 113 | + rm -f get-pip.py |
| 114 | + |
| 115 | +CMD ["python2"] |
0 commit comments