Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐳 Dockerize spec tests #3475

Closed
Closed
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5ed33fd
🐳 add Dockerfile for consensus-spec project
wenceslas-sanchez Aug 7, 2023
65979d3
✨ add bash script to iteract with consensus-specs image
wenceslas-sanchez Aug 7, 2023
d3d3867
➕ add all package needed to run pyspec test + test generator
wenceslas-sanchez Aug 7, 2023
a514b9d
🙈 add .dockerignore and remove venv potential files
wenceslas-sanchez Aug 7, 2023
9769c7d
🎨 add doc + move into workdir to builder
wenceslas-sanchez Aug 7, 2023
d44b857
➖ remove useless (for test running) dep
wenceslas-sanchez Aug 7, 2023
617298d
🐛 only reference killed containers
wenceslas-sanchez Aug 7, 2023
548a0f2
📝 add documentation + helps
wenceslas-sanchez Aug 7, 2023
11e316f
🔧 move test requirements to ``setup.py``
wenceslas-sanchez Aug 8, 2023
aae8b0f
✨ add Dockerfile script for consistency testing
wenceslas-sanchez Aug 8, 2023
6591458
➕ add linter dependencies
wenceslas-sanchez Aug 8, 2023
8b25aea
♻️ simply by naming the container + add doc
wenceslas-sanchez Aug 8, 2023
29f9e52
🚸 clean container when user exit console to let him see the console o…
wenceslas-sanchez Aug 8, 2023
183d94a
🔥 remove duplicated requirements
wenceslas-sanchez Aug 8, 2023
4dced70
⏪️ revert black formatter changes
wenceslas-sanchez Aug 8, 2023
c0a758d
⏪️ revert black formatter changes
wenceslas-sanchez Aug 8, 2023
186a032
⚗️ test the github actions dockerfile-test
wenceslas-sanchez Aug 9, 2023
26a0de1
⚗️ set context to repository
wenceslas-sanchez Aug 9, 2023
029cb6f
Merge branch 'dev' into test-dockerisation
wenceslas-sanchez Aug 9, 2023
b82a865
⚗️ add port + service
wenceslas-sanchez Aug 9, 2023
dfc9e9d
🔥 remove dockerfile_test script
wenceslas-sanchez Aug 9, 2023
20a1d09
🐛 remove useless env variable usage
wenceslas-sanchez Aug 9, 2023
09ea790
🐛 fotget flake8 context
wenceslas-sanchez Aug 9, 2023
dc6eac4
✅ run pylint instead of flake8
wenceslas-sanchez Aug 9, 2023
2769316
✅ pylint returc exit code != 0 if error of fatal is encountered
wenceslas-sanchez Aug 9, 2023
fd8605c
Update scripts/run_test.sh
wenceslas-sanchez Aug 10, 2023
1a046cd
📝 add doc to run the image test
wenceslas-sanchez Sep 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/venv
**/.venv
27 changes: 27 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defaults:

env:
TEST_PRESET_TYPE: "minimal"
TEST_TAG: "consensus-specs-dockerfile-test:latest"

on:
push:
Expand Down Expand Up @@ -66,6 +67,32 @@ jobs:
- name: Run linter for test generators
run: make lint_generators

dockerfile-test:
runs-on: self-hosted
needs: preclear
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- name: Checkout this repo
uses: actions/[email protected]
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
- name: Build and push to local registry
uses: docker/build-push-action@v4
with:
context: .
file: ./docker/Dockerfile
push: true
tags: localhost:5000/${{ env.TEST_TAG }}
- name: Test the image
run: |
docker run localhost:5000/${{ env.TEST_TAG }} pylint --rcfile ./linter.ini --errors-only pysetup

pyspec-tests:
runs-on: self-hosted
needs: [preclear,lint,codespell,table_of_contents]
Expand Down
16 changes: 16 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Build the consensus-specs image using the builder pattern.
# This image is base on the Debian slim distribution.
FROM python:3.11.0-slim-bullseye as base


FROM base as builder
RUN mkdir /consensus-specs
WORKDIR /consensus-specs
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update && apt install -y git
RUN python -m pip install --upgrade pip

COPY . .

RUN pip install -r requirements_preinstallation.txt -e .[lint] -e .[test]
RUN python setup.py pyspecdev
76 changes: 76 additions & 0 deletions scripts/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#! /bin/sh

# Run 'consensus-specs' tests from a container instance.
# *Be sure to launch Docker before running this script.*
#
# It does the bellow:
wenceslas-sanchez marked this conversation as resolved.
Show resolved Hide resolved
# 1. Run pytest for consensus-specs in a container.
# 2. Copy and paste the coverage report.
# 3. Remove all exited containers that use the consensus-specs:<TAG> images.


# Constants
ALL_EXECUTABLE_SPECS=("phase0" "altair" "bellatrix" "capella" "deneb" "eip6110" "whisk")
TEST_PRESET_TYPE=minimal
WORKDIR="//consensus-specs//tests//core//pyspec"
ETH2SPEC_FOLDER_NAME="eth2spec"
CONTAINER_NAME="consensus-specs-tests"

COV_HTML_OUT=.htmlcov

# Default flag values
version=latest
number_of_core=4

# Generates coverage scope
coverage_scope=()
for spec in "${ALL_EXECUTABLE_SPECS[@]}"
do
coverage_scope+=("--cov=${ETH2SPEC_FOLDER_NAME}.${spec}.${TEST_PRESET_TYPE}")
done

display_help() {
echo "Run 'consensus-specs' tests from a container instance."
echo "Be sure to launch Docker before running this script."
echo
echo "Syntax: run_test [-v TAG | -n NUMBER_OF_CORE | -h HELP]"
echo "-v Specify the image tag for consensus-specs."
echo "-n Specify the number of core to run tests."
echo "-h Get helps."
}

# Parse provided flags
while getopts v:n:h flag
do
case "${flag}" in
v) version=$OPTARG;;
n) number_of_core=$OPTARG;;
h) display_help && $SHELL;;
\?) echo "not valid -$OPTARG" && $SHELL;;
esac
done

# Stop and remove the 'consensus-specs-dockerfile-test' container.
# If this container doesn't exist, then a error message is printed
# (but the process is not stopped).
cleanup() {
echo "Stop and remove the 'consensus-specs-tests' container."
docker stop $CONTAINER_NAME || true && docker rm $CONTAINER_NAME || true
}

# Copy the coverage report from the container to the local
copy_coverage_report() {
docker cp $$CONTAINER_NAME:$WORKDIR/$COV_HTML_OUT ./$COV_HTML_OUT
}

cleanup
# Equivalent to `make test`
docker run -w $WORKDIR --name $CONTAINER_NAME consensus-specs:$version \
pytest -n $number_of_core --disable-bls $coverage_scope --cov-report="html:${COV_HTML_OUT}" --cov-branch eth2spec

# Get coverage report form container instance
$(copy_coverage_report)
# Only clean container after user exit console
trap cleanup EXIT

$SHELL