From 83d7d96141d4f73efbbd82be143d49eb4197cd1a Mon Sep 17 00:00:00 2001 From: mprahl Date: Jun 14 2018 12:54:27 +0000 Subject: Use a volume when running the unit tests instead of copying the source in the image --- diff --git a/.gitignore b/.gitignore index edcd4b2..360db57 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ test_module_build_service.db tests/test_module_build_service.db-journal *.swp .pytest_cache/ +requirements.txt.orig diff --git a/Dockerfile-tests b/Dockerfile-tests deleted file mode 100644 index f781e2d..0000000 --- a/Dockerfile-tests +++ /dev/null @@ -1,53 +0,0 @@ -FROM centos:7 - -WORKDIR /build -RUN yum -y update -RUN yum -y install epel-release yum-utils -RUN yum-config-manager --add-repo https://kojipkgs.fedoraproject.org/repos-dist/epel7Server-infra/latest/x86_64/ -RUN yum -y install \ - --nogpgcheck \ - --setopt=deltarpm=0 \ - --setopt=install_weak_deps=false \ - --setopt=tsflags=nodocs \ - createrepo_c \ - fedmsg \ - fedmsg-hub \ - git \ - kobo \ - kobo-rpmlib \ - libmodulemd \ - pdc-client \ - python-backports-ssl_match_hostname \ - python-dogpile-cache \ - python-enum34 \ - python-flask \ - python-flask-migrate \ - python-flask-sqlalchemy \ - python-funcsigs \ - python-futures \ - python-koji \ - python-ldap3 \ - python-mock \ - python-pip \ - python-requests \ - python-six \ - python-solv \ - python-sqlalchemy \ - # Test-only dependencies - python-flake8 \ - python-mock \ - python-tox \ - rpm-build \ - && yum clean all -# We currently require a newer versions of these Python packages for the tests -RUN pip install --upgrade flask-sqlalchemy pytest flake8 tox -# TODO: Consider making this a volume instead -COPY . . -# We install the python-koji RPM but it doesn't register as installed through pip. -# This hacks keeps tox from install koji from PyPi. -RUN sed -i '/koji/d' requirements.txt -# Delete any leftover compiled Python files -RUN find . -type f \( -name '*.pyc' -or -name '*.pyc' -or -name '__pycache__' \) -exec rm -rf {} \; -# Since tox seems to ignore `usedevelop` when we have `sitepackages` on, we have to run it manually -RUN python setup.py develop -CMD ["/usr/bin/tox", "-e", "flake8,py27"] diff --git a/Jenkinsfile b/Jenkinsfile index 2de0d0c..eac7c3e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -33,12 +33,12 @@ node('factory2'){ } stage('Build Docker Image') { - onmyduffynode 'cd fm-orchestrator && docker build -t mbs/test -f Dockerfile-tests .' + onmyduffynode 'cd fm-orchestrator && docker build -t mbs/test -f docker/Dockerfile-tests .' } stage('Run Test Suite') { timeout(20) { - onmyduffynode 'cd fm-orchestrator && docker run mbs/test' + onmyduffynode 'cd fm-orchestrator && docker run -v $PWD:/src:Z mbs/test' } } diff --git a/docker/Dockerfile-tests b/docker/Dockerfile-tests new file mode 100644 index 0000000..77b8cbb --- /dev/null +++ b/docker/Dockerfile-tests @@ -0,0 +1,47 @@ +FROM centos:7 + +WORKDIR /build +RUN yum -y update +RUN yum -y install epel-release yum-utils +RUN yum-config-manager --add-repo https://kojipkgs.fedoraproject.org/repos-dist/epel7Server-infra/latest/x86_64/ +RUN yum -y install \ + --nogpgcheck \ + --setopt=deltarpm=0 \ + --setopt=install_weak_deps=false \ + --setopt=tsflags=nodocs \ + bash \ + createrepo_c \ + fedmsg \ + fedmsg-hub \ + git \ + kobo \ + kobo-rpmlib \ + libmodulemd \ + pdc-client \ + python-backports-ssl_match_hostname \ + python-dogpile-cache \ + python-enum34 \ + python-flask \ + python-flask-migrate \ + python-flask-sqlalchemy \ + python-funcsigs \ + python-futures \ + python-koji \ + python-ldap3 \ + python-mock \ + python-pip \ + python-requests \ + python-six \ + python-solv \ + python-sqlalchemy \ + # Test-only dependencies + python-flake8 \ + python-mock \ + python-tox \ + rpm-build \ + && yum clean all +# We currently require a newer versions of these Python packages for the tests +RUN pip install --upgrade flask-sqlalchemy pytest flake8 tox +VOLUME /src +WORKDIR /src +CMD ["bash", "docker/test.sh"] diff --git a/docker/test.sh b/docker/test.sh new file mode 100755 index 0000000..da8151f --- /dev/null +++ b/docker/test.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# We install the python-koji RPM but it doesn't register as installed through pip. +# This hacks keeps tox from install koji from PyPi. +cp requirements.txt requirements.txt.orig +sed -i '/koji/d' requirements.txt +# Delete any leftover compiled Python files +for dir in module_build_service tests; do + find ${dir} -type f \( -name '*.pyc' -or -name '*.pyc' \) -exec rm -f {} \; +done +# Since tox seems to ignore `usedevelop` when we have `sitepackages` on, we have to run it manually +python setup.py develop +/usr/bin/tox -e flake8,py27 +# After running tox, we can revert back to the original requirements.txt file +rm -f requirements.txt +mv requirements.txt.orig requirements.txt diff --git a/docs/CONTRIBUTING.rst b/docs/CONTRIBUTING.rst index bd371bc..f25010d 100644 --- a/docs/CONTRIBUTING.rst +++ b/docs/CONTRIBUTING.rst @@ -4,9 +4,18 @@ Running Tests Since MBS requires Python dependencies that aren't available using PyPi (e.g. libsolv bindings), there is a Docker image that can be used to run the code analysis and unit tests. -To run the tests:: +To run the tests, you must first install and start Docker with:: - $ sudo docker build -t mbs/test -f Dockerfile-tests . && sudo docker run mbs/test + $ sudo dnf install docker + $ sudo systemctl start docker + +From the main git directory, build the Docker image with:: + + $ sudo docker build -t mbs/test -f docker/Dockerfile-tests . + +Then run the tests with:: + + $ sudo docker run -t -v $PWD:/src:Z mbs/test Development