diff --git a/webapp/Makefile b/webapp/Makefile index 5a3a0f7..e4addd3 100644 --- a/webapp/Makefile +++ b/webapp/Makefile @@ -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) . diff --git a/webapp/scripts/container-check b/webapp/scripts/container-check new file mode 100755 index 0000000..0382087 --- /dev/null +++ b/webapp/scripts/container-check @@ -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