Skip to content

Commit

Permalink
Feature/improve run iroha dev (hyperledger-iroha#1115)
Browse files Browse the repository at this point in the history
PR hyperledger-iroha#1115 changes the behavior of run-iroha-dev.sh and introduces stop-iroha-dev.sh.

Changes:
- Each user within a system can run own docker container
- Introduced script for full shutdown of container environment - stop-iroha-dev.sh
- Now it is possible to reenter into the container without its recreation
- run-iroha-dev.sh reports ports used on the host system for Iroha and debugger

 run-iroha-dev.sh now automatically picks first free port from
  range 50051-50101 on host system for Iroha and free port from
  range 20000-20100 on the host system for Debugger

Signed-off-by: Igor Egorov <[email protected]>
  • Loading branch information
igor-egorov authored and x3medima17 committed Mar 30, 2018
1 parent c609cac commit ab26677
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ services:
node:
image: hyperledger/iroha-docker-develop:v1
ports:
- "50051:50051"
- "20000:20000"
- "${IROHA_PORT}:50051"
- "${DEBUGGER_PORT}:20000"
environment:
- IROHA_POSTGRES_HOST=${COMPOSE_PROJECT_NAME}_postgres_1
- IROHA_POSTGRES_PORT=5432
Expand Down
25 changes: 23 additions & 2 deletions scripts/run-iroha-dev.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
#!/bin/bash

function next_free_port {
for port in $(seq $1 $2);
do echo -ne "\035" | nc 127.0.0.1 $port > /dev/null 2>&1; [ $? -eq 1 ] && echo "$port" && break;
done
}

CURDIR="$(cd "$(dirname "$0")"; pwd)"
IROHA_HOME="$(dirname "${CURDIR}")"
PROJECT=iroha${USERID}
PROJECT=iroha${UID}
COMPOSE=${IROHA_HOME}/docker/docker-compose.yml

export G_ID=$(id -g)
export U_ID=$(id -u)
export COMPOSE_PROJECT_NAME=${PROJECT}

docker-compose -f ${COMPOSE} up -d
if [ $(docker ps -q -f name=${PROJECT}_node_1 | wc -c) -eq 0 ];
then
export IROHA_PORT="$(next_free_port 50051 50101)"
export DEBUGGER_PORT="$(next_free_port 20000 20100)"

docker-compose -f ${COMPOSE} up -d
else
IROHA_DBG_PORTS="$(docker port ${PROJECT}_node_1 | sed 's/\(.*\)://' | sort -r | sed -e :a -e N -e 's/\n/:/p' -e ta)"
export IROHA_PORT="$(echo ${IROHA_DBG_PORTS} | sed 's/:.*//')"
export DEBUGGER_PORT="$(echo ${IROHA_DBG_PORTS} | sed 's/.*://')"
fi
echo ""
echo "Iroha is mapped to host port ${IROHA_PORT}"
echo "Debugger is mapped to host port ${DEBUGGER_PORT}"
echo ""
docker-compose -f ${COMPOSE} exec node /bin/bash
11 changes: 11 additions & 0 deletions scripts/stop-iroha-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
CURDIR="$(cd "$(dirname "$0")"; pwd)"
IROHA_HOME="$(dirname "${CURDIR}")"
PROJECT=iroha${UID}
COMPOSE=${IROHA_HOME}/docker/docker-compose.yml

# actual values of are not needed here, but variables need to be defined
export IROHA_PORT=1
export DEBUGGER_PORT=2

docker-compose -f ${COMPOSE} -p ${PROJECT} down

0 comments on commit ab26677

Please sign in to comment.