Skip to content

Commit 70ff1d7

Browse files
author
Oleksii Tsvietnov
committed
Add a new example
1 parent 91b9a98 commit 70ff1d7

File tree

1 file changed

+10
-3
lines changed
  • examples/reliable-tests-of-docker-images

1 file changed

+10
-3
lines changed

examples/reliable-tests-of-docker-images/README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
# Reliable tests of docker images
22

3-
If you have automated builds of docker images, you need to be sure that these images are not only built successfuly but also run services. Sometimes, services fail immidiately after they were started up.
3+
If you have automated builds of docker images, you need to be sure that these images are not only built successfuly but also run services. Sometimes, services fail immediately after they were started up.
44

55
This is an example of how services can be reliably tested without any extra efforts by adding a test proccess on the background and then, checking the exit status on exit.
66

7-
As an example docker image I'm going to use [OpenSMTPD](https://github.com/vorakl/docker-images/tree/master/centos-opensmtpd) service image. Then, inject a background test command. In case of a success test, it will send a specific signal to the main process and cause by this (because a default wait policy is `wait_any`) a stop the whole container. On exit, I'll inject a `halt` command to check if the main process has cought my signal (128 + 10 = 138). If yes, I'll rewrite an exit status to 0 (success). Otherwise, the script will finish with some other error.
7+
As an example docker image I'm going to use [OpenSMTPD](https://github.com/vorakl/docker-images/tree/master/centos-opensmtpd) service image. Then, inject a background test command. In case of a success test, it will send a specific signal to the main process and cause (because a default wait policy is `wait_any`) a stop the whole container. On exit, I'll inject a `halt` command to check if the main process has cought my signal (128 + 10 = 138). If yes, I'll rewrite an exit status to 0 (success). Otherwise, the script will finish with some other error.
88

9-
So many words but in fact it looks much more simple. It just a one-liner:
9+
So many words but in fact it looks much more simple.
10+
The container with a service resides in [vorakl/centos-opensmtpd](https://hub.docker.com/r/vorakl/centos-opensmtpd/) and can be simply started as
11+
12+
```bash
13+
$ docker run -d --name smtpd --net host vorakl/centos-opensmtpd
14+
```
15+
16+
Let's add two (`async`, -D and `halt`, -H) additional commands to test the service and check the result:
1017

1118
```bash
1219
$ docker run --rm vorakl/centos-opensmtpd -H 'if [[ ${_exit_status} -eq 138 ]]; then exit 0; else exit ${_exit_status}; fi' -D 'sleep 3; smtpctl show status && kill -10 ${MAINPID}'

0 commit comments

Comments
 (0)