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 30, 2024
1 parent a64a089 commit 2a60f9a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ 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-wrapper.sh /usr/local/bin
COPY docker-entrypoint.sh docker-wrapper.sh docker-healthcheck.sh /usr/local/bin

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

USER root

HEALTHCHECK --interval=2s CMD /usr/local/bin/docker-healthcheck.sh
ENTRYPOINT ["/usr/local/bin/docker-wrapper.sh"]
CMD ["/bin/sqld"]
5 changes: 3 additions & 2 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,22 @@ FROM debian:bullseye-slim
RUN apt update

EXPOSE 5001 8080

VOLUME [ "/var/lib/sqld" ]

RUN groupadd --system --gid 666 sqld
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-wrapper.sh /usr/local/bin
COPY docker-entrypoint.sh docker-wrapper.sh docker-healthcheck.sh /usr/local/bin

COPY --from=gosu /usr/local/bin/gosu /usr/local/bin/gosu
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /sqld/bin /bin/sqld

USER root

HEALTHCHECK --interval=2s CMD /usr/local/bin/docker-healthcheck.sh
ENTRYPOINT ["/usr/local/bin/docker-wrapper.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 2a60f9a

Please sign in to comment.