From 83d7d96141d4f73efbbd82be143d49eb4197cd1a Mon Sep 17 00:00:00 2001 From: mprahl Date: Thu, 14 Jun 2018 08:54:27 -0400 Subject: [PATCH] Use a volume when running the unit tests instead of copying the source in the image --- .gitignore | 1 + Jenkinsfile | 4 ++-- Dockerfile-tests => docker/Dockerfile-tests | 14 ++++---------- docker/test.sh | 16 ++++++++++++++++ docs/CONTRIBUTING.rst | 13 +++++++++++-- 5 files changed, 34 insertions(+), 14 deletions(-) rename Dockerfile-tests => docker/Dockerfile-tests (66%) create mode 100755 docker/test.sh diff --git a/.gitignore b/.gitignore index edcd4b2c..360db575 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/Jenkinsfile b/Jenkinsfile index 2de0d0c9..eac7c3ea 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/Dockerfile-tests b/docker/Dockerfile-tests similarity index 66% rename from Dockerfile-tests rename to docker/Dockerfile-tests index f781e2d1..77b8cbb5 100644 --- a/Dockerfile-tests +++ b/docker/Dockerfile-tests @@ -9,6 +9,7 @@ RUN yum -y install \ --setopt=deltarpm=0 \ --setopt=install_weak_deps=false \ --setopt=tsflags=nodocs \ + bash \ createrepo_c \ fedmsg \ fedmsg-hub \ @@ -41,13 +42,6 @@ RUN yum -y install \ && 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"] +VOLUME /src +WORKDIR /src +CMD ["bash", "docker/test.sh"] diff --git a/docker/test.sh b/docker/test.sh new file mode 100755 index 00000000..da8151f8 --- /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 bd371bc2..f25010d2 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