Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
feat(test): use dynamic docker port (#517)
Browse files Browse the repository at this point in the history
Co-authored-by: David <[email protected]>
  • Loading branch information
mask-pp and davidtaikocha authored Jan 19, 2024
1 parent 73a6047 commit 430abd6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
34 changes: 27 additions & 7 deletions internal/docker/docker_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
9 changes: 4 additions & 5 deletions internal/docker/nodes/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ services:
restart: unless-stopped
pull_policy: always
ports:
- "18545:8545"
- "18546:8545"
- "8545"
entrypoint:
- anvil
- --host
Expand All @@ -22,9 +21,9 @@ services:
volumes:
- .:/host
ports:
- "28545:8545"
- "28546:8546"
- "28551:8551"
- "8545"
- "8546"
- "8551"
command:
- --nodiscover
- --gcmode
Expand Down
8 changes: 2 additions & 6 deletions internal/docker/start.sh
Original file line number Diff line number Diff line change
@@ -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}}"
4 changes: 2 additions & 2 deletions internal/docker/stop.sh
Original file line number Diff line number Diff line change
@@ -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[*]}"

Expand Down

0 comments on commit 430abd6

Please sign in to comment.