Use a volume when running the unit tests instead of copying the source in the image

This commit is contained in:
mprahl
2018-06-14 08:54:27 -04:00
parent e2e804b1d6
commit 83d7d96141
5 changed files with 34 additions and 14 deletions

1
.gitignore vendored
View File

@@ -20,3 +20,4 @@ test_module_build_service.db
tests/test_module_build_service.db-journal
*.swp
.pytest_cache/
requirements.txt.orig

4
Jenkinsfile vendored
View File

@@ -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'
}
}

View File

@@ -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"]

16
docker/test.sh Executable file
View File

@@ -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

View File

@@ -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