Skip to content
Closed
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ RUN ./scripts/build.sh
# ============= Cleanup Stage ================
FROM debian:11-slim AS execution

# Install curl and jq to support healthchecks
RUN apt update && apt install -y curl jq

# Maintain compatibility with previous images
RUN mkdir -p /avalanchego/build
WORKDIR /avalanchego/build

# Copy the executables into the container
COPY --from=builder /build/build/ .

COPY scripts/docker/healthcheck.sh .
HEALTHCHECK --timeout=3s --start-period=1m CMD ./healthcheck.sh

CMD [ "./avalanchego" ]
23 changes: 23 additions & 0 deletions scripts/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "3.3"
services:
autoheal:
image: willfarrell/autoheal:latest
container_name: autoheal
volumes:
- /var/run/docker.sock:/var/run/docker.sock
restart: unless-stopped
avalanchego:
image: avaplatform/avalanchego:latest
container_name: avalanchego
hostname: avalanchego
user: "9650"
labels:
autoheal: "true"
environment:
- HOME=/avalanchego
volumes:
- /home/avalanchego/.avalanchego:/avalanchego/.avalanchego
ports:
- 9650:9650
- 9651:9651
restart: unless-stopped
36 changes: 36 additions & 0 deletions scripts/docker/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

function isBootstrapped() {
# Check the Info API:
# https://docs.avax.network/apis/avalanchego/apis/info/#infoisbootstrapped
BOOTSTRAPPED=$(curl --silent -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"info.isBootstrapped",
"params": {
"chain":"'"${1}"'"
}
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/info | jq .result.isBootstrapped)

echo "${BOOTSTRAPPED}"
}

# Check the Health API:
# https://docs.avax.network/apis/avalanchego/apis/health/
HEALTHY=$(curl --silent -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"health.health"
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/health | jq .result.healthy)
if [ "${HEALTHY}" = "true" ]; then
exit 0
fi

# Consider bootstrapping chains as healthy, even if the Health API says otherwise.
if [ "$(isBootstrapped 'P')" = "false" ] || \
[ "$(isBootstrapped 'X')" = "false" ] || \
[ "$(isBootstrapped 'C')" = "false" ]; then
exit 0
fi

exit 1