mirror of
https://github.com/techno-tim/littlelink-server.git
synced 2026-09-03 20:52:55 -05:00
fix(docker): use IPv4 loopback for healthcheck (#855)
- Avoid localhost resolving to IPv6 when the server listens on IPv4.\n- Add a container health regression test to the Docker smoke-test workflow.\n- Closes #854.
This commit is contained in:
@@ -50,5 +50,6 @@ jobs:
|
|||||||
littlelink-server:pr
|
littlelink-server:pr
|
||||||
trap 'docker stop littlelink-pr 2>/dev/null' EXIT
|
trap 'docker stop littlelink-pr 2>/dev/null' EXIT
|
||||||
sleep 3
|
sleep 3
|
||||||
|
bash src/container-health-test.sh littlelink-pr
|
||||||
curl -s -o /dev/null -w "healthcheck: %{http_code}\\n" http://localhost:3100/healthcheck
|
curl -s -o /dev/null -w "healthcheck: %{http_code}\\n" http://localhost:3100/healthcheck
|
||||||
curl -s -o /dev/null -w "root: %{http_code}\\n" http://localhost:3100/
|
curl -s -o /dev/null -w "root: %{http_code}\\n" http://localhost:3100/
|
||||||
|
|||||||
+1
-1
@@ -37,5 +37,5 @@ COPY --from=node-build --chown=node:node /usr/src/app/public ./public
|
|||||||
USER node
|
USER node
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||||
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/healthcheck || exit 1
|
CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:3000/healthcheck || exit 1
|
||||||
CMD [ "node", "server.js" ]
|
CMD [ "node", "server.js" ]
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Verify the image's built-in Docker healthcheck.
|
||||||
|
# Usage: ./src/container-health-test.sh [container-name] [timeout-seconds]
|
||||||
|
|
||||||
|
set -u
|
||||||
|
|
||||||
|
CONTAINER_NAME="${1:-littlelink-pr}"
|
||||||
|
TIMEOUT_SECONDS="${2:-90}"
|
||||||
|
START_TIME=$(date +%s)
|
||||||
|
|
||||||
|
echo "=== Container healthcheck test ==="
|
||||||
|
echo "Container: $CONTAINER_NAME"
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
STATUS=$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}no-healthcheck{{end}}' "$CONTAINER_NAME" 2>/dev/null || true)
|
||||||
|
|
||||||
|
case "$STATUS" in
|
||||||
|
healthy)
|
||||||
|
echo "PASS Docker healthcheck is healthy"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
unhealthy|no-healthcheck)
|
||||||
|
echo "FAIL Docker healthcheck status: $STATUS"
|
||||||
|
docker inspect --format '{{json .State.Health}}' "$CONTAINER_NAME" 2>/dev/null || true
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ $(( $(date +%s) - START_TIME )) -ge "$TIMEOUT_SECONDS" ]; then
|
||||||
|
echo "FAIL Docker healthcheck did not become healthy within ${TIMEOUT_SECONDS}s"
|
||||||
|
docker inspect --format '{{json .State.Health}}' "$CONTAINER_NAME" 2>/dev/null || true
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user