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

WIP: Update dockerisation #3477

Merged
merged 40 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 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
7fde517
test fork
parithosh Aug 10, 2023
7d6e818
testing without exposed ports
parithosh Aug 10, 2023
8acf9b3
switch to commit ref approach
parithosh Aug 10, 2023
77508b5
update dockerfile
parithosh Aug 10, 2023
14759df
Merge branch 'dev' into update-dockerisation
parithosh Dec 22, 2023
ac912c5
Merge remote-tracking branch 'origin/dev' into update-dockerisation
parithosh Jan 2, 2024
a8d5724
Merge branch 'ethereum:dev' into update-dockerisation
parithosh Jan 3, 2024
65eaf5b
Merge remote-tracking branch 'refs/remotes/origin/update-dockerisatio…
parithosh Jan 3, 2024
d4044ac
dockerized test script
parithosh Jan 3, 2024
94ecfbc
renaming file
parithosh Jan 3, 2024
49b8c71
add comments
parithosh Jan 3, 2024
21882ad
update flag
parithosh Jan 3, 2024
0163d3e
add pylint
parithosh Jan 3, 2024
ee9ab80
mod workflow
parithosh Jan 3, 2024
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
31 changes: 31 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ docs/ssz
docs/fork_choice
docs/README.md
site

# docker test results
testResults
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ SOLIDITY_FILE_NAME = deposit_contract.json
DEPOSIT_CONTRACT_TESTER_DIR = ${SOLIDITY_DEPOSIT_CONTRACT_DIR}/web3_tester
CONFIGS_DIR = ./configs
TEST_PRESET_TYPE ?= minimal
NUMBER_OF_CORES=16
# Collect a list of generator names
GENERATORS = $(sort $(dir $(wildcard $(GENERATOR_DIR)/*/.)))
# Map this list of generator paths to "gen_{generator name}" entries
Expand Down Expand Up @@ -128,10 +129,10 @@ citest: pyspec
mkdir -p $(TEST_REPORT_DIR);
ifdef fork
. venv/bin/activate; cd $(PY_SPEC_DIR); \
python3 -m pytest -n 16 --bls-type=fastest --preset=$(TEST_PRESET_TYPE) --fork=$(fork) --junitxml=test-reports/test_results.xml eth2spec
python3 -m pytest -n $(NUMBER_OF_CORES) --bls-type=fastest --preset=$(TEST_PRESET_TYPE) --fork=$(fork) --junitxml=test-reports/test_results.xml eth2spec
else
. venv/bin/activate; cd $(PY_SPEC_DIR); \
python3 -m pytest -n 16 --bls-type=fastest --preset=$(TEST_PRESET_TYPE) --junitxml=test-reports/test_results.xml eth2spec
python3 -m pytest -n $(NUMBER_OF_CORES) --bls-type=fastest --preset=$(TEST_PRESET_TYPE) --junitxml=test-reports/test_results.xml eth2spec
endif


Expand Down
22 changes: 22 additions & 0 deletions docker/Dockerfile
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

1 change: 1 addition & 0 deletions requirements_preinstallation.txt
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
103 changes: 103 additions & 0 deletions scripts/build_run_docker_tests.sh
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