|
| 1 | +FROM ubuntu:22.04 |
| 2 | + |
| 3 | +## Main python version to install + use for tox |
| 4 | +ARG PYTHON_MAIN_VERSION=3.11 |
| 5 | +## Other python versions to install |
| 6 | +# Must be available either in the deadsnakes PPA or in |
| 7 | +# the official Ubuntu repositories |
| 8 | +ARG PYTHON_OTHER_VERSIONS="3.7 3.8 3.9 3.10" |
| 9 | +## PyPy version to install |
| 10 | +# for versions see https://www.pypy.org/download.html |
| 11 | +ARG PYTHON_PYPY_VERSION=3.9-v7.3.12 |
| 12 | +## GPG key for the deadsnakes PPA |
| 13 | +# See https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa |
| 14 | +ARG DEADSNAKES_GPG_KEY=F23C5A6CF475977595C89F51BA6932366A755776 |
| 15 | + |
| 16 | +ARG TARGETARCH |
| 17 | +ENV DEBIAN_FRONTEND=noninteractive |
| 18 | + |
| 19 | +# Install common build dependencies, add deadsnakes PPA and cleanup. |
| 20 | +# (see https://github.com/deadsnakes) |
| 21 | +# hadolint ignore=DL3008,SC2086 |
| 22 | +RUN set -eux \ |
| 23 | + ; apt-get update \ |
| 24 | + ; apt-get install -y --no-install-recommends \ |
| 25 | + ca-certificates \ |
| 26 | + g++ \ |
| 27 | + gcc \ |
| 28 | + git \ |
| 29 | + curl \ |
| 30 | + bzip2 \ |
| 31 | + make \ |
| 32 | + ; savedAptMark="$(apt-mark showmanual)" \ |
| 33 | + \ |
| 34 | + ; apt-get install -y --no-install-recommends \ |
| 35 | + dirmngr \ |
| 36 | + gnupg \ |
| 37 | + \ |
| 38 | + ; tmp_home="$(mktemp -d)"; export GNUPGHOME="$tmp_home" \ |
| 39 | + ; gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys "$DEADSNAKES_GPG_KEY" \ |
| 40 | + ; gpg -o /usr/share/keyrings/deadsnakes.gpg --export "$DEADSNAKES_GPG_KEY" \ |
| 41 | + ; echo "deb [arch=amd64,arm64 signed-by=/usr/share/keyrings/deadsnakes.gpg] https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy main" >> /etc/apt/sources.list \ |
| 42 | + \ |
| 43 | + ; apt-mark auto '.*' > /dev/null \ |
| 44 | + ; apt-mark manual $savedAptMark \ |
| 45 | + ; apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ |
| 46 | + ; rm -rf /var/lib/apt/lists/* |
| 47 | + |
| 48 | +# Install pip3, all python versions and tox in the main python version |
| 49 | +# hadolint ignore=DL3008,SC2086 |
| 50 | +RUN set -eux \ |
| 51 | + ; apt-get update \ |
| 52 | + ; apt-get install -y --no-install-recommends python3-pip \ |
| 53 | + ; for version in ${PYTHON_OTHER_VERSIONS} ${PYTHON_MAIN_VERSION} \ |
| 54 | + ; do \ |
| 55 | + apt-get install -y --no-install-recommends \ |
| 56 | + python${version} \ |
| 57 | + python${version}-dev \ |
| 58 | + python${version}-venv \ |
| 59 | + python${version}-distutils \ |
| 60 | + ; python${version} -m pip install --upgrade pip \ |
| 61 | + ; done \ |
| 62 | + ; python${PYTHON_MAIN_VERSION} -m pip install --no-cache tox \ |
| 63 | + ; rm -rf /var/lib/apt/lists/*; |
| 64 | + |
| 65 | +# Install PyPy |
| 66 | +RUN set -eux \ |
| 67 | + ; if [ "$TARGETARCH" = "arm64" ] ; then curl -L --show-error --retry 5 -o /pypy.tar.bz2 https://downloads.python.org/pypy/pypy${PYTHON_PYPY_VERSION}-aarch64.tar.bz2 \ |
| 68 | + ; else curl -L --show-error --retry 5 -o /pypy.tar.bz2 https://downloads.python.org/pypy/pypy${PYTHON_PYPY_VERSION}-linux64.tar.bz2 \ |
| 69 | + ; fi \ |
| 70 | + ; mkdir /pypy && tar -xf /pypy.tar.bz2 -C /pypy --strip-components=1 |
| 71 | + |
| 72 | +ENV PATH="/pypy/bin:$PATH" |
| 73 | + |
| 74 | +# Create user and app directory |
| 75 | +RUN set -eux \ |
| 76 | + ; groupadd -r tox --gid=1000 \ |
| 77 | + ; useradd --no-log-init -r -g tox -m --uid=1000 tox \ |
| 78 | + ; mkdir /app \ |
| 79 | + ; chown tox:tox /app |
| 80 | + |
| 81 | +WORKDIR /app |
| 82 | +VOLUME /app |
| 83 | +USER tox |
| 84 | + |
| 85 | +# Add safe.directory to git to avoid setuptools_scm "unable to detect version" |
| 86 | +# This can't be limited to /app since gitlab-ci mounts the workspace somewhere else |
| 87 | +# (see https://github.com/pypa/setuptools_scm/issues/797) |
| 88 | +# This needs to run as user tox |
| 89 | +RUN git config --global --add safe.directory '*' |
0 commit comments