Skip to content

Commit d34aea6

Browse files
authored
[ci] Add tests for non-native architectures (#622)
This change introduces a new job to the CI to test the SDK on non-native architectures. Github CI ATM provides amd64 runners by default, so the new job targets testing on arch64 for now. The tests are run in containers running on the target platform(s). The container definitions are supposed to exist in the directory .github/containers/nox-cross-arch. A definition for an arm64-ubuntu20.04-python3.11 container can be found there. Since the tests take quite a while to run, given that they run on emulations, this step runs only on the `merge_group` event.
2 parents 9e8b167 + e9b34c8 commit d34aea6

File tree

6 files changed

+179
-1
lines changed

6 files changed

+179
-1
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM docker.io/library/ubuntu:20.04
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
5+
# Install Python 3.11 and curl to install pip later
6+
RUN apt-get update -y && \
7+
apt-get install --no-install-recommends -y \
8+
software-properties-common && \
9+
add-apt-repository ppa:deadsnakes/ppa && \
10+
apt-get install --no-install-recommends -y \
11+
ca-certificates \
12+
curl \
13+
git \
14+
python3.11 \
15+
python3.11-distutils && \
16+
apt-get clean && \
17+
rm -rf /var/lib/apt/lists/*
18+
19+
# Install pip
20+
RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11
21+
22+
RUN update-alternatives --install \
23+
/usr/local/bin/python python /usr/bin/python3.11 1 && \
24+
python -m pip install --upgrade --no-cache-dir pip
25+
26+
COPY entrypoint.bash /usr/bin/entrypoint.bash
27+
28+
ENTRYPOINT ["/usr/bin/entrypoint.bash"]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "System details:" $(uname -a)
5+
echo "Machine:" $(uname -m)
6+
7+
exec "$@"

.github/workflows/ci.yaml

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,115 @@ jobs:
7979
run: nox -R -e "$NOX_SESSION"
8080
timeout-minutes: 10
8181

82+
nox-cross-arch:
83+
name: Cross-arch tests with nox
84+
if: github.event_name == 'merge_group'
85+
strategy:
86+
fail-fast: false
87+
# Before adding new items to this matrix, make sure that a dockerfile
88+
# exists for the combination of items in the matrix.
89+
# Refer to .github/containers/nox-cross-arch/README.md to learn how to
90+
# add and name new dockerfiles.
91+
matrix:
92+
arch:
93+
- arm64
94+
os:
95+
- ubuntu-20.04
96+
python:
97+
- "3.11"
98+
nox-session:
99+
- "pytest_min"
100+
- "pytest_max"
101+
runs-on: ${{ matrix.os }}
102+
103+
steps:
104+
- name: Fetch sources
105+
uses: actions/checkout@v3
106+
107+
- name: Set up QEMU
108+
uses: docker/setup-qemu-action@v2
109+
with:
110+
platforms: linux/${{ matrix.arch }}
111+
112+
- name: Set up Docker Buildx
113+
uses: docker/setup-buildx-action@v2
114+
115+
# This is a workaround to prevent the cache from growing indefinitely.
116+
# https://docs.docker.com/build/ci/github-actions/cache/#local-cache
117+
# https://github.com/docker/build-push-action/issues/252
118+
# https://github.com/moby/buildkit/issues/1896
119+
- name: Cache container layers
120+
uses: actions/cache@v3
121+
with:
122+
path: /tmp/.buildx-cache
123+
key: ${{ runner.os }}-buildx-nox-${{ matrix.arch }}-${{ matrix.os }}-${{ matrix.python }}
124+
125+
- name: Build image
126+
uses: docker/build-push-action@v4
127+
with:
128+
context: .github/containers/nox-cross-arch
129+
file: .github/containers/nox-cross-arch/${{ matrix.arch }}-${{ matrix.os }}-python-${{ matrix.python }}.Dockerfile
130+
platforms: linux/${{ matrix.arch }}
131+
tags: localhost/nox-cross-arch:latest
132+
push: false
133+
load: true
134+
cache-from: type=local,src=/tmp/.buildx-cache
135+
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
136+
137+
# Refer to the workaround mentioned above
138+
- name: Move cache
139+
run: |
140+
rm -rf /tmp/.buildx-cache
141+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
142+
143+
# Cache pip downloads
144+
- name: Cache pip downloads
145+
uses: actions/cache@v3
146+
with:
147+
path: /tmp/pip-cache
148+
key: nox-${{ matrix.nox-session }}-${{ matrix.arch }}-${{ matrix.os }}-${{ matrix.python }}-${{ hashFiles('**/pyproject.toml') }}
149+
150+
# This ensures that the docker container has access to the pip cache.
151+
# Changing the user in the docker-run step causes it to fail due to
152+
# incorrect permissions. Setting the ownership of the pip cache to root
153+
# before running is a workaround to this issue.
154+
- name: Set pip cache owners to root for docker
155+
run: if [[ -e /tmp/pip-cache ]]; then sudo chown -R root:root /tmp/pip-cache; fi
156+
157+
- name: Run nox
158+
run: |
159+
docker run \
160+
--rm \
161+
-v $(pwd):/${{ github.workspace }} \
162+
-v /tmp/pip-cache:/root/.cache/pip \
163+
-w ${{ github.workspace }} \
164+
--net=host \
165+
--platform linux/${{ matrix.arch }} \
166+
localhost/nox-cross-arch:latest \
167+
bash -c "pip install -e .[dev-noxfile]; nox --install-only -e ${{ matrix.nox-session }}; pip freeze; nox -e ${{ matrix.nox-session }}"
168+
timeout-minutes: 30
169+
170+
# This ensures that the runner has access to the pip cache.
171+
- name: Reset pip cache ownership
172+
if: always()
173+
run: sudo chown -R $USER:$USER /tmp/pip-cache
174+
175+
# This job runs if `nox-cross-arch` ran and succeeded.
176+
# This is required because, when the `nox-cross-arch` job is skipped, its
177+
# inner matrix is not expanded, and branch protection rules on the
178+
# inner-matrix jobs get stuck. So instead of `nox-cross-arch`, this job can be
179+
# used in the branch protection rules.
180+
# At the time of writing this, there is an ongoing discussion about this here:
181+
# https://github.com/orgs/community/discussions/9141
182+
nox-cross-arch-all:
183+
name: Cross-arch tests with nox
184+
needs: ["nox-cross-arch"]
185+
runs-on: ubuntu-20.04
186+
steps:
187+
- name: Return true
188+
run: true
189+
190+
82191
build:
83192
name: Build distribution packages
84193
runs-on: ubuntu-20.04
@@ -176,7 +285,7 @@ jobs:
176285

177286
publish-docs:
178287
name: Publish documentation website to GitHub pages
179-
needs: ["nox", "test-installation"]
288+
needs: ["nox", "nox-cross-arch-all", "test-installation"]
180289
if: github.event_name == 'push'
181290
runs-on: ubuntu-20.04
182291
permissions:

CONTRIBUTING.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,27 @@ These are the steps to create a new release:
154154
eventually too).
155155

156156
7. Celebrate!
157+
158+
## Cross-Arch Testing
159+
160+
This project has built-in support for testing across multiple architectures. Currently, our CI conducts tests on `arm64` machines using QEMU emulation. We also have the flexibility to expand this support to include additional architectures in the future.
161+
162+
This project containers dockerfiles that can be used in the CI to test the
163+
python package in non-native machine architectures, e.g., `arm64`.
164+
The dockerfiles exist in the directory `.github/containers/nox-cross-arch`, and
165+
follow a naming scheme so that they can be easily used in build matrices in the
166+
CI, in `nox-cross-arch` job. The naming scheme is:
167+
168+
```
169+
<arch>-<os>-python-<python-version>.Dockerfile
170+
```
171+
172+
E.g.,
173+
174+
```
175+
arm64-ubuntu-20.04-python-3.11.Dockerfile
176+
```
177+
178+
If a dockerfile for your desired target architecture, OS, and python version
179+
does not exist here, please add one before proceeding to add your options to the
180+
test matrix.

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88

99
A development kit to interact with the Frequenz development platform.
1010

11+
## Supported Platforms
12+
13+
This SDK is supported on and thoroughly tested with the following platforms:
14+
15+
- **Python:** 3.11
16+
- **Operating System:** Ubuntu 20.04
17+
- **Architectures:** amd64, arm64
18+
1119
## Quick Start
1220

1321
We assume you are on a system with Python available. If that is not the case,

RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
- Now when printing `FormulaEngine` for debugging purposes the the formula will be shown in infix notation, which should be easier to read.
3232

33+
- The CI now runs cross-arch tests on `arm64` architectures.
34+
3335
## Bug Fixes
3436

3537
<!-- Here goes notable bug fixes that are worth a special mention or explanation -->

0 commit comments

Comments
 (0)