Skip to content

Commit

Permalink
Merge 77b59a7 into 5461777
Browse files Browse the repository at this point in the history
  • Loading branch information
megies committed Aug 1, 2016
2 parents 5461777 + 77b59a7 commit 57591bf
Show file tree
Hide file tree
Showing 17 changed files with 180 additions and 28 deletions.
22 changes: 22 additions & 0 deletions misc/docker_tests/README.md
Expand Up @@ -22,6 +22,28 @@ Running it without any commands will execute the test suite on all available ima
$ ./run_obspy_tests.sh
```

Additionally arguments can be passed to `obspy-runtests` in the Docker images
with the `-e` argument. To for example only the MiniSEED test suite on CentOS
7, do

```bash
$ ./run_obspy_tests.sh -eio.mseed centos_7
```

A specific commit from a specific obspy fork (or main repo) can be tested using
the `-t` (for "target") argument.

Make sure to use the `-e` argument before the list of images to run on.

```bash
$ # test a commit that is in the obspy main repo
$ ./run_obspy_tests.sh -tobspy:bdc6dd855c00c831bcc007b607d83f6070b5b1c0
$ # test a commit that only exists in a fork (but might be the tip of a PR)
$ ./run_obspy_tests.sh -tclaudiodsf:2fa3d3bdaded126a9ebdaf73cf60403c1acb3457
```

Make sure to use the `-t` argument before the list of images to run on.

If the image is not yet available it will be created automatically. The
`base_images` directory contains all available images receipts.

Expand Down
3 changes: 2 additions & 1 deletion misc/docker_tests/base_images/centos_7/Dockerfile
Expand Up @@ -7,6 +7,7 @@ RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.
RUN yum -y upgrade || true
RUN yum install -y gcc numpy scipy python-matplotlib python-sqlalchemy python-lxml python-mock python-basemap python-basemap-data python-pip python-requests python-decorator
RUN easy_install -U setuptools pip
RUN pip install flake8 future
RUN pip install future
RUN pip install https://github.com/Damgaard/PyImgur/archive/9ebd8bed9b3d0ae2797950876f5c1e64a560f7d8.zip
# Force agg.
RUN mkdir -p /root/.matplotlib && echo "backend: agg" > /root/.matplotlib/matplotlibrc
3 changes: 2 additions & 1 deletion misc/docker_tests/base_images/debian_7_wheezy/Dockerfile
Expand Up @@ -5,5 +5,6 @@ MAINTAINER Lion Krischer
# Can fail on occasion.
RUN apt-get update && apt-get upgrade || true
RUN apt-get -y install python-numpy python-scipy python-matplotlib python-sqlalchemy python-lxml python-mock python-mpltoolkits.basemap python-mpltoolkits.basemap-data python-pip ttf-bitstream-vera python-decorator python-requests
RUN pip install flake8 future
RUN pip install future
RUN pip install https://github.com/Damgaard/PyImgur/archive/9ebd8bed9b3d0ae2797950876f5c1e64a560f7d8.zip
RUN echo "backend: agg" > /etc/matplotlibrc
Expand Up @@ -5,5 +5,6 @@ MAINTAINER Lion Krischer
# Can fail on occasion.
RUN apt-get update && apt-get upgrade || true
RUN apt-get -y install python-numpy python-scipy python-matplotlib python-sqlalchemy python-lxml python-mock python-mpltoolkits.basemap python-mpltoolkits.basemap-data python-pip ttf-bitstream-vera python-decorator python-requests
RUN pip install flake8 future
RUN pip install future
RUN pip install https://github.com/Damgaard/PyImgur/archive/9ebd8bed9b3d0ae2797950876f5c1e64a560f7d8.zip
RUN echo "backend: agg" > /etc/matplotlibrc
3 changes: 2 additions & 1 deletion misc/docker_tests/base_images/debian_8_jessie/Dockerfile
Expand Up @@ -5,4 +5,5 @@ MAINTAINER Lion Krischer
# Can fail on occasion.
RUN apt-get update && apt-get upgrade || true
RUN apt-get -y install python-numpy python-scipy python-matplotlib python-sqlalchemy python-lxml python-mock python-mpltoolkits.basemap python-mpltoolkits.basemap-data python-pip python-tornado ttf-bitstream-vera python-decorator python-requests
RUN pip install flake8 future
RUN pip install future
RUN pip install https://github.com/Damgaard/PyImgur/archive/9ebd8bed9b3d0ae2797950876f5c1e64a560f7d8.zip
8 changes: 0 additions & 8 deletions misc/docker_tests/base_images/fedora_22/Dockerfile

This file was deleted.

3 changes: 2 additions & 1 deletion misc/docker_tests/base_images/fedora_23/Dockerfile
Expand Up @@ -4,4 +4,5 @@ MAINTAINER Lion Krischer

# Can fail on occasion.
RUN dnf -y upgrade || true
RUN dnf install -y gcc redhat-rpm-config numpy scipy python-matplotlib python-sqlalchemy python-lxml python-mock python-basemap python-basemap-data python-tornado python-pip python-decorator python-requests python-flake8 python-future
RUN dnf install -y gcc redhat-rpm-config numpy scipy python-matplotlib python-sqlalchemy python-lxml python-mock python-basemap python-basemap-data python-tornado python-pip python-decorator python-requests python-future
RUN pip install https://github.com/Damgaard/PyImgur/archive/9ebd8bed9b3d0ae2797950876f5c1e64a560f7d8.zip
8 changes: 8 additions & 0 deletions misc/docker_tests/base_images/fedora_24/Dockerfile
@@ -0,0 +1,8 @@
FROM fedora:24

MAINTAINER Lion Krischer

# Can fail on occasion.
RUN dnf -y upgrade || true
RUN dnf install -y gcc redhat-rpm-config numpy scipy python-matplotlib python-sqlalchemy python-lxml python-mock python-basemap python-basemap-data python-tornado python-pip python-decorator python-requests python-future
RUN pip install https://github.com/Damgaard/PyImgur/archive/9ebd8bed9b3d0ae2797950876f5c1e64a560f7d8.zip
3 changes: 2 additions & 1 deletion misc/docker_tests/base_images/opensuse_13_2/Dockerfile
Expand Up @@ -5,5 +5,6 @@ MAINTAINER Lion Krischer
RUN zypper --non-interactive addrepo http://download.opensuse.org/repositories/Application:/Geo/openSUSE_13.2/Application:Geo.repo
RUN zypper --non-interactive --no-gpg-checks refresh
RUN zypper --non-interactive update
RUN zypper --non-interactive install gcc python-devel python-numpy python-scipy python-matplotlib python-SQLAlchemy python-lxml python-mock python-pip python-tornado python-requests python-decorator python-flake8 python-basemap python-basemap-data python-nose ca-certificates-mozilla
RUN zypper --non-interactive install gcc python-devel python-numpy python-scipy python-matplotlib python-SQLAlchemy python-lxml python-mock python-pip python-tornado python-requests python-decorator python-basemap python-basemap-data python-nose ca-certificates-mozilla
RUN pip install future
RUN pip install https://github.com/Damgaard/PyImgur/archive/9ebd8bed9b3d0ae2797950876f5c1e64a560f7d8.zip
3 changes: 2 additions & 1 deletion misc/docker_tests/base_images/opensuse_leap_42_1/Dockerfile
Expand Up @@ -5,6 +5,7 @@ MAINTAINER Lion Krischer
RUN zypper --non-interactive addrepo http://download.opensuse.org/repositories/Application:/Geo/openSUSE_Leap_42.1/Application:Geo.repo
RUN zypper --non-interactive --no-gpg-checks refresh
RUN zypper --non-interactive update
RUN zypper --non-interactive install gcc python-devel python-numpy python-scipy python-matplotlib python-SQLAlchemy python-lxml python-mock python-pip python-tornado python-requests python-decorator python-flake8 python-basemap python-basemap-data python-nose
RUN zypper --non-interactive install gcc python-devel python-numpy python-scipy python-matplotlib python-SQLAlchemy python-lxml python-mock python-pip python-tornado python-requests python-decorator python-basemap python-basemap-data python-nose
RUN pip install --index-url=http://pypi.python.org/simple/ --trusted-host pypi.python.org future
RUN pip install https://github.com/Damgaard/PyImgur/archive/9ebd8bed9b3d0ae2797950876f5c1e64a560f7d8.zip
RUN zypper --non-interactive install ca-certificates-mozilla
Expand Up @@ -5,5 +5,6 @@ MAINTAINER Lion Krischer
# Can fail on occasion.
RUN apt-get update && apt-get upgrade || true
RUN apt-get -y install python-numpy python-scipy python-matplotlib python-sqlalchemy python-lxml python-mock python-mpltoolkits.basemap python-mpltoolkits.basemap-data python-pip python-tornado ttf-bitstream-vera python-decorator python-requests
RUN pip install flake8 future
RUN pip install future
RUN pip install https://github.com/Damgaard/PyImgur/archive/9ebd8bed9b3d0ae2797950876f5c1e64a560f7d8.zip
RUN echo "backend: agg" > /etc/matplotlibrc
3 changes: 2 additions & 1 deletion misc/docker_tests/base_images/ubuntu_14_04_trusty/Dockerfile
Expand Up @@ -5,4 +5,5 @@ MAINTAINER Lion Krischer
# Can fail on occasion.
RUN apt-get update && apt-get upgrade || true
RUN apt-get -y install python-numpy python-scipy python-matplotlib python-sqlalchemy python-lxml python-mock python-mpltoolkits.basemap python-mpltoolkits.basemap-data python-pip python-tornado ttf-bitstream-vera python-requests python-decorator
RUN pip install flake8 future
RUN pip install future
RUN pip install https://github.com/Damgaard/PyImgur/archive/9ebd8bed9b3d0ae2797950876f5c1e64a560f7d8.zip
@@ -1,8 +1,9 @@
FROM ubuntu:15.10
FROM ubuntu:16.04

MAINTAINER Lion Krischer

# Can fail on occasion.
RUN apt-get update && apt-get upgrade || true
RUN apt-get -y install python-numpy python-scipy python-matplotlib python-sqlalchemy python-lxml python-mock python-mpltoolkits.basemap python-mpltoolkits.basemap-data python-pip python-tornado ttf-bitstream-vera
RUN pip install flake8 future
RUN pip install future
RUN pip install https://github.com/Damgaard/PyImgur/archive/9ebd8bed9b3d0ae2797950876f5c1e64a560f7d8.zip
@@ -0,0 +1,47 @@
#!/bin/bash

mkdir -p logs
LOG=logs/github_get_all_pr_heads_without_docker-testbot_status.log

rm $LOG

# get a list of commit hashes for open pull requests
DATA=`curl --silent -H "Authorization: token ${OBSPY_COMMIT_STATUS_TOKEN}" --request GET 'https://api.github.com/repos/obspy/obspy/pulls?state=open&sort=updated&direction=desc&per_page=100'`
echo $DATA >> $LOG
echo "" >> $LOG
# echo without quotes gets rid of line breaks, which makes regex simpler
# than get rid of spaces and tabs with sed
# than extract all matches with grep, one per line
# ..assuming the following structure in the returned json:
# ...
# "statuses_url": "https://api.github.com/repos/obspy/obspy/statuses/dd58fbbc33a8d8ce6f1a76013a5daa9e4a7db72a",
# "head": {
# "label": "obspy:docker_rm_old_logs",
# "ref": "docker_rm_old_logs",
# "sha": "dd58fbbc33a8d8ce6f1a76013a5daa9e4a7db72a",
# "user": {
# "login": "obspy",
# ...
# finally extract the interesting parts with sed and regex
COMMITS=`echo $DATA | sed 's#\s##g' | grep -s --only-matching --extended-regexp '"head":{"label":"[^"]*","ref":"[^"]*","sha":"[a-z0-9]{40}"' | sed 's#.*"label":"\([^:]*\):.*"sha":"\([a-z0-9]\{40\}\)"#\1:\2#'`
echo $COMMITS >> $LOG
echo "" >> $LOG

# helper function to determine if given commit hash has a status with "docker-testbot" context or not
# returns 0 if no such status exists, i.e. build needed
# returns 1 if such status exists, i.e. no build needed
commit_needs_build() {
REPO_SHA=(${1//:/ })
SHA=${REPO_SHA[1]}
curl --silent --show-error --no-buffer -H "Authorization: token ${OBSPY_COMMIT_STATUS_TOKEN}" --request GET "https://api.github.com/repos/obspy/obspy/commits/${SHA}/status" 2>> $LOG | grep -q -s '"context":[ ]*"docker-testbot"' >> $LOG 2>&1
if [ $? = 0 ]; then return 1; else return 0; fi
}

for COMMIT in $COMMITS
do
if commit_needs_build $COMMIT
then
echo $COMMIT
echo $COMMIT >> $LOG
fi
done
83 changes: 77 additions & 6 deletions misc/docker_tests/run_obspy_tests.sh
@@ -1,4 +1,33 @@
#!/bin/bash

PWD=`pwd`
DATETIME=$(date -u +"%Y-%m-%dT%H-%M-%SZ")
LOG_DIR_BASE=logs/$DATETIME
mkdir -p $LOG_DIR_BASE

# Parse the additional args later passed to `obspy-runtests` in
# the docker images.
extra_args=""
while getopts "t:e:" opt; do
case "$opt" in
e) extra_args=', "'$OPTARG'"'
;;
t) TARGET=(${OPTARG//:/ })
REPO=${TARGET[0]}
SHA=${TARGET[1]}
TARGET=true
OBSPY_DOCKER_TEST_SOURCE_TREE="clone"
;;
esac
done

# This bracket is closed at the very end and causes a redirection of everything
# to the logfile as well as stdout.
{
# Delete all but the last 15 log directories. The `+16` is intentional. Fully
# POSIX compliant version adapted from http://stackoverflow.com/a/34862475/1657047
ls -tp logs | tail -n +16 | xargs -I % rm -rf -- logs/%

OBSPY_PATH=$(dirname $(dirname $(pwd)))

# Remove all test images stored locally. Otherwise they'll end up on the
Expand All @@ -10,7 +39,6 @@ rm -rf $OBSPY_PATH/obspy/station/tests/images/testrun
DOCKERFILE_FOLDER=base_images
TEMP_PATH=temp
NEW_OBSPY_PATH=$TEMP_PATH/obspy
DATETIME=$(date -u +"%Y-%m-%dT%H-%M-%SZ")

# Determine the docker binary name. The official debian packages use docker.io
# for the binary's name due to some legacy docker package.
Expand All @@ -20,7 +48,6 @@ DOCKER=`which docker.io || which docker`
# file.
python -c "import obspy"


# Create temporary folder.
rm -rf $TEMP_PATH
mkdir -p $TEMP_PATH
Expand All @@ -46,11 +73,27 @@ then
git clone file://$OBSPY_PATH $NEW_OBSPY_PATH
# we're cloning so we have a non-dirty version actually
cat $OBSPY_PATH/obspy/RELEASE-VERSION | sed 's#\.dirty$##' > $NEW_OBSPY_PATH/obspy/RELEASE-VERSION
if [ "$TARGET" = true ] ; then
cd $NEW_OBSPY_PATH
git remote add TEMP git://github.com/$REPO/obspy
git fetch TEMP
git checkout $SHA
git remote remove TEMP || git remote rm TEMP
git clean -fdx
git status
# write RELEASE-VERSION file in temporary obspy clone without
# installation, same magic as done in setup.py
python -c "import os, sys; sys.path.insert(0, os.path.join(\"${NEW_OBSPY_PATH}\", 'obspy', 'core', 'util')); from version import get_git_version; sys.path.pop(0); print(get_git_version())" > $NEW_OBSPY_PATH/obspy/RELEASE-VERSION
cat $NEW_OBSPY_PATH/obspy/RELEASE-VERSION
cd $PWD
fi
else
echo "Bad value for OBSPY_DOCKER_TEST_SOURCE_TREE: $OBSPY_DOCKER_TEST_SOURCE_TREE"
exit 1
fi

cd $PWD
FULL_VERSION=`cat $NEW_OBSPY_PATH/obspy/RELEASE-VERSION`
COMMIT=`cd $OBSPY_PATH && git log -1 --pretty=format:%H`

# Copy the install script.
cp scripts/install_and_run_tests_on_image.sh $TEMP_PATH/install_and_run_tests_on_image.sh
Expand All @@ -72,7 +115,7 @@ create_image () {
if [ "$has_image" ]; then
printf "\e[101m\e[30m >>> Image '$image_name' already exists.\e[0m\n"
else
printf "\e[101m\e[30m Image '$image_name'will be created.\e[0m\n"
printf "\e[101m\e[30m Image '$image_name' will be created.\e[0m\n"
$DOCKER build -t obspy:$image_name $image_path
fi
}
Expand All @@ -83,10 +126,10 @@ run_tests_on_image () {
image_name=$1;
printf "\n\e[101m\e[30m >>> Running tests for image '"$image_name"'...\e[0m\n"
# Copy dockerfile and render template.
sed 's/{{IMAGE_NAME}}/'$image_name'/g' scripts/Dockerfile_run_tests.tmpl > $TEMP_PATH/Dockerfile
sed "s/{{IMAGE_NAME}}/$image_name/g; s/{{EXTRA_ARGS}}/$extra_args/g" scripts/Dockerfile_run_tests.tmpl > $TEMP_PATH/Dockerfile

# Where to save the logs, and a random ID for the containers.
LOG_DIR=logs/$DATETIME/$image_name
LOG_DIR=${LOG_DIR_BASE}/$image_name
mkdir -p $LOG_DIR
ID=$RANDOM-$RANDOM-$RANDOM

Expand All @@ -96,6 +139,8 @@ run_tests_on_image () {

$DOCKER cp $ID:/INSTALL_LOG.txt $LOG_DIR
$DOCKER cp $ID:/TEST_LOG.txt $LOG_DIR
$DOCKER cp $ID:/failure $LOG_DIR
$DOCKER cp $ID:/success $LOG_DIR

$DOCKER cp $ID:/obspy/obspy/imaging/tests/images/testrun $LOG_DIR/imaging_testrun
$DOCKER cp $ID:/obspy/obspy/core/tests/images/testrun $LOG_DIR/core_testrun
Expand Down Expand Up @@ -143,4 +188,30 @@ for image_name in $($DOCKER images | grep obspy | awk '{print $2}'); do
run_tests_on_image $image_name;
done

# set commit status
# helper function to determine overall success/failure across all images
# env variable OBSPY_COMMIT_STATUS_TOKEN has to be set for authorization
overall_status() {
ls ${LOG_DIR_BASE}/*/failure 2>&1 > /dev/null && return 1
ls ${LOG_DIR_BASE}/*/success 2>&1 > /dev/null && return 0
return 1
}
# encode parameter part of the URL, using requests as it is installed anyway..
# (since we use python to import obspy to generate RELEASE-VERSION above)
# it's just looking up the correct quoting function from urllib depending on
# py2/3 and works with requests >= 1.0 (which is from 2012)
FULL_VERSION_URLENCODED=`python -c "from requests.compat import quote; print(quote(\"${FULL_VERSION}\"))"`
COMMIT_STATUS_TARGET_URL="http://tests.obspy.org/?version=${FULL_VERSION_URLENCODED}"
if overall_status ;
then
COMMIT_STATUS=success
COMMIT_STATUS_DESCRIPTION="Docker tests succeeded:"
else
COMMIT_STATUS=failed
COMMIT_STATUS_DESCRIPTION="Docker tests failed:"
fi
curl -H "Content-Type: application/json" -H "Authorization: token ${OBSPY_COMMIT_STATUS_TOKEN}" --request POST --data "{\"state\": \"${COMMIT_STATUS}\", \"context\": \"docker-testbot\", \"description\": \"${COMMIT_STATUS_DESCRIPTION}\", \"target_url\": \"${COMMIT_STATUS_TARGET_URL}\"}" https://api.github.com/repos/obspy/obspy/statuses/${COMMIT}

rm -rf $TEMP_PATH

} 2>&1 | tee -a $LOG_DIR_BASE/docker.log
2 changes: 1 addition & 1 deletion misc/docker_tests/scripts/Dockerfile_run_tests.tmpl
Expand Up @@ -5,4 +5,4 @@ MAINTAINER Lion Krischer
ADD install_and_run_tests_on_image.sh install_and_run_tests_on_image.sh
ADD obspy /obspy
RUN echo {{IMAGE_NAME}} > container_name.txt
CMD ["/bin/bash", "install_and_run_tests_on_image.sh"]
CMD ["/bin/bash", "install_and_run_tests_on_image.sh"{{EXTRA_ARGS}}]
6 changes: 4 additions & 2 deletions misc/docker_tests/scripts/install_and_run_tests_on_image.sh
Expand Up @@ -6,7 +6,7 @@ no_color='\e[0m'
# Install ObsPy and run the tests.
cd /obspy

pip install -v -e . > /INSTALL_LOG.txt 2>&1
pip install -v -e . 2>&1 | tee /INSTALL_LOG.txt

if [ $? != 0 ]; then
echo -e "${red}Installation failed!${no_color}"
Expand All @@ -16,13 +16,15 @@ fi

cd

obspy-runtests -r --keep-images --node=docker-$(cat /container_name.txt) > /TEST_LOG.txt 2>&1
obspy-runtests -r --keep-images --no-flake8 --node=docker-$(cat /container_name.txt) $1 2>&1 | tee /TEST_LOG.txt


if [ $? != 0 ]; then
echo -e "${red}Tests failed!${no_color}"
touch /failure
else
echo -e "${green}Tests successful!${no_color}"
touch /success
fi

echo "Done with everything!"

0 comments on commit 57591bf

Please sign in to comment.