Skip to content

Commit 91b9a98

Browse files
author
Oleksii Tsvietnov
committed
Add a new example
1 parent 10a4096 commit 91b9a98

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ To get started and find out some features, I suggest to go through these example
100100
* This solution shows how to [configure services in a docker container by using templates](https://github.com/vorakl/TrivialRC/tree/master/examples/docker-config-templates) and environment variables
101101
* This trick shows how to [create configuration on the fly](https://github.com/vorakl/TrivialRC/tree/master/examples/self-configuring) from the `boot` stage
102102
* [Serial launching of a group of parallel processes](https://github.com/vorakl/TrivialRC/tree/master/examples/sync-run-of-async-groups) and failing immediately if some group failed
103+
* [Reliable tests](https://github.com/vorakl/TrivialRC/tree/master/examples/reliable-tests-of-docker-images) of docker images
103104

104105
## Command line options
105106

@@ -229,7 +230,7 @@ You can also use some of internal functions in async/sync tasks:
229230
230231
## Useful global variables
231232
232-
* `MAINPID`, for sending signals to the main process
233+
* `MAINPID`, for sending signals to the main process ([example1](https://github.com/vorakl/TrivialRC/tree/master/examples/reliable-tests-of-docker-images))
233234
* `_exit_status`, for checking or rewriting an exit status of the whole script ([example1](https://github.com/vorakl/TrivialRC/blob/master/examples/process-manager/trc.d/halt.remove-logs), [example2](https://github.com/vorakl/TrivialRC/blob/master/examples/docker-service-discovery/trc.d/halt.sd-unreg))
234235
235236
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Reliable tests of docker images
2+
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.
4+
5+
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.
6+
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.
8+
9+
So many words but in fact it looks much more simple. It just a one-liner:
10+
11+
```bash
12+
$ 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}'
13+
14+
2017-03-16 21:40:50 trc [main/1]: The wait policy: wait_any
15+
2017-03-16 21:40:50 trc [async/15]: Launching on the background: /etc/trc.d/async.opensmtpd
16+
2017-03-16 21:40:50 trc [async/16]: Launching on the background: sleep 3; smtpctl show status && kill -10 ${MAINPID}
17+
info: OpenSMTPD 6.0.2p1 starting
18+
setup_peer: klondike -> control[28] fd=4
19+
setup_peer: klondike -> pony express[30] fd=5
20+
setup_done: ca[27] done
21+
setup_proc: klondike done
22+
setup_peer: control -> klondike[27] fd=5
23+
setup_peer: control -> lookup[29] fd=6
24+
setup_peer: control -> pony express[30] fd=7
25+
setup_peer: control -> queue[31] fd=8
26+
setup_peer: control -> scheduler[32] fd=9
27+
setup_done: control[28] done
28+
setup_proc: control done
29+
setup_peer: scheduler -> control[28] fd=9
30+
setup_peer: scheduler -> queue[31] fd=10
31+
setup_peer: lookup -> control[28] fd=6
32+
setup_peer: lookup -> pony express[30] fd=7
33+
setup_peer: lookup -> queue[31] fd=8
34+
setup_done: lka[29] done
35+
setup_proc: lookup done
36+
setup_peer: pony express -> control[28] fd=7
37+
setup_peer: queue -> control[28] fd=8
38+
setup_peer: pony express -> klondike[27] fd=8
39+
setup_peer: queue -> pony express[30] fd=9
40+
setup_peer: queue -> lookup[29] fd=10
41+
setup_peer: queue -> scheduler[32] fd=11
42+
setup_peer: pony express -> lookup[29] fd=9
43+
setup_peer: pony express -> queue[31] fd=10
44+
setup_done: pony[30] done
45+
setup_proc: pony express done
46+
setup_done: queue[31] done
47+
setup_proc: scheduler done
48+
setup_done: scheduler[32] done
49+
smtpd: setup done
50+
warn: purge_task: opendir: No such file or directory
51+
setup_proc: queue done
52+
MDA running
53+
MTA running
54+
SMTP running
55+
2017-03-16 21:40:53 trc [async/16]: Exiting on the background (exitcode=0): sleep 3; smtpctl show status && kill -10 ${MAINPID}
56+
2017-03-16 21:40:53 trc [main/1]: Trying to terminate sub-processes...
57+
2017-03-16 21:40:53 trc [main/1]: terminating the child process <pid=15>
58+
info: Terminated, shutting down
59+
info: control process exiting
60+
info: ca agent exiting
61+
info: pony agent exiting
62+
info: queue handler exiting
63+
info: lookup agent exiting
64+
info: scheduler handler exiting
65+
warn: parent terminating
66+
2017-03-16 21:40:53 trc [async/15]: Exiting on the background (exitcode=0): /etc/trc.d/async.opensmtpd
67+
2017-03-16 21:40:54 trc [halt/60]: Running the shutdown command: if [[ ${_exit_status} -eq 138 ]]; then exit 0; else exit ${_exit_status}; fi
68+
2017-03-16 21:40:54 trc [main/1]: Exiting from the shutdown command (exitcode=0): if [[ ${_exit_status} -eq 138 ]]; then exit 0; else exit ${_exit_status}; fi
69+
2017-03-16 21:40:54 trc [main/1]: Exited (exitcode=0)
70+
```

0 commit comments

Comments
 (0)