mirror of
https://github.com/willfarrell/docker-autoheal.git
synced 2024-12-06 19:16:20 +01:00
Merge pull request #58 from hasnat/add_tests
Try tests via docker-compose
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
.github
|
||||
.gitignore
|
||||
.dockerignore
|
||||
Dockerfile
|
||||
tests
|
||||
@@ -0,0 +1,13 @@
|
||||
# Docker Autoheal Tests
|
||||
|
||||
Docker Compose is used to build and deploy test environment.
|
||||
|
||||
test.sh waits on watch-autoheal exit code.
|
||||
|
||||
Currently setup to a very basic exit 1 on invalid restart and exit 0 on valid restart.
|
||||
|
||||
## Run tests
|
||||
```
|
||||
cd tests
|
||||
./tests.sh
|
||||
```
|
||||
@@ -0,0 +1,11 @@
|
||||
version: '3.7'
|
||||
|
||||
services:
|
||||
|
||||
watch-autoheal:
|
||||
container_name: watch-autoheal
|
||||
build: watch-autoheal
|
||||
restart: "no"
|
||||
volumes:
|
||||
- "/var/run/docker.sock:/var/run/docker.sock"
|
||||
network_mode: none
|
||||
@@ -0,0 +1,42 @@
|
||||
version: '3.7'
|
||||
|
||||
services:
|
||||
|
||||
should-keep-restarting:
|
||||
image: alpine
|
||||
container_name: should-keep-restarting
|
||||
network_mode: none
|
||||
restart: "no"
|
||||
healthcheck:
|
||||
test: exit 1
|
||||
interval: 3s
|
||||
timeout: 1s
|
||||
retries: 3
|
||||
start_period: 5s
|
||||
command: tail -f /dev/null
|
||||
|
||||
shouldnt-restart:
|
||||
image: alpine
|
||||
container_name: shouldnt-restart
|
||||
network_mode: none
|
||||
restart: "no"
|
||||
healthcheck:
|
||||
test: exit 0
|
||||
interval: 2s
|
||||
timeout: 1s
|
||||
retries: 1
|
||||
start_period: 1s
|
||||
command: tail -f /dev/null
|
||||
|
||||
|
||||
autoheal:
|
||||
container_name: autoheal
|
||||
build:
|
||||
context: ../
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
AUTOHEAL_CONTAINER_LABEL: "all"
|
||||
AUTOHEAL_INTERVAL: "10"
|
||||
volumes:
|
||||
- "/var/run/docker.sock:/var/run/docker.sock"
|
||||
network_mode: none
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euxo pipefail
|
||||
|
||||
COMPOSE_PROJECT_NAME=autoheal-test
|
||||
|
||||
function cleanup()
|
||||
{
|
||||
exit_status=$?
|
||||
echo "exit was $exit_status"
|
||||
docker-compose -f docker-compose.autoheal.yml -f docker-compose.yml rm -f || true
|
||||
exit "$exit_status"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
docker-compose up --build -d
|
||||
docker-compose -f docker-compose.autoheal.yml up --build --exit-code-from watch-autoheal watch-autoheal
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
FROM alpine:latest
|
||||
|
||||
RUN apk --update add bash docker
|
||||
|
||||
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
|
||||
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euxo pipefail
|
||||
|
||||
listenToDockerEvents()
|
||||
{
|
||||
docker events --filter 'container=should-keep-restarting' --filter 'container=shouldnt-restart' --filter 'event=restart' | while read LOGLINE
|
||||
do
|
||||
echo "$LOGLINE"
|
||||
# may be more elaborate checks here.
|
||||
[[ "${LOGLINE}" == *"container restart "*"name=shouldnt-restart"* ]] && echo "ERR: No restarts expected on shouldnt-restart container!" && pkill -9 docker && exit 1
|
||||
[[ "${LOGLINE}" == *"container restart "*"name=should-keep-restarting"* ]] && echo "OK: Expected restart on should-keep-restarting container!" && pkill -9 docker && exit 0
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
export -f listenToDockerEvents
|
||||
timeout 60s bash -c listenToDockerEvents
|
||||
Reference in New Issue
Block a user