This is a small app for getting acquainted with the pytest-docker-compose plugin.
docker build -t hello-pdc .
docker network create --driver=bridge hello-pdc
docker run --rm --name app --net hello-pdc -d -p 5000:80 hello-pdc
You can access the app on http://localhost:5000/ however the counter won't work because Redis isn't running.
To spin up a Redis instance and connect the app, do the following:
docker run --rm --name redis --net hello-pdc -d redis:alpine
Now if you go to http://localhost:5000/ you should see that the counter will now increment as you refresh the page.
To stop the containers from running:
docker stop app redis
For more information, refer to Dockerfile
in this repository.
We only had to deploy two containers, but it ended up being a fair amount of work — there were several moving parts and lots of command-line options to keep track of!
docker-compose makes the whole process considerably easier:
docker-compose up
This will spin up the app and redis containers and configure everything correctly. After running the above command, you can view the app on http://localhost:5000/ and the counter will work straightaway.
Press Control-C to bring the containers back down.
For more information, refer to docker-compose.yml
in this repository.
Important
This project was written & tested using Python 3.6 — other versions of Python might work, but we never tried.
- (optional but highly recommended) Create a new virtualenv.
pip install -e '.[test-runner]'
python setup.py test
This runs the unit tests in unit_tests/counter_test.py
. Both tests should
pass.
Because integration tests take considerably longer to run, they are not enabled
by default. Instead, you will need to use the pytest
command explicitly.
Note: the ``pytest`` command was installed when you ran ``pip install`` in the previous step.
docker-compose down
pytest integration_tests/homepage_test.py
This runs the integration tests in integration_tests/homepage_test.py
. Both
tests should pass.