./wait-for-healthy
is a script designed to synchronize services like docker containers. It is sh and alpine compatible. It was inspired by vishnubob/wait-for-it and eficode/wait-for.
When using this tool, you only need to pick the wait-for-healthy
file as part of your project.
To install wait-for-healthy
just run
RUN wget https://raw.githubusercontent.com/ninjaneers-team/wait-for-healthy/master/wait-for-healthy
inside your docker image and do a chmod +x
.
You can although use a special version when you replace /master
with v1.1.0
or any other tag.
RUN wget https://raw.githubusercontent.com/ninjaneers-team/wait-for-healthy/v1.1.0/wait-for-healthy
ninjaneers/flywait Example:
FROM boxfuse/flyway
RUN apt-get update && apt-get install -y \
curl
RUN wget https://raw.githubusercontent.com/ninjaneers-team/wait-for-healthy/master/wait-for-healthy
RUN ["chmod", "+x", "./wait-for-healthy"]
ENTRYPOINT [ "bin/sh" ]
Important: cUrl needs to be installed
./wait-for-healthy url [-m method] [-t timeout] [-- command args]
-q | --quiet Do not output any status messages
-m | --method Set HTTP method (Default: GET)
-t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes
To check if ninjaneers.de is healthy:
$ ./wait-for-healthy ninjaneers.de GET -- echo "Ninjaneers site is up"
Connection to ninjaneers.de [tcp/http] succeeded!
Ninjaneers site is up
To check any service which respond to a POST request healthy status (200, 201 HTTP status code):
$ ./wait-for-healthy anyservice:9000/api/status -m POST -- echo "Service is up and healthy"
Connection to anyservice:9000/api/status [tcp/http] succeeded!
Service site is healthy
Ironically testing is done using bats, which on the other hand is depending on bash.
docker build -t wait-for-healthy .
docker run -t wait-for-healthy
Code analysis is done using shellcheck