Im using CapRover to manage my Laravel app.
Even though CapRover does have logic to achieve zero downtime deployment (e.g. using stop-first
and/or start-first
), but Im getting 502 HTTP error for ~5s after every successful deployment.
I was advised to use Docker healthcheck
command to make sure the newly built container is healthy before making live.
Here is what I have tried:
My Dockerfile:
...
EXPOSE 80
COPY ./.deploy/production/entrypoint.sh /
ENTRYPOINT ["sh", "/entrypoint.sh"]
COPY ./.deploy/production/healthcheck.sh /
HEALTHCHECK --interval=2s --timeout=5m --start-period=3s CMD bash healthcheck.sh
and here is healthcheck.sh script:
#!/bin/sh
code=$(curl -o /dev/null -s -w "%{http_code}\n" http://localhost/ping)
echo "response code: $code"
if [ "$code" == "200" ]
then
echo "success"
exit 0;
else
echo "error"
exit 1;
fi
and the /ping
route just simply returns 200 "ok":
// My Laravel web.php
Route::get('/ping', function () {
return 'ok';
});
See line 280 where the healthcheck.sh script gets called, but it actually does not do anything. The build has finished successfully, but the new code was not successfully deployed.
I've double checked this by manually open the browser the hit "mydomain.com/ping" and got 404 instead of 200 "ok" (the "/ping" route is the new code, supposed to be in production after deployed).
I don't know whats wrong here.
This is the output of docker ps
:
Can anyone shed some light here please?
Cheers,