Skip to content

Commit 61b432b

Browse files
author
Garry Jeromson
committed
Set up Docker development workflow
1 parent b15fe9b commit 61b432b

7 files changed

+299
-22
lines changed

.dockerignore

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
.git
2+
3+
# Byte-compiled / optimized / DLL files
4+
__pycache__/
5+
*.py[cod]
6+
*$py.class
7+
8+
# C extensions
9+
*.so
10+
11+
# Distribution / packaging
12+
.Python
13+
build/
14+
develop-eggs/
15+
dist/
16+
downloads/
17+
eggs/
18+
.eggs/
19+
lib/
20+
lib64/
21+
parts/
22+
sdist/
23+
var/
24+
wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
.hypothesis/
50+
.pytest_cache/
51+
52+
# Translations
53+
*.mo
54+
*.pot
55+
56+
# Django stuff:
57+
*.log
58+
local_settings.py
59+
db.sqlite3
60+
61+
# Flask stuff:
62+
instance/
63+
.webassets-cache
64+
65+
# Scrapy stuff:
66+
.scrapy
67+
68+
# Sphinx documentation
69+
build_docs/
70+
71+
# PyBuilder
72+
target/
73+
74+
# Jupyter Notebook
75+
.ipynb_checkpoints
76+
77+
# pyenv
78+
.python-version
79+
80+
# celery beat schedule file
81+
celerybeat-schedule
82+
83+
# SageMath parsed files
84+
*.sage.py
85+
86+
# Environments
87+
.env
88+
.venv
89+
env/
90+
venv/
91+
ENV/
92+
env.bak/
93+
venv.bak/
94+
95+
# Spyder project settings
96+
.spyderproject
97+
.spyproject
98+
99+
# Rope project settings
100+
.ropeproject
101+
102+
# mkdocs documentation
103+
/site
104+
105+
# mypy
106+
.mypy_cache/
107+
108+
# Editor cruft
109+
.idea/
110+
*~
111+
112+
# Node modules
113+
node_modules/
114+
package-lock.json
115+
116+
# Mac cruft
117+
.DS_Store
118+
119+
# Mountebank data
120+
mb*.pid
121+
mb.log
122+
.mbdb/

.travis.yml

+88-19
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
language: python
2+
os: linux
23
dist: xenial
3-
matrix:
4+
jobs:
5+
fast_finish: true
46
allow_failures:
57
- os: windows
68
- os: osx
79
- python: 3.9-dev
10+
- env: DOCKER=true
811
include:
9-
- python: 3.7
12+
- stage: "Test"
13+
python: 3.7
14+
name: Test (Python 3.7, Linux)
1015
env:
1116
- TOX_ENV=py37
1217
- os: osx
1318
language: generic
1419
python: 3.7
20+
name: Test (Python 3.7, OSX)
1521
env:
1622
- TOX_ENV=py37
1723
- os: windows
18-
language: sh
24+
language: shell
1925
python: 3.7
26+
name: Test (Python 3.7, Windows)
2027
before_install:
2128
- choco install python --version=3.7.5
2229
- choco install nodejs
@@ -25,54 +32,116 @@ matrix:
2532
env:
2633
- TOX_ENV=py37
2734
- python: 3.5
35+
name: Test (Python 3.5, Linux)
2836
env:
2937
- TOX_ENV=py35
3038
- python: 3.6
39+
name: Test (Python 3.6, Linux)
3140
env:
3241
- TOX_ENV=py36
3342
- python: 3.8
43+
name: Test (Python 3.8, Linux)
3444
env:
3545
- TOX_ENV=py38
3646
- python: 3.9-dev
47+
name: Test (Python 3.9-dev, Linux)
3748
env:
3849
- TOX_ENV=py39
3950
- python: 3.6
51+
name: Test (Python 3.6 PyPy, Linux)
4052
env:
4153
- TOX_ENV=pypy3.6
4254
- python: 3.8
55+
name: Test (Mountebank 2.1, Python 3.8, Linux)
56+
env:
57+
- TOX_ENV=py38
58+
- MBTEST_VERSION=2.1
59+
- python: 3.8
60+
name: Test (Mountebank 2.0, Python 3.8, Linux)
61+
env:
62+
- TOX_ENV=py38
63+
- MBTEST_VERSION=2.0
64+
- python: 3.8
65+
name: Test (Mountebank 1.16, Python 3.8, Linux)
66+
env:
67+
- TOX_ENV=py38
68+
- MBTEST_VERSION=1.16
69+
- name: Test (Python 3.5, Docker)
70+
env: DOCKER=true
71+
before_install:
72+
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
73+
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
74+
- sudo apt-get update
75+
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
76+
install:
77+
- make use-docker
78+
- make build-with-python3.5
79+
script:
80+
- make test-with-python3.5
81+
- name: Test (Python 3.6, Docker)
82+
env: DOCKER=true
83+
before_install:
84+
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
85+
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
86+
- sudo apt-get update
87+
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
88+
install:
89+
- make use-docker
90+
- make build-with-python3.6
91+
script:
92+
- make test-with-python3.6
93+
- name: Test (Python 3.7, Docker)
94+
env: DOCKER=true
95+
before_install:
96+
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
97+
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
98+
- sudo apt-get update
99+
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
100+
install:
101+
- make use-docker
102+
- make build-with-python3.7
103+
script:
104+
- make test-with-python3.7
105+
- name: Test (Python 3.8, Docker)
106+
env: DOCKER=true
107+
before_install:
108+
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
109+
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
110+
- sudo apt-get update
111+
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
112+
install:
113+
- make use-docker
114+
- make build-with-python3.8
115+
script:
116+
- make test-with-python3.8
117+
- stage: "Code quality checks"
118+
python: 3.8
119+
name: Check formatting
43120
env:
44121
- TOX_ENV=check-format
45122
- python: 3.8
123+
name: Run flake8 checks
46124
env:
47125
- TOX_ENV=flake8
48126
- python: 3.8
127+
name: Run bandit checks
49128
env:
50129
- TOX_ENV=bandit
51130
- python: 3.8
131+
name: Run mypy checks
52132
env:
53133
- TOX_ENV=mypy
54-
- python: 3.8
134+
- stage: "Documentation"
135+
python: 3.8
136+
name: Generate documentation
55137
env:
56138
- TOX_ENV=docs
57139
- python: 3.6
140+
name: Publish coverage
58141
env:
59142
- TOX_ENV=publish-coverage
60143
- secure: "iBpfQQnq7LqJC9Tc4M7EuRiK5RSZLjsmacp6Ns9obpkkHQyJFWS80760BOD8iBsi9cor5w6z0JzLBIJYLGRZAmUNW7y76K+NKXs9pEn/i6mF7V8rXCzU6tyJ28xH6csNt9KAkoHIbXmt+0TAa4tN+uCRq2c7rHVbuarCfQBVislpJZl9qz61WVvDBfxpefL4VKCkteHxNTGMdZvw0wnc1+RvluNLeuNQ6TpPnJ7iS2FPGXOOMhcj26ZVL5cPMqIwX5IIo2JlWczMqXYWwoN+PC+4YlZclH+c73yl3XcZL9twq4g1cvW39HKAd5QDpQPapLep+3OF39bBiYetlqLUImHgCI/IwufV7RSceW+HUv1rqTVIteglRWhmR1ePZYeuJxLsuGnIbKRJcUnob7spk2Oxwr+ZrvqqC3+ivSpaPQiZjtIp2mdTEvetWm6X7xjMvk8FQKJZedp8CaRO8TEd9U5Cy3XxCA/hXNIThhxWtkpCwqmGs/VGV6Ao6swsuN/z9YxUQ2uIKvml7KwzCj1QYOhpHkdcxRGyTy/xoEUvQ4Vm7XGcrxksUKKBu1K9VCIdANo73w0WwTM6BPSWiMKDMHCUaJFqLiSr3gZwT2oUrPt83f9THdY7hl67NeZB7v0DHm/c4BSXf7nrkWmxREAUd86KRcrdczqe7NIJJGzpkRM="
61-
- python: 3.8
62-
sudo: yes
63-
env:
64-
- TOX_ENV=py38
65-
- MBTEST_VERSION=2.1
66-
- python: 3.8
67-
sudo: yes
68-
env:
69-
- TOX_ENV=py38
70-
- MBTEST_VERSION=2.0
71-
- python: 3.8
72-
sudo: yes
73-
env:
74-
- TOX_ENV=py38
75-
- MBTEST_VERSION=1.16
144+
76145
before_install:
77146
- nvm install 12
78147
- pip install --upgrade tox

Dockerfile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
ARG python_version
2+
FROM python:${python_version}-slim
3+
4+
ARG nodejs_major_version=14
5+
ARG nodejs_minor_version=2
6+
ARG nodejs_revision=0
7+
ARG mountebank_version=2.2.1
8+
ARG nodejs_apt_version=$nodejs_major_version.$nodejs_minor_version.${nodejs_revision}-1nodesource1
9+
10+
RUN apt-get update && apt-get -y install curl --no-install-recommends \
11+
&& curl -sL https://deb.nodesource.com/setup_$nodejs_major_version.x | bash - \
12+
&& apt-get -y install nodejs=$nodejs_apt_version --no-install-recommends \
13+
&& apt-get clean \
14+
&& rm -rf /var/lib/apt/lists/*
15+
16+
# We choose the user and group ID to match the TravisCI executor user and group, to avoid permission issues
17+
# when writing to bind-mounted folders.
18+
ARG user_id=1001
19+
ARG group_id=1002
20+
ARG user=travisci
21+
ARG group=travisci
22+
RUN addgroup --system $group --gid $group_id && adduser $user --gid $group_id --uid $user_id
23+
ARG workdir=/mbtest/
24+
RUN mkdir -p $workdir && chown $user:$group $workdir
25+
USER $user
26+
ENV PATH /home/$user/.local/bin:/home/$user/bin:$PATH
27+
ENV PYTHONPATH=${PYTHONPATH}:$workdir;${PYTHONPATH}:$workdir/src
28+
WORKDIR $workdir
29+
RUN npm install mountebank@$mountebank_version --production
30+
COPY --chown=${user}:${group} . ./
31+
RUN pip install -e .[test,coverage,docs] --user

Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ repl: ## Python REPL
8888
outdated: ## List outdated dependancies
8989
tox -e py38 -- pip list --outdated
9090

91+
.PHONY: use-docker
92+
use-docker: ## Use Docker-based local development workflow
93+
mv Makefile Makefile.tox
94+
mv Makefile.Docker Makefile
95+
9196
.PHONY: help
9297
help: ## Show this help
9398
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1,$$2}'

Makefile.Docker

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
SHELL = /bin/bash
2+
3+
default: help
4+
5+
PYTHON_VERSIONS = 3.5 3.6 3.7 3.8
6+
DEFAULT_PYTHON_VERSION = 3.8 # The version to use for commands other than testing, such as document generation.
7+
IMAGE_NAME = mbtest-dev
8+
9+
USER_ID = $(shell id -u $${USER})
10+
USERNAME = $(shell id -un)
11+
12+
build_all = $(addprefix build-with-python, $(PYTHON_VERSIONS))
13+
test_all = $(addprefix test-with-python, $(PYTHON_VERSIONS))
14+
15+
.PHONY: build-with-python%
16+
build-with-python%: ## Build Docker image for containerised development with specified Python version
17+
docker build . --build-arg user=$(USERNAME) \
18+
--build-arg user_id=$(USER_ID) \
19+
--build-arg python_version=$* -t $(IMAGE_NAME):python$*
20+
21+
.PHONY: build
22+
build: $(build_all) ## Build Docker images for containerised development
23+
24+
.PHONY: shell-with-python%
25+
shell-with-python%: ## Open an interactive shell in the development Docker container with the specified Python version
26+
docker run --volume $(PWD):/mbtest --volume node_modules:/mbtest/node_modules -it $(IMAGE_NAME):python$* bash
27+
28+
.PHONY: test-with-python%
29+
test-with-python%: ## Test with the specified Python version
30+
docker run --volume $(PWD):/mbtest --volume node_modules:/mbtest/node_modules -it $(IMAGE_NAME):python$* bash -c "python -m pytest -rf ./tests"
31+
32+
.PHONY: test
33+
test: $(test_all) ## Run tests
34+
35+
.PHONY: use-tox
36+
use-tox: ## Use the tox-based local development workflow
37+
mv Makefile Makefile.Docker
38+
mv Makefile.tox Makefile
39+
40+
41+
.PHONY: help
42+
help: ## Show this help
43+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1,$$2}'
44+
45+

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ After that, you should be ready to roll; running `make test` will let you know i
9797
Running `make precommit` tells you if you're OK to commit. For more options, run:
9898

9999
make help
100+
101+
### Developing with Docker
102+
103+
An alternative to using PyEnv and tox is to use Docker. To get started, run `make use-docker` then `make build`; this
104+
will build the required Docker images.
105+
106+
Note that the Docker-based development workflow is currently a work in progress and does not yet offer the same set of
107+
development commands as the tox-based workflow. To switch back, run `make use-tox`.
100108

101109
## Releasing
102110

requirements.txt

-3
This file was deleted.

0 commit comments

Comments
 (0)