Skip to content
Advertisement

Using wait-for-it.sh to wait on an endpoint with a slash

Background: I have a project that runs a docker image (in production it will run in knative, but for testing, docker/docker compose is a good first step), and as part of my CI/CD pipeline, I would like to run acceptance tests against the image. I have the image configured to run in docker, and the (cucumber) acceptance tests run as part of a gradle task. I would like the gradle testing to wait until the image is spun up (the image itself takes under .02 of a second to start thanks to graalvm ahead of time compilation, but the gitlab runner can be slow). I have hooked up a wait-for-it.sh script (https://gitlab.com/connorbutch/reading-comprehension/-/blob/5-implement-glue-code/wait-for-it.sh) and that works to wait for localhost:8080 (you can verify yourself by executing the following command: docker run -i --rm -p 8080:8080 connorbutch/reading-comprehension-server-quarkus-impl & ./wait-for-it.sh localhost:8080 --timeout=10 --strict -- ./gradlew acceptanceTest), but but I would like to have the task wait for localhost:8080/health/readiness, and the following command does not work: docker run -i --rm -p 8080:8080 connorbutch/reading-comprehension-server-quarkus-impl & ./wait-for-it.sh localhost:8080/health/readiness --timeout=10 --strict -- ./gradlew acceptanceTest It is important to note the application starts up in .02 seconds at the slowest, so the endpoint is up and working, it is an issue with how I am running the wait-for-it script

Any ideas on how to input the values to wait for it so that I have the wait-for-it.sh test a url containing a slash? Alternatively, any other input on how to perform this ordering would be great too!

If you’d like to run locally, clone the code from (https://gitlab.com/connorbutch/reading-comprehension/-/tree/5-implement-glue-code) (only requirement is to have docker), execute the ./run-it.sh, then use the above commands Thanks, Connor

Advertisement

Answer

wait-for-it.sh is a pure bash script that will wait on the availability of a host and TCP port.

you can’t use it to check if service deployed into the server or URL is returning response or not , so you have to implement your own entry point script by using curl command and sleep to wait for that URL to return 200 ok or the response which you are expecting

you can start from here

S=0

while [ $S -ne 200 ]
do

S=$(curl -s -o /dev/null -w "%{http_code}"  http://www.google.com )

sleep 1 

done ;

echo "DONE !!"

#write the script to start the service 
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement