Pārlūkot izejas kodu

cleanup after running scripts

Mokhtar Naamani 4 gadi atpakaļ
vecāks
revīzija
861fa1b533
2 mainītis faili ar 28 papildinājumiem un 9 dzēšanām
  1. 12 3
      storage-node/start-dev.sh
  2. 16 6
      tests/network-tests/run-tests.sh

+ 12 - 3
storage-node/start-dev.sh

@@ -3,21 +3,30 @@ set -e
 
 # Avoid pulling joystream/node from docker hub. It is most likely
 # not the version that we want to work with. Either you should
-# build it locally or pull it down manually if you that is what you want
+# build it locally or pull it down manually.
 if ! docker inspect joystream/node:latest > /dev/null 2>&1;
 then
   echo "Didn't find local joystream/node:latest docker image."
   exit 1
 fi
 
-# SCRIPT_PATH="$(dirname "${BASH_SOURCE[0]}")"
+SCRIPT_PATH="$(dirname "${BASH_SOURCE[0]}")"
+cd $SCRIPT_PATH
 
 # stop prior run and clear volumes
-docker-compose down -v
+# docker-compose down -v
 
 # Run a development joystream-node chain and ipfs daemon in the background
 docker-compose up -d
 
+function down()
+{
+    # Stop containers and clear volumes
+    docker-compose down -v
+}
+
+trap down EXIT
+
 # configure the dev chain
 DEBUG=joystream:storage-cli:dev yarn storage-cli dev-init
 

+ 16 - 6
tests/network-tests/run-tests.sh

@@ -1,6 +1,14 @@
 #!/usr/bin/env bash
 set -e
 
+function cleanup()
+{
+    docker stop ${CONTAINER_ID}
+    docker rm ${CONTAINER_ID}
+}
+
+trap cleanup EXIT
+
 # Location that will be mounted as the /data volume in containers
 # This is how we access the initial members and balances files from
 # the containers and where generated chainspec files will be located.
@@ -30,7 +38,7 @@ echo '
 ' > ${DATA_PATH}/initial-members.json
 
 # Create a chain spec file
-docker run -v ${DATA_PATH}:/data --entrypoint ./chain-spec-builder joystream/node \
+docker run --rm -v ${DATA_PATH}:/data --entrypoint ./chain-spec-builder joystream/node \
   new \
   --authority-seeds Alice \
   --sudo-account  5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY \
@@ -40,14 +48,16 @@ docker run -v ${DATA_PATH}:/data --entrypoint ./chain-spec-builder joystream/nod
   --initial-members-path /data/initial-members.json
 
 # Convert the chain spec file to a raw chainspec file
-docker run -v ${DATA_PATH}:/data joystream/node build-spec \
+docker run --rm -v ${DATA_PATH}:/data joystream/node build-spec \
   --raw --disable-default-bootnode \
   --chain /data/chain-spec.json > ~/tmp/chain-spec-raw.json
 
 # Start a chain with generated chain spec
-docker run -v ${DATA_PATH}:/data -d -p 9944:9944 joystream/node \
+CONTAINER_ID=`docker run -d -v ${DATA_PATH}:/data -p 9944:9944 joystream/node \
   --validator --alice --unsafe-ws-external --rpc-cors=all --log runtime \
-  --chain /data/chain-spec-raw.json
+  --chain /data/chain-spec-raw.json`
+
+# Execute the tests then stop the container
+yarn workspace network-tests test || echo "Failed Running Tests"
 
-# Execute the tests
-yarn workspace network-tests test
+cleanup()