-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 🐳 add Dockerfile and dockerfile based script for consensus-spec tests
- Loading branch information
Showing
7 changed files
with
165 additions
and
2 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,2 @@ | ||
**/venv | ||
**/.venv |
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 |
---|---|---|
|
@@ -66,6 +66,37 @@ 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: get git commit hash | ||
id: git_commit_hash | ||
shell: bash | ||
run: | | ||
echo "git_commit_hash=$(echo $(git log --pretty=format:'%h' -n 1))" >> $GITHUB_OUTPUT | ||
- 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/consensus-specs-dockerfile-test:${{ steps.git_commit_hash.outputs.git_commit_hash }} | ||
- name: Test the image by running the linter | ||
run: | | ||
docker run localhost:5000/consensus-specs-dockerfile-test:${{ steps.git_commit_hash.outputs.git_commit_hash }} make lint | ||
pyspec-tests: | ||
runs-on: self-hosted | ||
needs: [preclear,lint,codespell,table_of_contents] | ||
|
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 |
---|---|---|
|
@@ -46,3 +46,6 @@ docs/ssz | |
docs/fork_choice | ||
docs/README.md | ||
site | ||
|
||
# docker test results | ||
testResults |
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,22 @@ | ||
# Rename the build stage from 'base' to 'builder' for clarification and code readability | ||
FROM python:3.11.0-slim-bullseye as builder | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive \ | ||
WORKDIR=/consensus-specs \ | ||
PIP_UPGRADE_CMD="python -m pip install --upgrade pip" \ | ||
INSTALL_CMD="apt install -y git build-essential" | ||
|
||
RUN mkdir ${WORKDIR} | ||
WORKDIR ${WORKDIR} | ||
|
||
# Chain the commands together | ||
RUN apt update && ${INSTALL_CMD} && ${PIP_UPGRADE_CMD} && rm -rf /var/lib/apt/lists/* | ||
|
||
# Copy the current directory contents into the builder | ||
COPY . . | ||
|
||
# Inline installation commands | ||
RUN make install_test && \ | ||
make preinstallation && \ | ||
make pyspec | ||
|
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pip>=23.1.2 | ||
wheel>=0.40.0 | ||
setuptools>=68.0.0 | ||
pylint>=3.0.0 |
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,103 @@ | ||
#! /bin/sh | ||
|
||
# Run 'consensus-specs' tests from a docker container instance. | ||
# *Be sure to launch Docker before running this script.* | ||
# | ||
# It does the below: | ||
# 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. | ||
|
||
|
||
# Set variables | ||
ALL_EXECUTABLE_SPECS=("phase0" "altair" "bellatrix" "capella" "deneb" "eip6110" "whisk") | ||
TEST_PRESET_TYPE=minimal | ||
FORK_TO_TEST=phase0 | ||
NUMBER_OF_CORES=4 | ||
WORKDIR="//consensus-specs//tests//core//pyspec" | ||
ETH2SPEC_FOLDER_NAME="eth2spec" | ||
CONTAINER_NAME="consensus-specs-tests" | ||
DATE=$(date +"%Y%m%d-%H-%M") | ||
# Default flag values | ||
version=$(git log --pretty=format:'%h' -n 1) | ||
IMAGE_NAME="consensus-specs:$version" | ||
number_of_core=4 | ||
|
||
# displays the available options | ||
display_help() { | ||
echo "Run 'consensus-specs' tests from a container instance." | ||
echo "Be sure to launch Docker before running this script." | ||
echo | ||
echo "Syntax: build_run_test.sh [--v TAG | --n NUMBER_OF_CORE | --f FORK_TO_TEST | --p PRESET_TYPE | --a | --h HELP]" | ||
echo " --f <fork> Specify the fork to test" | ||
echo " --i <image_name> Specify the docker image to use" | ||
echo " --n <number> Specify the number of cores" | ||
echo " --p <type> Specify the test preset type" | ||
echo " --a Test all forks" | ||
echo " --h Display this help and exit" | ||
} | ||
|
||
# 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 results from the container to a local folder | ||
copy_test_results() { | ||
local fork_name="$1" # Storing the first argument in a variable | ||
|
||
docker cp $CONTAINER_NAME:$WORKDIR/test-reports/test_results.xml ./testResults/test-results-$fork_name-$DATE.xml | ||
} | ||
|
||
# Function to check if the Docker image already exists | ||
image_exists() { | ||
docker images --format '{{.Repository}}:{{.Tag}}' | grep -q "$1" | ||
} | ||
|
||
# Parse command line arguments | ||
while [[ "$#" -gt 0 ]]; do | ||
case $1 in | ||
--f) FORK_TO_TEST="$2"; shift ;; | ||
--v) IMAGE_NAME="$2"; shift ;; | ||
--n) NUMBER_OF_CORES="$2"; shift ;; | ||
--p) TEST_PRESET_TYPE="$2"; shift ;; | ||
--a) FORK_TO_TEST="all" ;; | ||
--h) display_help; exit 0 ;; | ||
*) echo "Unknown parameter: $1"; display_help; exit 1 ;; | ||
esac | ||
shift | ||
done | ||
|
||
# initialize a test result directory | ||
mkdir -p ./testResults | ||
|
||
# Only clean container after user exit console | ||
trap cleanup SIGINT | ||
|
||
# Build Docker container if it doesn't exist | ||
if ! image_exists "$IMAGE_NAME"; then | ||
echo "Image $IMAGE_NAME does not exist. Building Docker image..." | ||
docker build ../ -t $IMAGE_NAME -f ../docker/Dockerfile | ||
else | ||
echo "Image $IMAGE_NAME already exists. Skipping build..." | ||
fi | ||
|
||
# Equivalent to `make citest with the subsequent flags` | ||
if [ "$FORK_TO_TEST" == "all" ]; then | ||
for fork in "${ALL_EXECUTABLE_SPECS[@]}"; do | ||
docker run --name $CONTAINER_NAME $IMAGE_NAME \ | ||
make citest fork=$fork TEST_PRESET_TYPE=$TEST_PRESET_TYPE NUMBER_OF_CORES=$NUMBER_OF_CORES | ||
copy_test_results $fork | ||
done | ||
else | ||
docker run --name $CONTAINER_NAME $IMAGE_NAME \ | ||
make citest fork=$FORK_TO_TEST TEST_PRESET_TYPE=$TEST_PRESET_TYPE NUMBER_OF_CORES=$NUMBER_OF_CORES | ||
copy_test_results $FORK_TO_TEST | ||
fi | ||
|
||
# Stop and remove the container | ||
cleanup |