Add testing Dockerfile (#470)

* Add testing Dockerfile

* Add comments

* Format table

* Add tests/README.md

* Rephrase

* add note in dockerfile
This commit is contained in:
Bas Nijholt 2023-03-26 18:18:18 -07:00 committed by GitHub
commit 1b08e8e6ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 104 additions and 0 deletions

26
.github/workflows/docker-build.yml vendored Normal file
View file

@ -0,0 +1,26 @@
name: docker
on:
push:
branches:
- "master"
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
push: true
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: ${{ secrets.DOCKERHUB_USERNAME }}/home-assistant-streamdeck-yaml:latest

58
Dockerfile Normal file
View file

@ -0,0 +1,58 @@
# See tests/README.md for instructions on how to run the tests.
# tl;dr:
# Run the following command in the adaptive-lighting repo folder to run the tests:
# docker run -v $(pwd):/app basnijholt/adaptive-lighting:latest
# Optionally build the image yourself with:
# docker build -t basnijholt/adaptive-lighting:latest .
FROM python:3.11-buster
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
git \
&& rm -rf /var/lib/apt/lists/*
# Clone home-assistant/core
RUN git clone https://github.com/home-assistant/core.git /core
# Install home-assistant/core dependencies
RUN pip3 install -r /core/requirements.txt --use-pep517 && \
pip3 install -r /core/requirements_test.txt --use-pep517 && \
pip3 install -e /core/ --use-pep517
# Clone the Adaptive Lighting repository
RUN git clone https://github.com/basnijholt/adaptive-lighting.git /app
# Setup symlinks in core
RUN ln -s /app/custom_components/adaptive_lighting /core/homeassistant/components/adaptive_lighting && \
ln -s /app/tests /core/tests/components/adaptive_lighting && \
# For test_dependencies.py
ln -s /core /app/core
# Install dependencies of components that Adaptive Lighting depends on
RUN pip3 install $(python3 /app/test_dependencies.py) --use-pep517
WORKDIR /core
CMD ["python3", \
# Enable Python development mode
"-X", "dev", \
# Run pytest
"-m", "pytest", \
# Verbose output
"-vvv", \
# Set a timeout of 9 seconds per test
"--timeout=9", \
# Print the 10 slowest tests
"--durations=10", \
# Measure code coverage for the 'homeassistant' package
"--cov='homeassistant'", \
# Generate an XML report of the code coverage
"--cov-report=xml", \
# Print a count of test results in the console
"-o", "console_output_style=count", \
# Run tests in the 'tests/components/adaptive_lighting' directory
"tests/components/adaptive_lighting" \
]

20
tests/README.md Normal file
View file

@ -0,0 +1,20 @@
# Developer notes for the tests directory
To run the tests, check out the [CI configuration](../.github/workflows/pytest.yml) to see how they are executed in the CI pipeline.
Alternatively, you can use the provided Docker image to run the tests locally.
To run the tests using the Docker image, navigate to the `adaptive-lighting` repo folder and execute the following command:
```bash
docker run -v $(pwd):/app basnijholt/adaptive-lighting:latest
```
This command will download the Docker image from [the adaptive-lighting Docker Hub repo]((https://hub.docker.com/r/basnijholt/adaptive-lighting)) and run the tests.
If you prefer to build the image yourself, use the following command:
```bash
docker build -t basnijholt/adaptive-lighting:latest --no-cache .
```
This might be necessary if the image on Docker Hub is outdated or if the [`test_dependencies.py`](../test_dependencies.py) file is updated.