diff --git a/docker-compose/docker-compose.yml b/docker-compose/docker-compose.yml new file mode 100644 index 00000000..2cc1a1c3 --- /dev/null +++ b/docker-compose/docker-compose.yml @@ -0,0 +1,10 @@ +version: "3" +name: pybitmessage +services: + bootstrap: + image: pybitmessage/bootstrap:latest + build: .. + ports: + - 127.0.0.1::8444 + deploy: + replicas: $THREADS diff --git a/docker-compose/start-loadbalancer.sh b/docker-compose/start-loadbalancer.sh new file mode 100755 index 00000000..7e763076 --- /dev/null +++ b/docker-compose/start-loadbalancer.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +apt -y install curl jq ipvsadm + +EXTIP=$(curl -s telnetmyip.com|jq -r .ip) +THREADS=$(nproc --all) +echo "THREADS=$THREADS" > .env + +ipvsadm -C +ipvsadm -A -t ${EXTIP}:8444 -s rr +ipvsadm -A -t ${EXTIP}:8080 -s rr + +docker compose up -d + +for i in `seq 1 $THREADS`; do + cont="pybitmessage-bootstrap-${i}" + IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $cont 2>/dev/null) + [ -z "$IP" ] && continue + echo "Adding $IP" + ipvsadm -a -t ${EXTIP}:8444 -r ${IP}:8444 -m + ipvsadm -a -t ${EXTIP}:8080 -r ${IP}:8444 -m +done + +ipvsadm -l diff --git a/packages/docker/launcher.sh b/packages/docker/launcher.sh index c0e48855..1a876fec 100755 --- a/packages/docker/launcher.sh +++ b/packages/docker/launcher.sh @@ -3,13 +3,15 @@ # Setup the environment for docker container APIUSER=${USER:-api} APIPASS=${PASSWORD:-$(tr -dc a-zA-Z0-9 < /dev/urandom | head -c32 && echo)} +IP=$(hostname -i) echo "\napiusername: $APIUSER\napipassword: $APIPASS" -sed -i -e "s|\(apiinterface = \).*|\10\.0\.0\.0|g" \ +sed -i -e "s|\(apiinterface = \).*|\1$IP|g" \ -e "s|\(apivariant = \).*|\1json|g" \ -e "s|\(apiusername = \).*|\1$APIUSER|g" \ -e "s|\(apipassword = \).*|\1$APIPASS|g" \ + -e "s|\(bind = \).*|\1$IP|g" \ -e "s|apinotifypath = .*||g" ${BITMESSAGE_HOME}/keys.dat # Run