Skip to content

Commit

Permalink
scripts: still listen on localhost on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
cfal committed Aug 9, 2023
1 parent 0481ad3 commit 3521ff9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
22 changes: 13 additions & 9 deletions scripts/core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ else
fi
echo "Using core image: ${image_name}"

docker_ip=""
if [ "$(uname)" != "Darwin" ]; then
listen_ips=""
if [ "$(uname)" = "Darwin" ]; then
echo "Listening on all interfaces on MacOS"
listen_ips="0.0.0.0"
else
docker_ip=$(docker network inspect bridge -f '{{range .IPAM.Config}}{{.Gateway}}{{end}}')
if [ -z "${docker_ip}" ]; then
echo "Could not fetch docker ip."
exit 1
fi
echo "Docker IP: ${docker_ip}"
else
echo "Listening on all interfaces on MacOS"
listen_ips="127.0.0.1 ${docker_ip}"
fi

NODE_COUNT="${NODE_COUNT:-4}"
Expand All @@ -68,16 +69,19 @@ for ((i = 1; i <= NODE_COUNT; i++)); do
psql "${host_postgres_url}" -c "DROP DATABASE ${database_name};" &>/dev/null || true
psql "${host_postgres_url}" -c "CREATE DATABASE ${database_name};" &>/dev/null

listen_args=()
for ip in $listen_ips; do
listen_args+=("-p" "${ip}:$((core_base_port + i - 1)):6688")
listen_args+=("-p" "${ip}:$((core_p2p_base_port + i - 1)):6691")
done

echo "Starting core container $i"
docker run \
--rm \
-d \
--add-host=host.docker.internal:host-gateway \
--platform linux/amd64 \
-p 127.0.0.1:$((core_base_port + i - 1)):6688 \
-p 127.0.0.1:$((core_p2p_base_port + i - 1)):6691 \
-p "${docker_ip}:$((core_base_port + i - 1)):6688" \
-p "${docker_ip}:$((core_p2p_base_port + i - 1)):6691" \
"${listen_args[@]}" \
-e "CL_CONFIG=${core_config}" \
-e "CL_DATABASE_URL=postgresql://postgres:[email protected]:5432/${database_name}?sslmode=disable" \
-e 'CL_PASSWORD_KEYSTORE=asdfasdfasdfasdf' \
Expand Down
19 changes: 13 additions & 6 deletions scripts/postgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,28 @@ set -euo pipefail

bash "$(dirname -- "$0")/postgres.down.sh"

docker_ip=""
if [ "$(uname)" != "Darwin" ]; then
listen_ips=""
if [ "$(uname)" = "Darwin" ]; then
echo "Listening on all interfaces on MacOS"
listen_ips="0.0.0.0"
else
docker_ip=$(docker network inspect bridge -f '{{range .IPAM.Config}}{{.Gateway}}{{end}}')
if [ -z "${docker_ip}" ]; then
echo "Could not fetch docker ip."
exit 1
fi
echo "Docker IP: ${docker_ip}"
else
echo "Listening on all interfaces on MacOS"
listen_ips="127.0.0.1 ${docker_ip}"
fi

echo "Starting postgres container"

listen_args=()
for ip in $listen_ips; do
listen_args+=("-p" "${ip}:5432:5432")
done

docker run \
-p "${docker_ip}:5432:5432" \
"${listen_args[@]}" \
-d \
--name "${container_name}" \
-e POSTGRES_USER=postgres \
Expand Down
18 changes: 12 additions & 6 deletions scripts/wasmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,28 @@ set -euo pipefail

bash "$(dirname -- "$0")/wasmd.down.sh"

docker_ip=""
if [ "$(uname)" != "Darwin" ]; then
listen_ips=""
if [ "$(uname)" = "Darwin" ]; then
echo "Listening on all interfaces on MacOS"
listen_ips="0.0.0.0"
else
docker_ip=$(docker network inspect bridge -f '{{range .IPAM.Config}}{{.Gateway}}{{end}}')
if [ -z "${docker_ip}" ]; then
echo "Could not fetch docker ip."
exit 1
fi
echo "Docker IP: ${docker_ip}"
else
echo "Listening on all interfaces on MacOS"
listen_ips="127.0.0.1 ${docker_ip}"
fi

echo "Starting wasmd container"

listen_args=()
for ip in $listen_ips; do
listen_args+=("-p" "${ip}:26657:26657")
done

docker run \
-p "${docker_ip}:26657:26657" \
"${listen_args[@]}" \
-d \
--name "${container_name}" \
"cosmwasm/wasmd:${container_version}" \
Expand Down

0 comments on commit 3521ff9

Please sign in to comment.