├── .dockerignore ├── Dockerfile ├── LICENSE └── README.md /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | LICENSE 3 | README.md 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM themattrix/tox-base 2 | 3 | MAINTAINER Matthew Tardiff 4 | 5 | ONBUILD COPY install-prereqs*.sh requirements*.txt tox.ini /app/ 6 | ONBUILD ARG SKIP_TOX=false 7 | ONBUILD RUN bash -c " \ 8 | if [ -f '/app/install-prereqs.sh' ]; then \ 9 | bash /app/install-prereqs.sh; \ 10 | fi && \ 11 | if [ $SKIP_TOX == false ]; then \ 12 | TOXBUILD=true tox; \ 13 | fi" 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-2017 Matthew Tardiff 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tox 2 | 3 | *Available on Docker Hub as [`themattrix/tox`](https://registry.hub.docker.com/u/themattrix/tox/).* 4 | 5 | This image is intended for running [tox](https://tox.readthedocs.org/en/latest/) with 6 | Python 2.6, 2.7, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, PyPy, and PyPy3. 7 | Its goal is to make testing your code against multiple Python versions quick and easy. 8 | The image contains several `ONBUILD` commands for initializing the tox environments with 9 | your project's `requirements.txt` files. 10 | 11 | 12 | ## Usage 13 | 14 | The Dockerfile contains the following `ONBUILD` commands: 15 | 16 | ```dockerfile 17 | ONBUILD COPY install-prereqs*.sh requirements*.txt tox.ini /app/ 18 | ONBUILD ARG SKIP_TOX=false 19 | ONBUILD RUN bash -c " \ 20 | if [ -f '/app/install-prereqs.sh' ]; then \ 21 | bash /app/install-prereqs.sh; \ 22 | fi && \ 23 | if [ $SKIP_TOX == false ]; then \ 24 | TOXBUILD=true tox; \ 25 | fi" 26 | ``` 27 | 28 | This means your project *must* contain a `tox.ini` file. 29 | 30 | You can also optionally include an `install-prereqs.sh` script for installing 31 | prerequisites of the project requirements. 32 | 33 | To avoid the tox environments being rebuilt every time you want to test your code, 34 | tox is run twice - first with the `TOXBUILD` environment variable set to `true`, 35 | and second without it being set: 36 | 37 | 1. `$ TOXBUILD=true tox` 38 | 39 | Executed during the `build` phase to initialize all of the environments. It is 40 | expected *not* to install your code nor run your tests; it should *only* 41 | install the requirements which your project needs to be tested. 42 | 43 | This step can be skipped by specifying `--build-arg SKIP_TOX=true` in the build phase. 44 | 45 | 2. `$ tox` 46 | 47 | Executed during the `run` phase to test your code. 48 | 49 | 50 | When your requirements or tox configuration changes, *both* steps are run. 51 | When your code changes, *only the second step is run*, saving valuable time. 52 | This also ensures that your code is always tested in a completely clean 53 | environment. 54 | 55 | Example `tox.ini` supporting the TOXBUILD environment variable: 56 | 57 | [tox] 58 | envlist = py26,py27,py33,py34,py35,py36,py37,py38,pypy,pypy3 59 | skipsdist = {env:TOXBUILD:false} 60 | 61 | [testenv] 62 | passenv = LANG 63 | whitelist_externals = true 64 | deps = 65 | -rrequirements_test_runner.txt 66 | -rrequirements_static_analysis.txt 67 | -rrequirements_test.txt 68 | commands = {env:TOXBUILD:./tests.sh --static-analysis} 69 | 70 | 71 | For a full example, see the [`python-pypi-template`]( 72 | https://github.com/themattrix/python-pypi-template) project, which uses this image. 73 | --------------------------------------------------------------------------------