Skip to content

Commit

Permalink
Add jq-based healthcheck script for checking the readiness endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
matt committed Sep 5, 2024
1 parent 8f7fb5f commit e6885d3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/aptos-cli/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ WORKDIR /app
ENV PATH=/usr/local/bin:$PATH
COPY --from=aptos-cli $CLI_BINARY /usr/local/bin

COPY sh/healthcheck.sh /app/sh/healthcheck.sh
RUN chmod +x /app/sh/healthcheck.sh

STOPSIGNAL SIGKILL

# Set the default healthcheck to `curl` the default readiness endpoint.
HEALTHCHECK \
--interval=5s \
--timeout=5s \
--start-period=60s \
--retries=10 \
CMD [ "curl", "http://localhost:8070/" ]
CMD [ "bash", "sh/healthcheck.sh" ]

# Note that the `--bind-to 0.0.0.0` flag is required to undo the default CLI
# behavior of binding to 127.0.0.1 since `aptos` v2.3.2.
Expand Down
18 changes: 18 additions & 0 deletions src/aptos-cli/sh/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Note that the response from the readiness endpoint at http://localhost:8070
# is a JSON object of the following structure:
#
# {
# "ready": [
# // Objects describing services that are ready.
# ],
# "not_ready": [
# // Objects describing services that are not ready.
# ]
# }
#
# `curl` the readiness endpoint and check if the `not_ready` array is empty.
# Pipe the output from `jq` to `grep` to check if the length is 0.

curl -s http://localhost:8070/ | jq '.not_ready | length' | grep -q 0

0 comments on commit e6885d3

Please sign in to comment.