Make the validation of the webapp container a bit more useful

This is almost a liveness probe 🔥
This commit is contained in:
R. Tyler Croy 2018-01-02 13:15:06 -08:00
parent 68b1cfae24
commit b01b105619
No known key found for this signature in database
GPG Key ID: 1426C7DC3F51E16F
2 changed files with 36 additions and 1 deletions

View File

@ -14,7 +14,7 @@ run: depends monkeys.txt
./scripts/ruby bundle exec puma
check-container: container
docker run --rm $(IMAGE_NAME):latest bundle exec puma --version
IMAGE_NAME=$(IMAGE_NAME) ./scripts/container-check
container: depends Dockerfile monkeys.txt
docker build -t $(IMAGE_NAME) .

35
webapp/scripts/container-check Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env bash
NAME=codevalet-webapp-container-check
PORT=9292
URL=http://127.0.0.1:${PORT}/
function terminate {
echo ">> Terminating ${NAME}"
docker stop ${NAME}
docker rm ${NAME}
}
trap terminate EXIT
docker run --detach -p ${PORT}:${PORT} \
--name ${NAME} \
${IMAGE_NAME}:latest \
for i in $(seq 1 10); do
echo ">> Attempt #${i} to reach ${URL}"
curl -sI ${URL} 2>&1 > /dev/null
if [ $? -ne 0 ]; then
sleep 1
else
echo '----> :) The app returned a 200'
exit 0
fi;
sleep 1
done;
echo "----> :( Failed to reach the container"
docker ps
# If we get to here without having bailed out, something is wrong
exit 1