|
| 1 | +# Copyright 2020 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from ubuntu:20.04 |
| 16 | + |
| 17 | +ENV DEBIAN_FRONTEND noninteractive |
| 18 | + |
| 19 | +# Ensure local Python is preferred over distribution Python. |
| 20 | +ENV PATH /usr/local/bin:$PATH |
| 21 | + |
| 22 | +# Install dependencies. |
| 23 | +RUN apt-get update \ |
| 24 | + && apt-get install -y --no-install-recommends \ |
| 25 | + apt-transport-https \ |
| 26 | + build-essential \ |
| 27 | + ca-certificates \ |
| 28 | + curl \ |
| 29 | + dirmngr \ |
| 30 | + git \ |
| 31 | + gpg-agent \ |
| 32 | + graphviz \ |
| 33 | + libbz2-dev \ |
| 34 | + libdb5.3-dev \ |
| 35 | + libexpat1-dev \ |
| 36 | + libffi-dev \ |
| 37 | + liblzma-dev \ |
| 38 | + libreadline-dev \ |
| 39 | + libsnappy-dev \ |
| 40 | + libssl-dev \ |
| 41 | + libsqlite3-dev \ |
| 42 | + portaudio19-dev \ |
| 43 | + redis-server \ |
| 44 | + software-properties-common \ |
| 45 | + ssh \ |
| 46 | + sudo \ |
| 47 | + tcl \ |
| 48 | + tcl-dev \ |
| 49 | + tk \ |
| 50 | + tk-dev \ |
| 51 | + uuid-dev \ |
| 52 | + wget \ |
| 53 | + zlib1g-dev \ |
| 54 | + && add-apt-repository universe \ |
| 55 | + && apt-get update \ |
| 56 | + && apt-get -y install jq \ |
| 57 | + && apt-get clean autoclean \ |
| 58 | + && apt-get autoremove -y \ |
| 59 | + && rm -rf /var/lib/apt/lists/* \ |
| 60 | + && rm -f /var/cache/apt/archives/*.deb |
| 61 | + |
| 62 | + |
| 63 | +COPY fetch_gpg_keys.sh /tmp |
| 64 | +# Install the desired versions of Python. |
| 65 | +RUN set -ex \ |
| 66 | + && export GNUPGHOME="$(mktemp -d)" \ |
| 67 | + && echo "disable-ipv6" >> "${GNUPGHOME}/dirmngr.conf" \ |
| 68 | + && /tmp/fetch_gpg_keys.sh \ |
| 69 | + && for PYTHON_VERSION in 3.7.8 3.8.5; do \ |
| 70 | + wget --no-check-certificate -O python-${PYTHON_VERSION}.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \ |
| 71 | + && wget --no-check-certificate -O python-${PYTHON_VERSION}.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \ |
| 72 | + && gpg --batch --verify python-${PYTHON_VERSION}.tar.xz.asc python-${PYTHON_VERSION}.tar.xz \ |
| 73 | + && rm -r python-${PYTHON_VERSION}.tar.xz.asc \ |
| 74 | + && mkdir -p /usr/src/python-${PYTHON_VERSION} \ |
| 75 | + && tar -xJC /usr/src/python-${PYTHON_VERSION} --strip-components=1 -f python-${PYTHON_VERSION}.tar.xz \ |
| 76 | + && rm python-${PYTHON_VERSION}.tar.xz \ |
| 77 | + && cd /usr/src/python-${PYTHON_VERSION} \ |
| 78 | + && ./configure \ |
| 79 | + --enable-shared \ |
| 80 | + # This works only on Python 2.7 and throws a warning on every other |
| 81 | + # version, but seems otherwise harmless. |
| 82 | + --enable-unicode=ucs4 \ |
| 83 | + --with-system-ffi \ |
| 84 | + --without-ensurepip \ |
| 85 | + && make -j$(nproc) \ |
| 86 | + && make install \ |
| 87 | + && ldconfig \ |
| 88 | + ; done \ |
| 89 | + && rm -rf "${GNUPGHOME}" \ |
| 90 | + && rm -rf /usr/src/python* \ |
| 91 | + && rm -rf ~/.cache/ |
| 92 | + |
| 93 | +RUN wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \ |
| 94 | + && python3.7 /tmp/get-pip.py \ |
| 95 | + && python3.8 /tmp/get-pip.py \ |
| 96 | + && rm /tmp/get-pip.py |
| 97 | + |
| 98 | +CMD ["python3.7"] |
0 commit comments