|
| 1 | +## WARNING: This image is plane copy of: |
| 2 | +## https://github.com/docker-library/python/blob/7c8595e8e2b1c8bca0b6d9d146675b94c2a37ec7/3.10/bullseye/Dockerfile |
| 3 | +## This is temporary solution and we come with proper solution in the future. |
| 4 | +## Ticket: https://linear.app/deepnote/issue/PLA-3219/cleanup-build-pipeline-for-deepnote-python-images |
| 5 | + |
| 6 | +ARG CIRCLE_PULL_REQUEST |
| 7 | +FROM deepnote/python:base${CIRCLE_PULL_REQUEST:+-ra-${CIRCLE_PULL_REQUEST##*/}} |
| 8 | + |
| 9 | + |
| 10 | +# ensure local python is preferred over distribution python |
| 11 | +ENV PATH /usr/local/bin:$PATH |
| 12 | + |
| 13 | +# cannot remove LANG even though https://bugs.python.org/issue19846 is fixed |
| 14 | +# last attempted removal of LANG broke many users: |
| 15 | +# https://github.com/docker-library/python/pull/570 |
| 16 | +ENV LANG C.UTF-8 |
| 17 | + |
| 18 | +# runtime dependencies |
| 19 | +RUN set -eux; \ |
| 20 | + apt-get update; \ |
| 21 | + apt-get install -y --no-install-recommends \ |
| 22 | + libbluetooth-dev \ |
| 23 | + tk-dev \ |
| 24 | + uuid-dev \ |
| 25 | + ; \ |
| 26 | + rm -rf /var/lib/apt/lists/* |
| 27 | + |
| 28 | +ENV GPG_KEY A035C8C19219BA821ECEA86B64E628F8D684696D |
| 29 | +ENV PYTHON_VERSION 3.10.15 |
| 30 | + |
| 31 | +RUN set -eux; \ |
| 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 | + GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \ |
| 36 | + gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$GPG_KEY"; \ |
| 37 | + gpg --batch --verify python.tar.xz.asc python.tar.xz; \ |
| 38 | + gpgconf --kill all; \ |
| 39 | + rm -rf "$GNUPGHOME" python.tar.xz.asc; \ |
| 40 | + mkdir -p /usr/src/python; \ |
| 41 | + tar --extract --directory /usr/src/python --strip-components=1 --file python.tar.xz; \ |
| 42 | + rm python.tar.xz; \ |
| 43 | + \ |
| 44 | + cd /usr/src/python; \ |
| 45 | + gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ |
| 46 | + ./configure \ |
| 47 | + --build="$gnuArch" \ |
| 48 | + --enable-loadable-sqlite-extensions \ |
| 49 | + --enable-optimizations \ |
| 50 | + --enable-option-checking=fatal \ |
| 51 | + --enable-shared \ |
| 52 | + --with-lto \ |
| 53 | + --with-system-expat \ |
| 54 | + --with-ensurepip \ |
| 55 | + ; \ |
| 56 | + nproc="$(nproc)"; \ |
| 57 | + EXTRA_CFLAGS="$(dpkg-buildflags --get CFLAGS)"; \ |
| 58 | + LDFLAGS="$(dpkg-buildflags --get LDFLAGS)"; \ |
| 59 | + make -j "$nproc" \ |
| 60 | + "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ |
| 61 | + "LDFLAGS=${LDFLAGS:-}" \ |
| 62 | + "PROFILE_TASK=${PROFILE_TASK:-}" \ |
| 63 | + ; \ |
| 64 | +# https://github.com/docker-library/python/issues/784 |
| 65 | +# prevent accidental usage of a system installed libpython of the same version |
| 66 | + rm python; \ |
| 67 | + make -j "$nproc" \ |
| 68 | + "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \ |
| 69 | + "LDFLAGS=${LDFLAGS:--Wl},-rpath='\$\$ORIGIN/../lib'" \ |
| 70 | + "PROFILE_TASK=${PROFILE_TASK:-}" \ |
| 71 | + python \ |
| 72 | + ; \ |
| 73 | + make install; \ |
| 74 | + \ |
| 75 | +# enable GDB to load debugging data: https://github.com/docker-library/python/pull/701 |
| 76 | + bin="$(readlink -ve /usr/local/bin/python3)"; \ |
| 77 | + dir="$(dirname "$bin")"; \ |
| 78 | + mkdir -p "/usr/share/gdb/auto-load/$dir"; \ |
| 79 | + cp -vL Tools/gdb/libpython.py "/usr/share/gdb/auto-load/$bin-gdb.py"; \ |
| 80 | + \ |
| 81 | + cd /; \ |
| 82 | + rm -rf /usr/src/python; \ |
| 83 | + \ |
| 84 | + find /usr/local -depth \ |
| 85 | + \( \ |
| 86 | + \( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \ |
| 87 | + -o \( -type f -a \( -name '*.pyc' -o -name '*.pyo' -o -name 'libpython*.a' \) \) \ |
| 88 | + \) -exec rm -rf '{}' + \ |
| 89 | + ; \ |
| 90 | + \ |
| 91 | + ldconfig; \ |
| 92 | + \ |
| 93 | + export PYTHONDONTWRITEBYTECODE=1; \ |
| 94 | + python3 --version; \ |
| 95 | + \ |
| 96 | + pip3 install \ |
| 97 | + --disable-pip-version-check \ |
| 98 | + --no-cache-dir \ |
| 99 | + --no-compile \ |
| 100 | + 'setuptools==65.5.1' \ |
| 101 | + wheel \ |
| 102 | + ; \ |
| 103 | + pip3 --version |
| 104 | + |
| 105 | +# make some useful symlinks that are expected to exist ("/usr/local/bin/python" and friends) |
| 106 | +RUN set -eux; \ |
| 107 | + for src in idle3 pip3 pydoc3 python3 python3-config; do \ |
| 108 | + dst="$(echo "$src" | tr -d 3)"; \ |
| 109 | + [ -s "/usr/local/bin/$src" ]; \ |
| 110 | + [ ! -e "/usr/local/bin/$dst" ]; \ |
| 111 | + ln -svT "$src" "/usr/local/bin/$dst"; \ |
| 112 | + done |
| 113 | + |
| 114 | + |
| 115 | +# We create the virtual environment in the home directory in the Dockerfile |
| 116 | +# for performance improvement. |
| 117 | +RUN python -m venv --system-site-packages ~/venv |
0 commit comments