-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run tests in a docker container (#342)
- Loading branch information
Showing
7 changed files
with
151 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: Docker Image Build for Tests | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
paths: | ||
- "tests/Dockerfile" | ||
- "tests/run.sh" | ||
- "tests/requirements.txt" | ||
- ".github/workflows/test-docker-image-build.yml" | ||
|
||
env: | ||
IMAGE_NAME: "pitop/pt-miniscreen-test-runner" | ||
PLATFORMS: "linux/amd64" | ||
|
||
jobs: | ||
build-push-docker-hub: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
with: | ||
version: latest | ||
install: true | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | ||
|
||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v3 | ||
with: | ||
images: ${{ env.IMAGE_NAME }} | ||
tags: | | ||
type=ref,event=branch | ||
- name: Build and push | ||
id: docker_build_push | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: tests | ||
file: tests/Dockerfile | ||
platforms: ${{ env.PLATFORMS }} | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
||
- name: Show image digest | ||
run: echo ${{ steps.docker_build_push.outputs.digest }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
FROM debian:bookworm | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
RUN apt update | ||
|
||
RUN apt install -y \ | ||
python3 \ | ||
python3-pip \ | ||
libfreetype6-dev \ | ||
libjpeg-dev \ | ||
zlib1g-dev | ||
|
||
RUN rm -f /usr/lib/python3.11/EXTERNALLY-MANAGED | ||
|
||
COPY requirements.txt /tmp/requirements.txt | ||
|
||
RUN pip3 install -r /tmp/requirements.txt --extra-index-url=https://packagecloud.io/pi-top/pypi/pypi/simple | ||
|
||
RUN rm -f /tmp/requirements.txt | ||
|
||
COPY scripts/run.sh / | ||
|
||
WORKDIR /src | ||
|
||
ENTRYPOINT [ "/run.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
## Tests | ||
|
||
We recommend running tests in a docker image. Most of the tests produce images that are compared with | ||
a base snapshot, but sometimes results might be a bit different from machine to machine (e.g.: image might be shifted 1 pixel). | ||
|
||
### Using pi-top test runner image | ||
|
||
``` | ||
$ docker run \ | ||
--rm \ | ||
--volume "$PWD":/src \ | ||
pitop/pt-miniscreen-test-runner:latest | ||
``` | ||
|
||
### Building the image | ||
|
||
Build the image by running: | ||
|
||
``` | ||
$ docker build -t pt-miniscreen-test-runner tests | ||
``` | ||
|
||
Then, run the tests with: | ||
|
||
``` | ||
$ docker run \ | ||
--rm \ | ||
--volume "$PWD":/src \ | ||
pt-miniscreen-test-runner | ||
``` | ||
|
||
### Updating base images | ||
|
||
Override the entrypoint to access the image using `bash`. Then use `pytest --snapshot-update` to update the snapshots in the tests folder. | ||
|
||
``` | ||
$ docker run \ | ||
--rm \ | ||
--volume "$PWD":/src \ | ||
--entrypoint bash \ | ||
pitop/pt-miniscreen-test-runner:latest | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
if [ ! -d "/src" ]; then | ||
echo "Error: /src directory not found, make sure to mount the project root directory to /src" | ||
exit 1 | ||
fi | ||
|
||
cd /src | ||
|
||
# Install new dependencies | ||
pip3 install -r tests/requirements.txt --extra-index-url=https://packagecloud.io/pi-top/pypi/pypi/simple | ||
|
||
# Run the tests | ||
pytest --verbose --cov-report term-missing --cov=pt_miniscreen || exit 1 | ||
|
||
# Generate the coverage report | ||
coverage xml |