|
| 1 | +# |
| 2 | +# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh" |
| 3 | +# |
| 4 | +# PLEASE DO NOT EDIT IT DIRECTLY. |
| 5 | +# |
| 6 | + |
| 7 | +FROM alpine:3.13 |
| 8 | + |
| 9 | +# ensure local python is preferred over distribution python |
| 10 | +ENV PATH /usr/local/bin:$PATH |
| 11 | + |
| 12 | +# http://bugs.python.org/issue19846 |
| 13 | +# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK. |
| 14 | +ENV LANG C.UTF-8 |
| 15 | + |
| 16 | +# runtime dependencies |
| 17 | +RUN set -eux; \ |
| 18 | + apk add --no-cache \ |
| 19 | +# install ca-certificates so that HTTPS works consistently |
| 20 | + ca-certificates \ |
| 21 | + ; |
| 22 | +# other runtime dependencies for Python are installed later |
| 23 | + |
| 24 | +ENV GPG_KEY 0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D |
| 25 | +ENV PYTHON_VERSION 3.6.12 |
| 26 | + |
| 27 | +RUN set -ex \ |
| 28 | + && apk add --no-cache --virtual .fetch-deps \ |
| 29 | + gnupg \ |
| 30 | + tar \ |
| 31 | + xz \ |
| 32 | + \ |
| 33 | + && wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \ |
| 34 | + && wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \ |
| 35 | + && export GNUPGHOME="$(mktemp -d)" \ |
| 36 | + && gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \ |
| 37 | + && gpg --batch --verify python.tar.xz.asc python.tar.xz \ |
| 38 | + && { command -v gpgconf > /dev/null && gpgconf --kill all || :; } \ |
| 39 | + && rm -rf "$GNUPGHOME" python.tar.xz.asc \ |
| 40 | + && mkdir -p /usr/src/python \ |
| 41 | + && tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \ |
| 42 | + && rm python.tar.xz \ |
| 43 | + \ |
| 44 | + && apk add --no-cache --virtual .build-deps \ |
| 45 | + bluez-dev \ |
| 46 | + bzip2-dev \ |
| 47 | + coreutils \ |
| 48 | + dpkg-dev dpkg \ |
| 49 | + expat-dev \ |
| 50 | + findutils \ |
| 51 | + gcc \ |
| 52 | + gdbm-dev \ |
| 53 | + libc-dev \ |
| 54 | + libffi-dev \ |
| 55 | + libnsl-dev \ |
| 56 | + libtirpc-dev \ |
| 57 | + linux-headers \ |
| 58 | + make \ |
| 59 | + ncurses-dev \ |
| 60 | + openssl-dev \ |
| 61 | + pax-utils \ |
| 62 | + readline-dev \ |
| 63 | + sqlite-dev \ |
| 64 | + tcl-dev \ |
| 65 | + tk \ |
| 66 | + tk-dev \ |
| 67 | + xz-dev \ |
| 68 | + zlib-dev \ |
| 69 | +# add build deps before removing fetch deps in case there's overlap |
| 70 | + && apk del --no-network .fetch-deps \ |
| 71 | + \ |
| 72 | + && cd /usr/src/python \ |
| 73 | + && gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \ |
| 74 | + && ./configure \ |
| 75 | + --build="$gnuArch" \ |
| 76 | + --enable-loadable-sqlite-extensions \ |
| 77 | + --enable-optimizations \ |
| 78 | + --enable-option-checking=fatal \ |
| 79 | + --enable-shared \ |
| 80 | + --with-system-expat \ |
| 81 | + --with-system-ffi \ |
| 82 | + --without-ensurepip \ |
| 83 | + && make -j "$(nproc)" \ |
| 84 | +# set thread stack size to 1MB so we don't segfault before we hit sys.getrecursionlimit() |
| 85 | +# https://github.com/alpinelinux/aports/commit/2026e1259422d4e0cf92391ca2d3844356c649d0 |
| 86 | + EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000" \ |
| 87 | + LDFLAGS="-Wl,--strip-all" \ |
| 88 | +# setting PROFILE_TASK makes "--enable-optimizations" reasonable: https://bugs.python.org/issue36044 / https://github.com/docker-library/python/issues/160#issuecomment-509426916 |
| 89 | + PROFILE_TASK='-m test.regrtest --pgo \ |
| 90 | + test_array \ |
| 91 | + test_base64 \ |
| 92 | + test_binascii \ |
| 93 | + test_binhex \ |
| 94 | + test_binop \ |
| 95 | + test_bytes \ |
| 96 | + test_c_locale_coercion \ |
| 97 | + test_class \ |
| 98 | + test_cmath \ |
| 99 | + test_codecs \ |
| 100 | + test_compile \ |
| 101 | + test_complex \ |
| 102 | + test_csv \ |
| 103 | + test_decimal \ |
| 104 | + test_dict \ |
| 105 | + test_float \ |
| 106 | + test_fstring \ |
| 107 | + test_hashlib \ |
| 108 | + test_io \ |
| 109 | + test_iter \ |
| 110 | + test_json \ |
| 111 | + test_long \ |
| 112 | + test_math \ |
| 113 | + test_memoryview \ |
| 114 | + test_pickle \ |
| 115 | + test_re \ |
| 116 | + test_set \ |
| 117 | + test_slice \ |
| 118 | + test_struct \ |
| 119 | + test_threading \ |
| 120 | + test_time \ |
| 121 | + test_traceback \ |
| 122 | + test_unicode \ |
| 123 | + ' \ |
| 124 | + && make install \ |
| 125 | + && rm -rf /usr/src/python \ |
| 126 | + \ |
| 127 | + && find /usr/local -depth \ |
| 128 | + \( \ |
| 129 | + \( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \ |
| 130 | + -o \( -type f -a \( -name '*.pyc' -o -name '*.pyo' -o -name '*.a' \) \) \ |
| 131 | + -o \( -type f -a -name 'wininst-*.exe' \) \ |
| 132 | + \) -exec rm -rf '{}' + \ |
| 133 | + \ |
| 134 | + && find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec scanelf --needed --nobanner --format '%n#p' '{}' ';' \ |
| 135 | + | tr ',' '\n' \ |
| 136 | + | sort -u \ |
| 137 | + | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \ |
| 138 | + | xargs -rt apk add --no-cache --virtual .python-rundeps \ |
| 139 | + && apk del --no-network .build-deps \ |
| 140 | + \ |
| 141 | + && python3 --version |
| 142 | + |
| 143 | +# make some useful symlinks that are expected to exist |
| 144 | +RUN cd /usr/local/bin \ |
| 145 | + && ln -s idle3 idle \ |
| 146 | + && ln -s pydoc3 pydoc \ |
| 147 | + && ln -s python3 python \ |
| 148 | + && ln -s python3-config python-config |
| 149 | + |
| 150 | +# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'" |
| 151 | +ENV PYTHON_PIP_VERSION 20.3.3 |
| 152 | +# https://github.com/pypa/get-pip |
| 153 | +ENV PYTHON_GET_PIP_URL https://github.com/pypa/get-pip/raw/39356a9d34700a468cf847867ac1a3bd72cc5e45/get-pip.py |
| 154 | +ENV PYTHON_GET_PIP_SHA256 ec367c5c9b82fa13c04cfabb0a069e84496d5c36714f14d19b5f24d519d3ba25 |
| 155 | + |
| 156 | +RUN set -ex; \ |
| 157 | + \ |
| 158 | + wget -O get-pip.py "$PYTHON_GET_PIP_URL"; \ |
| 159 | + echo "$PYTHON_GET_PIP_SHA256 *get-pip.py" | sha256sum -c -; \ |
| 160 | + \ |
| 161 | + python get-pip.py \ |
| 162 | + --disable-pip-version-check \ |
| 163 | + --no-cache-dir \ |
| 164 | + "pip==$PYTHON_PIP_VERSION" \ |
| 165 | + ; \ |
| 166 | + pip --version; \ |
| 167 | + \ |
| 168 | + find /usr/local -depth \ |
| 169 | + \( \ |
| 170 | + \( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \ |
| 171 | + -o \ |
| 172 | + \( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \ |
| 173 | + \) -exec rm -rf '{}' +; \ |
| 174 | + rm -f get-pip.py |
| 175 | + |
| 176 | +CMD ["python3"] |
0 commit comments