Skip to content

Commit

Permalink
Add tests for wheels built using cibuildwheel
Browse files Browse the repository at this point in the history
  • Loading branch information
mwydmuch committed Sep 7, 2023
1 parent 8820509 commit fb1f4a7
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ venv
vizdoom.egg-info
wheelhouse

# Tests
test_dockerfiles

# Copied from the original ZDoom repository (and modified)
*.cbp
*.ncb
Expand Down
29 changes: 29 additions & 0 deletions scripts/install_and_test_wheel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -e

# Set working dir to the root of the repo
cd $( dirname "${BASH_SOURCE[0]}" )/..

# Report directory
ls -lha .

# Report python version
python3 --version
python3 -c "import sys; print('Python', sys.version)"

# Find matching wheel file in wheelhouse
PYTHON_VERSION=$(python3 -c "import sys; print('{}{}'.format(sys.version_info.major, sys.version_info.minor))")
PYTHON_WHEEL=$(ls wheelhouse/vizdoom-*-cp${PYTHON_VERSION}-cp${PYTHON_VERSION}*.whl)

# Updgrade pip and install test deps
python3 -m pip install --upgrade pip
python3 -m pip install pytest psutil

# Install wheel
python3 -m pip install ${PYTHON_WHEEL}

# Test import
python3 -c "import vizdoom"

# Run tests
pytest tests
5 changes: 5 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Tests

This directory contains the tests for the project that can be run with pytest or by running the `test_*.py` or `manual_test_*.py` files directly.
Manual tests require significant amount of time, so they are not run by default by CI/CD.
The `build_test_*.sh` scripts test the build process of the project under different distrubutions and enviroments. To run them docker and cibuildwheels is required.
55 changes: 55 additions & 0 deletions tests/build_test_cibuildwheel_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
set -e

NC='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'

DOCKERFILES_DIR=$( dirname ${BASH_SOURCE[0]} )/wheels_test_dockerfiles
GENERATED_DOCKERFILES_DIR=tests/test_dockerfiles
IMAGE_PREFIX="vizdoom_wheels"

# Generate and run dockerfiles
# Array in format "<base docker image> <base dockerfile to use> <additional commands to add to the dockerfile after FROM statement>"
DOCKERFILES_TO_BUILD_AND_RUN=(
"almalinux:9 dnf-based.Dockerfile" # Python 3.9
"fedora:36 dnf-based.Dockerfile" # Python 3.10
"fedora:37 dnf-based.Dockerfile" # Python 3.11
"rockylinux:9 dnf-based.Dockerfile" # Python 3.9
"debian:11.6 apt-based.Dockerfile ENV LANG C.UTF-8" # Python 3.9
"ubuntu:20.04 apt-based.Dockerfile" # Python 3.8
"ubuntu:22.04 apt-based.Dockerfile" # Python 3.10
"continuumio/miniconda3:latest conda-based.Dockerfile" # Python 3.10
)

function create_dockerfile ( ) {
local all_args=("$@")
local base_image=$1
local base_name=$( basename "$( echo ${base_image} | tr ':' '_' )" )
local base_dockerfile=$2
local add_commands=("${all_args[@]:2}")

mkdir -p $GENERATED_DOCKERFILES_DIR
dockerfile=${GENERATED_DOCKERFILES_DIR}/${IMAGE_PREFIX}_${base_name}.Dockerfile

echo "FROM $base_image" > $dockerfile
echo "" >> $dockerfile
echo -e "${add_commands[@]}" >> $dockerfile
cat ${DOCKERFILES_DIR}/$base_dockerfile | tail -n +2 >> $dockerfile
}

for dockerfile_setting in "${DOCKERFILES_TO_BUILD_AND_RUN[@]}"; do
create_dockerfile $dockerfile_setting

echo -n "Building and running $dockerfile, saving output to $dockerfile.log ... "
filename=$( basename "$dockerfile" )
dockerfile_dir=$( dirname "$dockerfile" )
without_ext="${filename%.*}"
tag="${without_ext}:latest"
log="${dockerfile_dir}/${without_ext}.log"

docker build -t $tag -f $dockerfile . &> $log || ( echo -e "${RED}FAILED${NC}"; exit 1 )
docker run -it $tag &>> $log || ( echo -e "${RED}FAILED${NC}"; exit 1 )

echo -e "${GREEN}OK${NC}"
done
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,31 @@ NC='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'

DOCKERFILES_DIR=$( dirname "${BASH_SOURCE[0]}" )
GENERATED_DOCKERFILES_DIR=tmp_dockerfiles
DOCKERFILES_DIR=$( dirname ${BASH_SOURCE[0]} )/local_builds_dockerfiles
GENERATED_DOCKERFILES_DIR=tests/test_dockerfiles
IMAGE_PREFIX="vizdoom_local"

# Array in format "<base docker image> <base dockerfile to use> <additional commands to add to the dockerfile after FROM statement>"
DOCKERFILES_TO_BUILD_AND_RUN=(
"almalinux:9 dnf-based.Dockerfile RUN dnf install -y 'dnf-command(config-manager)' && dnf config-manager --set-enabled crb"
"tgagor/centos:stream9 dnf-based.Dockerfile RUN dnf install -y 'dnf-command(config-manager)' && dnf config-manager --set-enabled crb"
"fedora:36 dnf-based.Dockerfile"
"fedora:37 dnf-based.Dockerfile"
"rockylinux:9 dnf-based.Dockerfile RUN dnf install -y 'dnf-command(config-manager)' && dnf config-manager --set-enabled crb"
"debian:11.6 apt-based.Dockerfile ENV LANG C.UTF-8"
"ubuntu:18.04 apt-based.Dockerfile"
"ubuntu:20.04 apt-based.Dockerfile"
"ubuntu:22.04 apt-based.Dockerfile"
"ubuntu:latest apt-based.Dockerfile"
#"continuumio/miniconda3:latest conda-based.Dockerfile" # Does not work at the moment
)


# Build wheels using cibuildwheel
cibuildwheel --platform linux --arch $(uname -m)


# Test wheels inside docker containers
function create_dockerfile ( ) {
local all_args=("$@")
local base_image=$1
Expand All @@ -16,49 +38,26 @@ function create_dockerfile ( ) {
local add_commands=("${all_args[@]:2}")

mkdir -p $GENERATED_DOCKERFILES_DIR
dockerfile=${GENERATED_DOCKERFILES_DIR}/${base_name}.Dockerfile
dockerfile=${GENERATED_DOCKERFILES_DIR}/${IMAGE_PREFIX}_${base_name}.Dockerfile

echo "FROM $base_image" > $dockerfile
echo "" >> $dockerfile
echo -e "${add_commands[@]}" >> $dockerfile
cat ${DOCKERFILES_DIR}/$base_dockerfile | tail -n +2 >> $dockerfile
}

# Generate and run dockerfiles
# Array in florma "<base docker image> <base dockerfile to use> <additional commands to add to the dockerfile after FROM statement>"
DOCKERFILES_TO_BUILD_AND_RUN=(
#"almalinux:8 dnf-based.Dockerfile RUN dnf install -y 'dnf-command(config-manager)' && dnf config-manager --set-enabled powertools"
"almalinux:9 dnf-based.Dockerfile RUN dnf install -y 'dnf-command(config-manager)' && dnf config-manager --set-enabled crb"
#"tgagor/centos:stream8 dnf-based.Dockerfile RUN dnf install -y 'dnf-command(config-manager)' && dnf config-manager --set-enabled powertools"
"tgagor/centos:stream9 dnf-based.Dockerfile RUN dnf install -y 'dnf-command(config-manager)' && dnf config-manager --set-enabled crb"
#"fedora:34 dnf-based.Dockerfile" # EOL
#"fedora:35 dnf-based.Dockerfile" # EOL
"fedora:36 dnf-based.Dockerfile"
"fedora:37 dnf-based.Dockerfile"
#"rockylinux:8 dnf-based.Dockerfile RUN dnf install -y 'dnf-command(config-manager)' && dnf config-manager --set-enabled devel"
"rockylinux:9 dnf-based.Dockerfile RUN dnf install -y 'dnf-command(config-manager)' && dnf config-manager --set-enabled crb"
#"debian:10.13 apt-based.Dockerfile ENV LANG C.UTF-8" # EOL
"debian:11.6 apt-based.Dockerfile ENV LANG C.UTF-8"
#"ubuntu:18.04 apt-based.Dockerfile" # EOL
"ubuntu:20.04 apt-based.Dockerfile"
"ubuntu:22.04 apt-based.Dockerfile"
#"continuumio/miniconda3:latest conda-based.Dockerfile" # Does not work at the moment
)

for dockerfile_setting in "${DOCKERFILES_TO_BUILD_AND_RUN[@]}"; do
create_dockerfile $dockerfile_setting

echo -n "Building and running $dockerfile, saving output to $dockerfile.log ... "
filename=$( basename "$dockerfile" )
dockerfile_dir=$( dirname "$dockerfile" )
without_ext="${filename%.*}"
tag="vizdoom_${without_ext}:latest"
log="vizdoom_${without_ext}.log"
tag="${without_ext}:latest"
log="${dockerfile_dir}/${without_ext}.log"

docker build -t $tag -f $dockerfile . &> $log || ( echo -e "${RED}FAILED${NC}"; exit 1 )
docker run -it $tag &>> $log || ( echo -e "${RED}FAILED${NC}"; exit 1 )

echo -e "${GREEN}OK${NC}"

done

rm -rf $GENERATED_DOCKERFILES_DIR
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions tests/wheels_test_dockerfiles/apt-based.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM ubuntu:latest

ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe/Warsaw

WORKDIR vizdoom

# MINIMAL
RUN apt update && apt install -y python3-dev python3-pip

COPY . ./
CMD ["bash", "./scripts/install_and_test_wheel.sh"]
6 changes: 6 additions & 0 deletions tests/wheels_test_dockerfiles/conda-based.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM continuumio/miniconda3:latest

WORKDIR vizdoom

COPY . ./
CMD ["bash", "./scripts/install_and_test_wheel.sh"]
9 changes: 9 additions & 0 deletions tests/wheels_test_dockerfiles/dnf-based.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM fedora:latest

WORKDIR vizdoom

# MINIMAL
RUN dnf update -y && dnf clean all && dnf install -y python3-devel python3-pip

COPY . ./
CMD ["bash", "./scripts/install_and_test_wheel.sh"]

0 comments on commit fb1f4a7

Please sign in to comment.