Skip to content
This repository was archived by the owner on Aug 12, 2020. It is now read-only.

Commit cc67adf

Browse files
committed
feat: healthcheck
1 parent e687dc2 commit cc67adf

File tree

5 files changed

+59
-16
lines changed

5 files changed

+59
-16
lines changed

.github/workflows/build.yml

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
run: |
1919
docker build --build-arg VERSION=$RABBITMQ_VERSION --file Dockerfile.windows --tag exivity/rabbitmq:$RABBITMQ_VERSION .
2020
docker tag exivity/rabbitmq:$RABBITMQ_VERSION exivity/rabbitmq:latest
21+
- name: test
22+
run: test.sh
2123
- name: login
2224
run: echo $GITHUB_TOKEN | docker login -u $DOCKER_HUB_USER --password-stdin
2325
env:

Dockerfile.windows

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ RUN curl ('https://github.com/rabbitmq/rabbitmq-server/releases/download/v{0}/ra
1616
ENV RABBITMQ_SERVER="C:\Program Files\RabbitMQ Server\rabbitmq_server-${VERSION}"
1717

1818
ENV RABBITMQ_CONFIG_FILE="c:\rabbitmq"
19-
COPY rabbitmq.config C:/
20-
COPY rabbitmq.config C:/Users/ContainerAdministrator/AppData/Roaming/RabbitMQ/
19+
COPY healthcheck.cmd C:/
2120
COPY enabled_plugins C:/Users/ContainerAdministrator/AppData/Roaming/RabbitMQ/
2221

2322
EXPOSE 4369
24-
EXPOSE 5672
2523
EXPOSE 5671
24+
EXPOSE 5672
2625
EXPOSE 15672
2726

27+
HEALTHCHECK --interval=5s --timeout=60s CMD C:/healthcheck.cmd
28+
2829
WORKDIR C:/Program\ Files/RabbitMQ\ Server/rabbitmq_server-${VERSION}/sbin
2930
CMD .\rabbitmq-server.bat

healthcheck.cmd

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
curl --connect-timeout 5 --max-time 60 --retry 1 --user guest:guest http://localhost:15672/api/healthchecks/node

rabbitmq.config

-13
This file was deleted.

test.sh

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
3+
healthy=healthy
4+
5+
# https://gist.github.com/sj26/88e1c6584397bb7c13bd11108a579746
6+
function retry {
7+
local retries=$1
8+
shift
9+
10+
local count=0
11+
until "$@"; do
12+
exit=$?
13+
wait=$((2 ** $count))
14+
count=$(($count + 1))
15+
if [ $count -lt $retries ]; then
16+
echo "Retry $count/$retries exited $exit, retrying in $wait seconds..."
17+
sleep $wait
18+
else
19+
echo "Retry $count/$retries exited $exit, no more retries left."
20+
return $exit
21+
fi
22+
done
23+
return 0
24+
}
25+
26+
function health {
27+
docker inspect --format='{{json .State.Health.Status}}' rabbitmq
28+
}
29+
30+
function test {
31+
status=`health`
32+
33+
echo "Got status $status"
34+
35+
[ $status = "\"$healthy\"" ]
36+
}
37+
38+
set -e
39+
40+
docker run \
41+
--rm \
42+
--detach \
43+
-p 4369:4369 \
44+
-p 5671:5671 \
45+
-p 5672:5672 \
46+
-p 15672:15672 \
47+
--name rabbitmq \
48+
exivity/rabbitmq:latest
49+
50+
retry 10 test
51+
52+
docker stop rabbitmq

0 commit comments

Comments
 (0)