Skip to content

Commit

Permalink
Fix healthcheck issue on Docker (#72)
Browse files Browse the repository at this point in the history
### What was the problem?

This PR resolves #LISK-1129

### How was it solved?

- [x] Update healthcheck command on the Docker container
- [x] Set the API server host/port within the containers via the env
file build script
- [x] Update default API server host to be `0.0.0.0`
- [x] Update docker dev script to build image from local

### How was it tested?

Start the containers locally with the docker dev scripts
Run: `curl --fail https://localhost:3000/healthz` and check container
health with `docker ps`
  • Loading branch information
sameersubudhi authored Sep 25, 2024
1 parent 9bf4759 commit 4235e14
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ services:
ports:
- ${RELAYER_1_API_SERVER_HOST:-0.0.0.0}:${RELAYER_1_API_SERVER_PORT:-3000}:${RELAYER_1_API_SERVER_PORT:-3000}
healthcheck:
test: curl --fail http://relayer_1:${RELAYER_1_API_SERVER_PORT:-3000}/healthz
test: echo $$(wget --server-response http://relayer_1:${RELAYER_1_API_SERVER_PORT:-3000}/healthz 2>&1 | grep '200 OK') | grep '200' || exit 1
extra_hosts:
- "host.docker.internal:host-gateway"

Expand Down
3 changes: 1 addition & 2 deletions scripts/lisk/docker/dev/composeStart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ mkdir -p $PWD/.aws
cp $HOME/.aws/credentials $PWD/.aws/
git apply scripts/lisk/docker/dev/docker-compose-dev.patch

aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${AWS_ECR_REGISTRY}
docker compose up --pull always --detach
docker compose up --pull always --build --detach
14 changes: 11 additions & 3 deletions scripts/lisk/docker/dev/docker-compose-dev.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
diff --git a/docker-compose.yml b/docker-compose.yml
index 5c229e7e..c4177aaf 100644
index 33792d2c..556ba0cf 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -21,17 +21,18 @@ services:
@@ -15,23 +15,24 @@ services:
retries: 3

relayer_1:
- image: ${AWS_ECR_REGISTRY}/${AWS_ECR_REPOSITORY}:${ACROSS_RELAYER_IMAGE_TAG}
+ build: .
platform: linux/amd64
depends_on:
redis:
condition: service_healthy
volumes:
- - ./scripts/lisk/docker/${NETWORK:-mainnet}/containerStartBot_1.sh:/home/lisk/across-relayer/scripts/start.sh
+ - ./.aws/credentials:/home/lisk/.aws/credentials
- ./scripts/lisk/docker/${NETWORK:-mainnet}/containerStartBot_1.sh:/home/lisk/across-relayer/scripts/start.sh
+ - ./scripts/lisk/docker/${NETWORK:-sepolia}/containerStartBot_1.sh:/home/lisk/across-relayer/scripts/start.sh
networks:
- across_relayer_network
restart: always
Expand Down
6 changes: 6 additions & 0 deletions scripts/lisk/docker/mainnet/containerStartBot_1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ echo "RPC_PROVIDER_DRPC_1135=$RPC_PROVIDER_DRPC_1135" >> ${env_file}
RPC_PROVIDER_GELATO_1135=`echo $RELAYER_CONFIG | jq -r ."RPC_PROVIDER_GELATO_1135"`
echo "RPC_PROVIDER_GELATO_1135=$RPC_PROVIDER_GELATO_1135" >> ${env_file}

API_SERVER_HOST=`echo $RELAYER_CONFIG | jq -r ."RELAYER_1_API_SERVER_HOST"`
echo "API_SERVER_HOST=$API_SERVER_HOST" >> ${app_dir}/.env

API_SERVER_PORT=`echo $RELAYER_CONFIG | jq -r ."RELAYER_1_API_SERVER_PORT"`
echo "API_SERVER_PORT=$API_SERVER_PORT" >> ${app_dir}/.env

SLACK_CONFIG=`echo $RELAYER_CONFIG | jq -r ."SLACK_CONFIG"`
echo "SLACK_CONFIG=$SLACK_CONFIG" >> ${env_file}

Expand Down
6 changes: 6 additions & 0 deletions scripts/lisk/docker/sepolia/containerStartBot_1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ echo "RPC_PROVIDER_GELATO_4202=$RPC_PROVIDER_GELATO_4202" >> ${env_file}
HUB_CHAIN_ID=`echo $RELAYER_CONFIG | jq -r ."HUB_CHAIN_ID"`
echo "HUB_CHAIN_ID=$HUB_CHAIN_ID" >> ${env_file}

API_SERVER_HOST=`echo $RELAYER_CONFIG | jq -r ."RELAYER_1_API_SERVER_HOST"`
echo "API_SERVER_HOST=$API_SERVER_HOST" >> ${app_dir}/.env

API_SERVER_PORT=`echo $RELAYER_CONFIG | jq -r ."RELAYER_1_API_SERVER_PORT"`
echo "API_SERVER_PORT=$API_SERVER_PORT" >> ${app_dir}/.env

echo "All env vars from secrets are set."

# Set the bot identifier
Expand Down
2 changes: 1 addition & 1 deletion src/api/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dotenv.config();

export function runAPIServer(logger: winston.Logger): void {
const app: Express = express();
const host = process.env.API_SERVER_HOST || "127.0.0.1";
const host = process.env.API_SERVER_HOST || "0.0.0.0";
const port = Number(process.env.API_SERVER_PORT) || 3000;

app.use("/healthz", healthz());
Expand Down

0 comments on commit 4235e14

Please sign in to comment.