mirror of
https://github.com/thib8956/nginx-proxy
synced 2024-11-22 11:56:31 +00:00
TESTS: add script to run the test suite from a docker container
This commit is contained in:
parent
7a4cae050c
commit
787fa28799
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
update-dependencies:
|
update-dependencies:
|
||||||
requirements/build.sh
|
requirements/build.sh
|
||||||
pip install -U -r requirements.txt
|
pip install -U -r requirements/python-requirements.txt
|
||||||
|
|
||||||
test-debian: update-dependencies
|
test-debian: update-dependencies
|
||||||
docker build -t jwilder/nginx-proxy:test ..
|
docker build -t jwilder/nginx-proxy:test ..
|
||||||
|
@ -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:
|
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
|
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
|
Prepare the nginx-proxy test image
|
||||||
|
@ -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')
|
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):
|
class requests_retry_on_error_502(object):
|
||||||
"""
|
"""
|
||||||
Proxy for calling methods of the requests module.
|
Proxy for calling methods of the requests module.
|
||||||
@ -113,6 +114,8 @@ def restore_urllib_dns_resolver(getaddrinfo_func):
|
|||||||
def remove_all_containers():
|
def remove_all_containers():
|
||||||
docker_client = docker.from_env()
|
docker_client = docker.from_env()
|
||||||
for info in docker_client.containers(all=True):
|
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)
|
docker_client.remove_container(info["Id"], v=True, force=True)
|
||||||
|
|
||||||
|
|
||||||
|
36
test2/nginx-proxy-tester.sh
Executable file
36
test2/nginx-proxy-tester.sh
Executable 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}
|
5
test2/requirements/Dockerfile-nginx-proxy-tester
Normal file
5
test2/requirements/Dockerfile-nginx-proxy-tester
Normal 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"]
|
@ -5,6 +5,17 @@ This directory contains ressources to build Docker images tests depend on
|
|||||||
./build.sh
|
./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
|
# Images
|
||||||
|
|
||||||
## web
|
## 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.
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,4 +3,4 @@ set -e
|
|||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
docker build -t web $DIR/web
|
docker build -t web $DIR/web
|
Loading…
Reference in New Issue
Block a user