#953 Use a volume when running the unit tests instead of copying the source in the image
Merged 10 months ago by mprahl. Opened 10 months ago by mprahl.

file modified
+1

@@ -20,3 +20,4 @@ 

  tests/test_module_build_service.db-journal

  *.swp

  .pytest_cache/

+ requirements.txt.orig

file modified
+2 -2

@@ -33,12 +33,12 @@ 

          }

  

          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'

              }

          }

  

docker/Dockerfile-tests Dockerfile-tests
file renamed
+4 -10

@@ -9,6 +9,7 @@ 

      --setopt=deltarpm=0 \

      --setopt=install_weak_deps=false \

      --setopt=tsflags=nodocs \

+     bash \

      createrepo_c \

      fedmsg \

      fedmsg-hub \

@@ -41,13 +42,6 @@ 

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

file added
+16

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

file modified
+11 -2

@@ -4,9 +4,18 @@ 

  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

no initial comment

:thumbsup: Much better for testing and for interactive work inside the container. :thumbsup:

Thank you & feel free to merge!

Pull-Request has been merged by mprahl

10 months ago