Sign inSign up

justdevzero/py27-37-tools

By justdevzero

Updated 8 days ago

Python 2.7 and 3.7 side by side on Ubuntu 18.04 (bionic), with build tools and UTF-8 locales.

Image
0

75

justdevzero/py27-37-tools repository overview

# Python 2.7 and 3.7 side by side on Ubuntu 18.04 (bionic).
#
# Bionic is the last Ubuntu LTS carrying both interpreters in apt, which is why
# codebases finishing a 2-to-3 migration end up here: the two can coexist on
# one host, one service at a time moving over. This image is that host, so an
# application image can be built for either interpreter from a single base.
#
# It also pins the platform wheels resolve against: bionic ships glibc 2.27, so
# a manylinux_2_28 wheel picked on a modern machine is rejected here silently
# and shows up much later as an unrelated dependency conflict.
#
# What it does NOT do, on purpose: no virtualenv, and PATH is left alone. Both
# interpreters are reached as `python2.7` and `python3.7`, so whoever builds on
# top decides where its venv lives without fighting this image for PATH.

FROM ubuntu:18.04

ENV PYTHONUNBUFFERED=1

# Interpreters and their headers, to build and install C extensions.
# python3-distutils ships the distutils that Ubuntu splits out of the
# interpreter package, and that older setup.py files need in order to build.
#
# Toolchain: build-essential, binutils
# Geospatial: gdal-bin, libproj-dev, libgeos-dev
# Imaging (Pillow): libjpeg-turbo8*, libpng16-16
# PDF: wkhtmltopdf (the binary behind pdfkit)
# Vector graphics (pycairo): pkg-config, libcairo2-dev
# Unprivileged user proxy: gosu
# i18n: gettext, locales
# Tooling: less, vim, tree, wget, git, inotify-tools
RUN set -eux; \
    apt-get update; \
    apt-get install -y --no-install-recommends \
        python2.7 \
        python2.7-dev \
        python3.7 \
        python3.7-dev \
        python3.7-venv \
        python3-distutils \
        build-essential \
        binutils \
        gdal-bin \
        libproj-dev \
        libgeos-dev \
        libjpeg-turbo8 \
        libjpeg-turbo8-dev \
        libpng16-16 \
        wkhtmltopdf \
        pkg-config \
        libcairo2-dev \
        gosu \
        gettext \
        locales \
        less \
        vim \
        tree \
        wget \
        git \
        inotify-tools \
        ca-certificates; \
    update-ca-certificates; \
    apt-get clean; \
    rm -rf /var/lib/apt/lists/*

# UTF-8 locales for the languages an application is likely to format dates,
# numbers and currencies in. Add more with `locale-gen` at runtime if needed.
RUN set -eux; \
    for loc in \
        ca_ES cs_CZ de_DE en_GB en_US es_ES fr_FR hr_HR hu_HU it_IT \
        lt_LT nl_NL pl_PL pt_PT ru_RU sk_SK zh_CN; do \
        sed -i "s/^# ${loc}.UTF-8/${loc}.UTF-8/" /etc/locale.gen; \
    done; \
    locale-gen; \
    update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8

# A docker exec is not a login shell and does not read /etc/default/locale, so
# the values are set here as well. Python 2 in particular is quick to choke on
# non-ASCII output without them.
ENV LANG=en_US.UTF-8 \
    LANGUAGE= \
    LC_ALL=en_US.UTF-8

# pip for both interpreters. Bionic dropped pip for 2.7 from its repositories
# and never shipped one for 3.7, so both come from the pypa bootstrap, which
# still publishes the last release supporting each.
RUN set -eux; \
    wget -q -O /tmp/get-pip-2.7.py https://bootstrap.pypa.io/pip/2.7/get-pip.py; \
    wget -q -O /tmp/get-pip-3.7.py https://bootstrap.pypa.io/pip/3.7/get-pip.py; \
    python2.7 /tmp/get-pip-2.7.py; \
    python3.7 /tmp/get-pip-3.7.py; \
    rm /tmp/get-pip-2.7.py /tmp/get-pip-3.7.py; \
    python2.7 -m pip install --no-cache-dir virtualenv; \
    python3.7 -m pip install --no-cache-dir --upgrade "setuptools<60" wheel

# uv, pinned rather than installed from the vendor script, so the image is
# reproducible. It drives the Python 3.7 side only: uv needs an interpreter
# that understands `-I`, so 3.6 or newer, and refuses to touch python2.7.
ARG UV_VERSION=0.12.14
RUN set -eux; \
    wget -q -O /tmp/uv.tar.gz \
        "https://github.com/astral-sh/uv/releases/download/${UV_VERSION}/uv-x86_64-unknown-linux-gnu.tar.gz"; \
    tar -xzf /tmp/uv.tar.gz -C /tmp; \
    mv /tmp/uv-x86_64-unknown-linux-gnu/uv /tmp/uv-x86_64-unknown-linux-gnu/uvx /usr/local/bin/; \
    rm -rf /tmp/uv.tar.gz /tmp/uv-x86_64-unknown-linux-gnu; \
    uv --version

WORKDIR /work
CMD ["bash"]

Tag summary

Content type

Image

Digest

sha256:b2375496e

Size

413.4 MB

Last updated

8 days ago

docker pull justdevzero/py27-37-tools