Skip to content

Commit

Permalink
docker: add healthchecks
Browse files Browse the repository at this point in the history
  • Loading branch information
MNThomson committed Jul 16, 2024
1 parent ec9aa56 commit 287ca1e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ RUN adduser --system --home /var/lib/sqld --uid 666 --gid 666 sqld
WORKDIR /var/lib/sqld
USER sqld

COPY docker-entrypoint.sh /usr/local/bin
COPY docker-entrypoint.sh docker-healthcheck.sh /usr/local/bin

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /target/release/sqld /bin/sqld

HEALTHCHECK --interval=2s CMD /usr/local/bin/docker-healthcheck.sh
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["/bin/sqld"]
3 changes: 2 additions & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN apt update

COPY --from=builder /sqld/bin /bin/sqld
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY docker-entrypoint.sh /usr/local/bin
COPY docker-entrypoint.sh docker-healthcheck.sh /usr/local/bin

VOLUME [ "/var/lib/sqld" ]

Expand All @@ -35,5 +35,6 @@ WORKDIR /var/lib/sqld

EXPOSE 5001 8080

HEALTHCHECK --interval=2s CMD /usr/local/bin/docker-healthcheck.sh
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["/bin/sqld"]
18 changes: 18 additions & 0 deletions docker-healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -euo pipefail

SQLD_HTTP_LISTEN_ADDR="${SQLD_HTTP_LISTEN_ADDR:-"0.0.0.0:8080"}"
SQLD_HTTP_LISTEN_ADDR="${SQLD_HTTP_LISTEN_ADDR//:/\/}"

exec 3<>"/dev/tcp/$SQLD_HTTP_LISTEN_ADDR"
echo -e "GET /health HTTP/1.1\r\nConnection: close\r\n\r\n" >&3
RESPONSE=$(cat <&3)
exec 3<&- && exec 3>&-

if echo "$RESPONSE" | grep -q "HTTP/1.1 200 OK"; then
exit 0
else
echo "Did not receive HTTP 200 response"
echo "$RESPONSE"
exit 1
fi

0 comments on commit 287ca1e

Please sign in to comment.