From 90483690a5d88bb04a68fb64fcb358ab82660914 Mon Sep 17 00:00:00 2001 From: fivepiece Date: Sat, 2 Sep 2017 13:22:18 +0300 Subject: [PATCH] Use docker to build and run tests on multiple distributions --- .travis.yml | 39 ++++++++++++++++++++------ test/Dockerfiles/bionic.Dockerfile | 37 +++++++++++++++++++++++++ test/Dockerfiles/build_docker.sh | 41 ++++++++++++++++++++++++++++ test/Dockerfiles/centos7.Dockerfile | 33 ++++++++++++++++++++++ test/Dockerfiles/fedora27.Dockerfile | 36 ++++++++++++++++++++++++ test/Dockerfiles/stretch.Dockerfile | 37 +++++++++++++++++++++++++ test/Dockerfiles/xenial.Dockerfile | 37 +++++++++++++++++++++++++ test/run_tests.sh | 2 +- 8 files changed, 253 insertions(+), 9 deletions(-) create mode 100755 test/Dockerfiles/bionic.Dockerfile create mode 100755 test/Dockerfiles/build_docker.sh create mode 100755 test/Dockerfiles/centos7.Dockerfile create mode 100755 test/Dockerfiles/fedora27.Dockerfile create mode 100755 test/Dockerfiles/stretch.Dockerfile create mode 100755 test/Dockerfiles/xenial.Dockerfile diff --git a/.travis.yml b/.travis.yml index f6bfd8e..078c046 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,4 @@ sudo: required -os: - - linux - - osx dist: trusty addons: apt: @@ -11,17 +8,43 @@ addons: packages: - bitcoind - python-qt4 python-sip +matrix: + include: + - os: osx + - os: linux + - os: linux + services: docker + env: DOCKER_IMG_JM=xenial + - os: linux + services: docker + env: DOCKER_IMG_JM=bionic + - os: linux + services: docker + env: DOCKER_IMG_JM=stretch + - os: linux + services: docker + env: DOCKER_IMG_JM=centos7 + - os: linux + services: docker + env: DOCKER_IMG_JM=fedora27 before_install: - do_on(){ if [ "$TRAVIS_OS_NAME" = "$1" ]; then shift; $@ ; fi; } + - on_host(){ if [ -z "$DOCKER_IMG_JM" ]; then $@ ; fi; } + - on_docker(){ if [ -n "$DOCKER_IMG_JM" ]; then $@ ; fi; } +cache: + directories: + $HOME/downloads install: - - ./install.sh --develop --no-gpg-validation + - on_host ./install.sh --develop --no-gpg-validation before_script: - - source jmvenv/bin/activate + - on_host source jmvenv/bin/activate script: - - do_on linux bitcoind --help | head -1 - - do_on linux ./test/run_tests.sh + - on_host do_on linux bitcoind --help | head -1 + - on_host do_on linux ./test/run_tests.sh + - on_docker ./test/Dockerfiles/build_docker.sh after_success: - - do_on linux coveralls + - on_docker echo "Success !" + - on_host do_on linux coveralls branches: except: - py3 diff --git a/test/Dockerfiles/bionic.Dockerfile b/test/Dockerfiles/bionic.Dockerfile new file mode 100755 index 0000000..4a8c0e0 --- /dev/null +++ b/test/Dockerfiles/bionic.Dockerfile @@ -0,0 +1,37 @@ +FROM ubuntu:bionic +SHELL ["/bin/bash", "-c"] + +# dependencies +RUN apt-get update +RUN apt-get install -y build-essential +RUN apt-get install -y \ + automake pkg-config libtool +RUN apt-get install -y \ + python-dev python-pip python-virtualenv python-qt4 python-sip + +# curl is a better tool +RUN apt-get install -y curl + +RUN useradd --home-dir /home/chaum --create-home --shell /bin/bash --skel /etc/skel/ chaum +ARG core_version +ARG core_dist +ARG repo_name +RUN mkdir -p /home/chaum/${repo_name} +COPY ${repo_name} /home/chaum/${repo_name} +RUN ls -la /home/chaum +RUN chown -R chaum:chaum /home/chaum/${repo_name} +USER chaum + +# copy node software from the host and install +WORKDIR /home/chaum +RUN ls -la . +RUN ls -la ${repo_name} +RUN ls -la ${repo_name}/deps +RUN tar xaf ./${repo_name}/deps/${core_dist} -C /home/chaum +ENV PATH "/home/chaum/bitcoin-${core_version}/bin:${PATH}" +RUN bitcoind --version | head -1 + +# install script +WORKDIR ${repo_name} +RUN ./install.sh --no-gpg-validation +RUN source jmvenv/bin/activate && ./test/run_tests.sh diff --git a/test/Dockerfiles/build_docker.sh b/test/Dockerfiles/build_docker.sh new file mode 100755 index 0000000..7a9dc1d --- /dev/null +++ b/test/Dockerfiles/build_docker.sh @@ -0,0 +1,41 @@ +#!/bin/bash -x + +travis_docker_env () +{ + if [[ -n "${DOCKER_IMG_JM}" ]] && [[ "${HAS_JOSH_K_SEAL_OF_APPROVAL}" == true ]]; then + return 0 + else + return 1 + fi +} + +build_docker () +{ + if ! travis_docker_env; then + return 0 + fi + + core_version='0.16.1' + core_dist="bitcoin-${core_version}-x86_64-linux-gnu.tar.gz" + core_url="https://bitcoin.org/bin/bitcoin-core-${core_version}/${core_dist}" + jm_root="${TRAVIS_BUILD_DIR}" + owner_name="${TRAVIS_REPO_SLUG%\/*}" + repo_name="${TRAVIS_REPO_SLUG#*\/}" + + if [[ ! -f "${HOME}/downloads/${core_dist}" ]]; then + wget "${core_url}" -O "$HOME/downloads/${core_dist}" + fi + + mkdir -p "${jm_root}/deps" + cp "${HOME}/downloads/${core_dist}" "${jm_root}/deps/" + cd "${jm_root}/../" + + docker build \ + --shm-size=1G \ + --build-arg core_version="${core_version}" \ + --build-arg core_dist="${core_dist}" \ + --build-arg repo_name="${repo_name}" \ + -f "./${repo_name}/test/Dockerfiles/${DOCKER_IMG_JM}.Dockerfile" . + return "$?" +} +build_docker diff --git a/test/Dockerfiles/centos7.Dockerfile b/test/Dockerfiles/centos7.Dockerfile new file mode 100755 index 0000000..5b9a636 --- /dev/null +++ b/test/Dockerfiles/centos7.Dockerfile @@ -0,0 +1,33 @@ +FROM centos:7 +SHELL ["/bin/bash", "-c"] + +# dependencies +RUN yum -y groups install 'Development tools' +RUN yum -y install epel-release && \ + yum -y update +RUN yum -y install \ + python-devel python2-pip python-virtualenv + +RUN useradd --home-dir /home/chaum --create-home --shell /bin/bash --skel /etc/skel/ chaum +ARG core_version +ARG core_dist +ARG repo_name +RUN mkdir -p /home/chaum/${repo_name} +COPY ${repo_name} /home/chaum/${repo_name} +RUN ls -la /home/chaum +RUN chown -R chaum:chaum /home/chaum/${repo_name} +USER chaum + +# copy node software from the host and install +WORKDIR /home/chaum +RUN ls -la . +RUN ls -la ${repo_name} +RUN ls -la ${repo_name}/deps +RUN tar xaf ./${repo_name}/deps/${core_dist} -C /home/chaum +ENV PATH "/home/chaum/bitcoin-${core_version}/bin:${PATH}" +RUN bitcoind --version | head -1 + +# install script +WORKDIR ${repo_name} +RUN ./install.sh --no-gpg-validation +RUN source jmvenv/bin/activate && ./test/run_tests.sh diff --git a/test/Dockerfiles/fedora27.Dockerfile b/test/Dockerfiles/fedora27.Dockerfile new file mode 100755 index 0000000..1b36887 --- /dev/null +++ b/test/Dockerfiles/fedora27.Dockerfile @@ -0,0 +1,36 @@ +FROM fedora:27 +SHELL ["/bin/bash", "-c"] + +# dependencies +RUN dnf -y groups install 'Development tools' +RUN dnf -y install \ + autoconf libtool pkgconfig \ + python-devel python-pip python2-virtualenv + +# needed for build time +# https://stackoverflow.com/questions/34624428/g-error-usr-lib-rpm-redhat-redhat-hardened-cc1-no-such-file-or-directory +RUN dnf -y install redhat-rpm-config + +RUN useradd --home-dir /home/chaum --create-home --shell /bin/bash --skel /etc/skel/ chaum +ARG core_version +ARG core_dist +ARG repo_name +RUN mkdir -p /home/chaum/${repo_name} +COPY ${repo_name} /home/chaum/${repo_name} +RUN ls -la /home/chaum +RUN chown -R chaum:chaum /home/chaum/${repo_name} +USER chaum + +# copy node software from the host and install +WORKDIR /home/chaum +RUN ls -la . +RUN ls -la ${repo_name} +RUN ls -la ${repo_name}/deps +RUN tar xaf ./${repo_name}/deps/${core_dist} -C /home/chaum +ENV PATH "/home/chaum/bitcoin-${core_version}/bin:${PATH}" +RUN bitcoind --version | head -1 + +# install script +WORKDIR ${repo_name} +RUN ./install.sh --no-gpg-validation +RUN source jmvenv/bin/activate && ./test/run_tests.sh diff --git a/test/Dockerfiles/stretch.Dockerfile b/test/Dockerfiles/stretch.Dockerfile new file mode 100755 index 0000000..c6cc8c1 --- /dev/null +++ b/test/Dockerfiles/stretch.Dockerfile @@ -0,0 +1,37 @@ +FROM debian:stretch +SHELL ["/bin/bash", "-c"] + +# dependencies +RUN apt-get update +RUN apt-get install -y build-essential +RUN apt-get install -y \ + automake pkg-config libtool +RUN apt-get install -y \ + python-dev python-pip python-virtualenv python-qt4 python-sip + +# curl is a better tool +RUN apt-get install -y curl + +RUN useradd --home-dir /home/chaum --create-home --shell /bin/bash --skel /etc/skel/ chaum +ARG core_version +ARG core_dist +ARG repo_name +RUN mkdir -p /home/chaum/${repo_name} +COPY ${repo_name} /home/chaum/${repo_name} +RUN ls -la /home/chaum +RUN chown -R chaum:chaum /home/chaum/${repo_name} +USER chaum + +# copy node software from the host and install +WORKDIR /home/chaum +RUN ls -la . +RUN ls -la ${repo_name} +RUN ls -la ${repo_name}/deps +RUN tar xaf ./${repo_name}/deps/${core_dist} -C /home/chaum +ENV PATH "/home/chaum/bitcoin-${core_version}/bin:${PATH}" +RUN bitcoind --version | head -1 + +# install script +WORKDIR ${repo_name} +RUN ./install.sh --no-gpg-validation +RUN source jmvenv/bin/activate && ./test/run_tests.sh diff --git a/test/Dockerfiles/xenial.Dockerfile b/test/Dockerfiles/xenial.Dockerfile new file mode 100755 index 0000000..8c3ab3d --- /dev/null +++ b/test/Dockerfiles/xenial.Dockerfile @@ -0,0 +1,37 @@ +FROM ubuntu:xenial +SHELL ["/bin/bash", "-c"] + +# dependencies +RUN apt-get update +RUN apt-get install -y build-essential +RUN apt-get install -y \ + automake pkg-config libtool +RUN apt-get install -y \ + python-dev python-pip python-virtualenv python-qt4 python-sip + +# curl is a better tool +RUN apt-get install -y curl + +RUN useradd --home-dir /home/chaum --create-home --shell /bin/bash --skel /etc/skel/ chaum +ARG core_version +ARG core_dist +ARG repo_name +RUN mkdir -p /home/chaum/${repo_name} +COPY ${repo_name} /home/chaum/${repo_name} +RUN ls -la /home/chaum +RUN chown -R chaum:chaum /home/chaum/${repo_name} +USER chaum + +# copy node software from the host and install +WORKDIR /home/chaum +RUN ls -la . +RUN ls -la ${repo_name} +RUN ls -la ${repo_name}/deps +RUN tar xaf ./${repo_name}/deps/${core_dist} -C /home/chaum +ENV PATH "/home/chaum/bitcoin-${core_version}/bin:${PATH}" +RUN bitcoind --version | head -1 + +# install script +WORKDIR ${repo_name} +RUN ./install.sh --no-gpg-validation +RUN source jmvenv/bin/activate && ./test/run_tests.sh diff --git a/test/run_tests.sh b/test/run_tests.sh index cc6ae8c..9fac45b 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -51,7 +51,7 @@ run_jm_tests () if read bitcoind_pid <"${jm_test_datadir}/bitcoind.pid"; then kill -15 ${bitcoind_pid} || kill -9 ${bitcoind_pid} fi - if [[ "${HAS_JOSH_K_SEAL_OF_APPROVAL}" = true ]] && (( ${success} != 0 )); then + if [[ "${HAS_JOSH_K_SEAL_OF_APPROVAL}" == true ]] && (( ${success} != 0 )); then tail -100 "${jm_test_datadir}/regtest/debug.log" find "${jm_test_datadir}" else