From 430abd6deed8117b2287183a662276607adb50b9 Mon Sep 17 00:00:00 2001 From: maskpp Date: Fri, 19 Jan 2024 22:00:49 +0800 Subject: [PATCH] feat(test): use dynamic docker port (#517) Co-authored-by: David --- internal/docker/docker_env.sh | 34 +++++++++++++++++++----- internal/docker/nodes/docker-compose.yml | 9 +++---- internal/docker/start.sh | 8 ++---- internal/docker/stop.sh | 4 +-- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/internal/docker/docker_env.sh b/internal/docker/docker_env.sh index 880c5ecc5..2c52a0894 100755 --- a/internal/docker/docker_env.sh +++ b/internal/docker/docker_env.sh @@ -2,13 +2,33 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -export L1_NODE_HTTP_ENDPOINT=http://localhost:18545 -export L1_NODE_WS_ENDPOINT=ws://localhost:18546 -export L1_EXECUTION_ENGINE_AUTH_ENDPOINT=http://localhost:18551 +# check until L1 chain is ready +L1_PROBE_URL=http://localhost:$(docker port l1_node | grep '0.0.0.0' | awk -F ':' '{print $2}') +until cast chain-id --rpc-url "$L1_PROBE_URL" 2> /dev/null; do + sleep 1 +done -export L2_EXECUTION_ENGINE_HTTP_ENDPOINT=http://localhost:28545 -export L2_EXECUTION_ENGINE_WS_ENDPOINT=ws://localhost:28546 -export L2_EXECUTION_ENGINE_AUTH_ENDPOINT=http://localhost:28551 +# check until L2 chain is ready +L2_PROBE_URL=http://localhost:$(docker port l2_node | grep "0.0.0.0" | awk -F ':' 'NR==1 {print $2}') +until cast chain-id --rpc-url "$L2_PROBE_URL" 2> /dev/null; do + sleep 1 +done + + +L1_NODE_PORT=$(docker port l1_node | grep '0.0.0.0' | awk -F ':' '{print $2}') +export L1_NODE_HTTP_ENDPOINT=http://localhost:$L1_NODE_PORT +export L1_NODE_WS_ENDPOINT=ws://localhost:$L1_NODE_PORT + +export L2_EXECUTION_ENGINE_HTTP_ENDPOINT=http://localhost:$(docker port l2_node | grep "0.0.0.0" | awk -F ':' 'NR==1 {print $2}') +export L2_EXECUTION_ENGINE_WS_ENDPOINT=ws://localhost:$(docker port l2_node | grep "0.0.0.0" | awk -F ':' 'NR==2 {print $2}') +export L2_EXECUTION_ENGINE_AUTH_ENDPOINT=http://localhost:$(docker port l2_node | grep "0.0.0.0" | awk -F ':' 'NR==3 {print $2}') export JWT_SECRET=$DIR/nodes/jwt.hex -export DOCKER_SERVICE_LIST=("l1_node" "l2_execution_engine") +echo -e "L1_NODE PORTS: \n$(docker port l1_node)" +echo -e "L2_NODE PORTS: \n$(docker port l2_node)" + +echo "L1_NODE_HTTP_ENDPOINT: $L1_NODE_HTTP_ENDPOINT" +echo "L1_NODE_WS_ENDPOINT: $L1_NODE_WS_ENDPOINT" +echo "L2_EXECUTION_ENGINE_HTTP_ENDPOINT: $L2_EXECUTION_ENGINE_HTTP_ENDPOINT" +echo "L2_EXECUTION_ENGINE_WS_ENDPOINT: $L2_EXECUTION_ENGINE_WS_ENDPOINT" +echo "L2_EXECUTION_ENGINE_AUTH_ENDPOINT: $L2_EXECUTION_ENGINE_AUTH_ENDPOINT" \ No newline at end of file diff --git a/internal/docker/nodes/docker-compose.yml b/internal/docker/nodes/docker-compose.yml index c22036495..f809e19ed 100644 --- a/internal/docker/nodes/docker-compose.yml +++ b/internal/docker/nodes/docker-compose.yml @@ -7,8 +7,7 @@ services: restart: unless-stopped pull_policy: always ports: - - "18545:8545" - - "18546:8545" + - "8545" entrypoint: - anvil - --host @@ -22,9 +21,9 @@ services: volumes: - .:/host ports: - - "28545:8545" - - "28546:8546" - - "28551:8551" + - "8545" + - "8546" + - "8551" command: - --nodiscover - --gcmode diff --git a/internal/docker/start.sh b/internal/docker/start.sh index 641bf3667..cde4a56a2 100755 --- a/internal/docker/start.sh +++ b/internal/docker/start.sh @@ -1,18 +1,14 @@ #!/bin/bash source scripts/common.sh -source internal/docker/docker_env.sh + +DOCKER_SERVICE_LIST=("l1_node" "l2_execution_engine") # start docker compose service list echo "start docker compose service: ${DOCKER_SERVICE_LIST[*]}" compose_up "${DOCKER_SERVICE_LIST[@]}" -# check until L1 chain is ready -until cast chain-id --rpc-url "$L2_EXECUTION_ENGINE_HTTP_ENDPOINT"; do - sleep 1 -done - # show all the running containers echo docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}\t{{.Status}}" diff --git a/internal/docker/stop.sh b/internal/docker/stop.sh index 0bb580635..0a69ade32 100755 --- a/internal/docker/stop.sh +++ b/internal/docker/stop.sh @@ -1,8 +1,8 @@ #!/bin/bash - source scripts/common.sh -source internal/docker/docker_env.sh + +DOCKER_SERVICE_LIST=("l1_node" "l2_execution_engine") echo "stop docker compose service: ${DOCKER_SERVICE_LIST[*]}"