1
0
mirror of https://github.com/thib8956/nginx-proxy synced 2024-12-25 03:56:31 +00:00

TESTS: add script to run the test suite from a docker container

This commit is contained in:
Thomas LEVEIL 2017-01-24 22:42:13 +01:00
parent 7a4cae050c
commit 787fa28799
8 changed files with 69 additions and 4 deletions

View File

@ -4,7 +4,7 @@
update-dependencies:
requirements/build.sh
pip install -U -r requirements.txt
pip install -U -r requirements/python-requirements.txt
test-debian: update-dependencies
docker build -t jwilder/nginx-proxy:test ..

View File

@ -7,7 +7,9 @@ Install requirements
You need [python 2.7](https://www.python.org/) and [pip](https://pip.pypa.io/en/stable/installing/) installed. Then run the commands:
requirements/build.sh
pip install -r requirements.txt
pip install -r requirements/python-requirements.txt
If you can't install those requirements on your computer, you can alternatively use the _nginx-proxy-tester.sh_ script which will run the tests from a Docker container which has those requirements.
Prepare the nginx-proxy test image

View File

@ -18,7 +18,7 @@ logging.getLogger('patched DNS').setLevel(logging.INFO)
CA_ROOT_CERTIFICATE = os.path.join(os.path.dirname(__file__), 'certs/ca-root.crt')
I_AM_RUNNING_INSIDE_A_DOCKER_CONTAINER = os.path.isfile("/.dockerenv")
###############################################################################
#
@ -26,6 +26,7 @@ CA_ROOT_CERTIFICATE = os.path.join(os.path.dirname(__file__), 'certs/ca-root.crt
#
###############################################################################
class requests_retry_on_error_502(object):
"""
Proxy for calling methods of the requests module.
@ -113,6 +114,8 @@ def restore_urllib_dns_resolver(getaddrinfo_func):
def remove_all_containers():
docker_client = docker.from_env()
for info in docker_client.containers(all=True):
if I_AM_RUNNING_INSIDE_A_DOCKER_CONTAINER and info['Id'].startswith(socket.gethostname()):
continue # pytest is running within a Docker container, so we do not want to remove that particular container
docker_client.remove_container(info["Id"], v=True, force=True)

36
test2/nginx-proxy-tester.sh Executable file
View File

@ -0,0 +1,36 @@
#!/bin/bash
###############################################################################
# #
# This script is meant to run the test suite from a Docker container. #
# #
# This is usefull when you want to run the test suite from Mac or #
# Docker Toolbox. #
# #
###############################################################################
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ARGS="$@"
# check requirements
if [[ "$(docker images -q nginx-proxy-tester 2>/dev/null)" == "" ]]; then
echo "> Building nginx-proxy-tester image..."
docker build -t nginx-proxy-tester -f $DIR/requirements/Dockerfile-nginx-proxy-tester $DIR/requirements
fi
# delete python cache
[[ -d "${DIR}/__pycache__" ]] && rm "${DIR}/__pycache__" -rf
# run the nginx-proxy-tester container setting the correct value for the working dir in order for
# docker-compose to work properly when run from within that container.
docker run --rm -it \
-v ${DIR}:/${DIR} \
-v ${DIR}/__pycache__/ \
-w ${DIR} \
-v /var/run/docker.sock:/var/run/docker.sock \
nginx-proxy-tester "${ARGS}"
PYTEST_EXIT_CODE=$?
# delete python cache
[[ -d "${DIR}/__pycache__" ]] && rm "${DIR}/__pycache__" -rf
exit ${PYTEST_EXIT_CODE}

View File

@ -0,0 +1,5 @@
FROM python:2.7
COPY python-requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
WORKDIR /test
ENTRYPOINT ["pytest"]

View File

@ -5,6 +5,17 @@ This directory contains ressources to build Docker images tests depend on
./build.sh
# python-requirements.txt
If you want to run the test suite from your computer, you need python and a few python modules.
The _python-requirements.txt_ file describes the python modules required. To install them, use
pip:
pip install -r python-requirements.txt
If you don't want to run the test from your computer, you can run the tests from a docker container, see the _nginx-proxy-tester.sh_ script.
# Images
## web
@ -33,3 +44,11 @@ answer from port 80
```
## nginx-proxy-tester
This is an optional requirement which is usefull if you cannot (or don't want to) install pytest and its requirements on your computer. In this case, you can use the `nginx-proxy-tester` docker image to run the test suite from a Docker container.
To use this image, it is mandatory to run the container using the `nginx-proxy-tester.sh` shell script.

View File

@ -3,4 +3,4 @@ set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
docker build -t web $DIR/web
docker build -t web $DIR/web