Skip to content

Commit 9058627

Browse files
committed
Merge branch 'init' into 'main'
Add first implementation Closes #1 See merge request divio/incubator/multi-python!1
2 parents e876df2 + f299a14 commit 9058627

File tree

6 files changed

+164
-0
lines changed

6 files changed

+164
-0
lines changed

.gitlab-ci.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
image: docker:latest
2+
3+
include:
4+
- project: divio/infra/gitlab-pipelines
5+
ref: master
6+
file: docker-project/.gitlab-ci.yml
7+
8+
variables:
9+
PUBLIC_REPOSITORY: divio/multi-python
10+
PUBLIC_CREDS: ${DOCKER_HUB_USER}:${DOCKER_HUB_TOKEN}
11+
12+
build-docker-image:
13+
before_script:
14+
- !reference [.buildx, install]
15+
# Update the QEMU version, this is required for libc-bin on ARM
16+
- docker run --rm --privileged linuxkit/binfmt:af88a591f9cc896a52ce596b9cf7ca26a061ef97
17+
18+
test:
19+
stage: qa
20+
needs: [build-docker-image]
21+
image: ${CI_REGISTRY_IMAGE}/build:${CI_PIPELINE_IID}
22+
except:
23+
- tags
24+
script:
25+
- cd test && tox
26+
27+
release-latest-docker-image:
28+
variables:
29+
DST_REGISTRY_CREDS: ${PUBLIC_CREDS}
30+
TARGET_IMAGE_NAME: ${PUBLIC_REPOSITORY}:latest
31+
32+
release-tag-docker-image:
33+
variables:
34+
DST_REGISTRY_CREDS: ${PUBLIC_CREDS}
35+
TARGET_IMAGE_NAME: ${PUBLIC_REPOSITORY}:${CI_COMMIT_TAG}

Dockerfile

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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 '*'

Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
IMAGE_NAME = registry.gitlab.com/divio/incubator/multi-python
2+
TARGET ?= amd64
3+
4+
lint:
5+
docker run --rm -e LINT_FILE_DOCKER=Dockerfile -v $(CURDIR):/app divio/lint /bin/lint ${ARGS}
6+
7+
build:
8+
docker build -t ${IMAGE_NAME} --platform linux/${TARGET} .

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Multi-Python Image
2+
3+
This repository defines a Python image based on Ubuntu with multiple Python versions installed,
4+
along with the `tox` executable. It is meant to use in CI for test purposes.
5+
6+
It supports both ARM and AMD architectures.
7+
8+
## Python versions
9+
10+
The list of Python versions to install is passed as arguments (see `Dockerfile`).
11+
One Python version must be selected as "main" - it will be used to install `tox`.
12+
Along with "regular" Python versions, one pypy version will also be installed.
13+
14+
**IMPORTANT**: Python versions must be available either in the official Ubuntu repositories or in
15+
the [deadsnakes PPA](https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa). The PyPy version should
16+
be available at https://www.pypy.org/download.html.
17+
18+
## Usage
19+
20+
Run the following from a terminal at the root of your Python project:
21+
```bash
22+
docker run --rm -it -v $(PWD):/app registry.gitlab.com/divio/incubator/multi-Python:latest tox
23+
```
24+
25+
## Development
26+
27+
After updating the Python versions in the `Dockerfile`, ensure you also update `test/tox.ini` to
28+
reflect the change.

test/test_foo.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
assert True

test/tox.ini

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[tox]
2+
envlist = py37,py38,py39,py3.10,py3.11,pypy3
3+
skip_missing_interpreters = false

0 commit comments

Comments
 (0)