Skip to content

Commit 20bf988

Browse files
authored
Merge pull request #24 from absolutejam/feat/docker_local_testing
Add support for testing locally using Docker
2 parents 2701860 + 6431b86 commit 20bf988

File tree

17 files changed

+240
-0
lines changed

17 files changed

+240
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
66
## [Unreleased]
77
### Added
88
- Add support for python 3.5, which is the default version in Debian 9. (@barryorourke)
9+
- Added Dockerfiles and docker-compose.yml to aid with local development & testing (@absolutejam)
910

1011
## [0.3.2] 2017-10-10
1112
### Fixed

docker/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# README
2+
3+
To help lint & check the contents of this repo, docker resources have been
4+
provided.
5+
6+
The simplest way to run the tests is to use `docker-compose`. Within the
7+
docker directory, run `docker-compose run --rm <version>`, where version is
8+
one of `2.7`,`3.4`,`3.5`,`3.6`. This will automatically build the docker
9+
images from the `docker_build` directory and run the `run_tests` script against
10+
the `sensu_plugin` directory within the container, removing the container
11+
one exit.
12+
13+
For any additional prerequisites that are needed (eg. python modules),
14+
ammend `docker_build/setup.sh` and then run `docker_build/update` (This
15+
copies the ammended `setup.sh` into each image directory). Procede to rebuild
16+
the docker images, either via.
17+
`docker build -t python:2.7.14-sensuci ./docker_build/2.7`
18+
or with `docker-compose build 2.7`.
19+
20+
If you are feeling adventurous, you can simply `docker-compose up` to build
21+
and launch all of the containers at once!

docker/docker-compose.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
version: "2.1"
2+
3+
services:
4+
"2.7":
5+
image: "python:2.7.14-sensuci"
6+
build: "./docker_build/2.7"
7+
hostname: "2.7"
8+
container_name: "sensuplugin_python2.7"
9+
volumes:
10+
- "../sensu_plugin:/sensu_plugin/"
11+
- "../run_tests:/entrypoint.sh:ro"
12+
13+
"3.4":
14+
image: "python:3.4-sensuci"
15+
build: "./docker_build/3.4"
16+
hostname: "3.4"
17+
container_name: "sensuplugin_python3.4"
18+
volumes:
19+
- "../sensu_plugin:/sensu_plugin"
20+
- "../run_tests:/entrypoint.sh:ro"
21+
22+
"3.5":
23+
image: "python:3.5.4-sensuci"
24+
build: "./docker_build/3.5"
25+
hostname: "3.5"
26+
container_name: "sensuplugin_python3.5"
27+
volumes:
28+
- "../sensu_plugin:/sensu_plugin"
29+
- "../run_tests:/entrypoint.sh:ro"
30+
31+
"3.6":
32+
image: "python:3.6-sensuci"
33+
build: "./docker_build/3.6"
34+
hostname: "3.6"
35+
container_name: "sensuplugin_python3.6"
36+
volumes:
37+
- "../sensu_plugin:/sensu_plugin"
38+
- "../run_tests:/entrypoint.sh:ro"

docker/docker_build/2.7/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM python:2.7
2+
3+
ADD ./setup.sh /setup.sh
4+
5+
RUN chmod +x /setup.sh && \
6+
bash -c /setup.sh
7+
8+
ENTRYPOINT [ "/entrypoint.sh" ]

docker/docker_build/2.7/entrypoint.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
3+
EXIT=0
4+
pep8 sensu_plugin
5+
RC=$?
6+
if [ $RC -ne 0 ]; then
7+
EXIT=1
8+
fi
9+
pylint --rcfile=pylint.rc sensu_plugin
10+
RC=$?
11+
if [ $RC -ne 0 ]; then
12+
EXIT=1
13+
fi
14+
nosetests --with-coverage --cover-package=sensu_plugin \
15+
--cover-min-percentage=35 sensu_plugin/test/
16+
RC=$?
17+
if [ $RC -ne 0 ]; then
18+
EXIT=1
19+
fi
20+
21+
echo
22+
echo "Exiting with code $EXIT"
23+
exit $EXIT

docker/docker_build/2.7/setup.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
set -x
3+
4+
apt update
5+
6+
# Module requirements
7+
pip install requests
8+
9+
# Testing requiremenets
10+
pip install pep8 pylint nose coverage

docker/docker_build/3.4/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM python:3.4
2+
3+
COPY setup.sh /setup.sh
4+
5+
RUN chmod +x /setup.sh && \
6+
/setup.sh
7+
8+
ENTRYPOINT [ "/entrypoint.sh" ]

docker/docker_build/3.4/entrypoint.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
3+
EXIT=0
4+
pep8 sensu_plugin
5+
RC=$?
6+
if [ $RC -ne 0 ]; then
7+
EXIT=1
8+
fi
9+
pylint --rcfile=pylint.rc sensu_plugin
10+
RC=$?
11+
if [ $RC -ne 0 ]; then
12+
EXIT=1
13+
fi
14+
nosetests --with-coverage --cover-package=sensu_plugin \
15+
--cover-min-percentage=35 sensu_plugin/test/
16+
RC=$?
17+
if [ $RC -ne 0 ]; then
18+
EXIT=1
19+
fi
20+
21+
echo
22+
echo "Exiting with code $EXIT"
23+
exit $EXIT

docker/docker_build/3.4/setup.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
set -x
3+
4+
apt update
5+
6+
# Module requirements
7+
pip install requests
8+
9+
# Testing requiremenets
10+
pip install pep8 pylint nose coverage

docker/docker_build/3.5/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM python:3.5
2+
3+
COPY setup.sh /setup.sh
4+
5+
RUN chmod +x /setup.sh && \
6+
/setup.sh
7+
8+
ENTRYPOINT [ "/entrypoint.sh" ]

0 commit comments

Comments
 (0)