Skip to content

Commit

Permalink
Added start/stop mechanism along with comsetic changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
cristure committed Mar 20, 2024
1 parent 96adb1f commit e3cd364
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 37 deletions.
6 changes: 5 additions & 1 deletion scripts/docker-testnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ script is provided. This can be done, by invoking the script or building the ima

```
./build.sh # (Optional) Can be ignored if you already have the images stored in the local registry.
./start.sh # Will start the local-testnet.
./setup.sh # Will setup the local-testnet.
./clean.sh # Will stop and remove the containers related to the local-testnet.
Optionally
./stop.sh # Will stop all the containers in the local-testnet.
./start.sh # Will start all stopped containers from the initial local-testnet.
```
43 changes: 43 additions & 0 deletions scripts/docker-testnet/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

set -eux

export DOCKERTESTNETDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

MULTIVERSXTESTNETSCRIPTSDIR="$(dirname "$DOCKERTESTNETDIR")/testnet"

source "$DOCKERTESTNETDIR/variables.sh"
source "$DOCKERTESTNETDIR/functions.sh"
source "$MULTIVERSXTESTNETSCRIPTSDIR/include/config.sh"
source "$MULTIVERSXTESTNETSCRIPTSDIR/include/build.sh"

cloneRepositories

prepareFolders

buildConfigGenerator

generateConfig

copyConfig

copySeednodeConfig
updateSeednodeConfig

copyNodeConfig
updateNodeConfig

createDockerNetwork

startSeedNode
startObservers
startValidators

if [ $USE_PROXY -eq 1 ]; then
buildProxyImage
prepareFolders_Proxy
copyProxyConfig
updateProxyConfigDocker
startProxyDocker
fi

47 changes: 11 additions & 36 deletions scripts/docker-testnet/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,17 @@

set -eux

export DOCKERTESTNETDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
file_path="./tmp/stopped_containers"

MULTIVERSXTESTNETSCRIPTSDIR="$(dirname "$DOCKERTESTNETDIR")/testnet"

source "$DOCKERTESTNETDIR/variables.sh"
source "$DOCKERTESTNETDIR/functions.sh"
source "$MULTIVERSXTESTNETSCRIPTSDIR/include/config.sh"
source "$MULTIVERSXTESTNETSCRIPTSDIR/include/build.sh"

cloneRepositories

prepareFolders

buildConfigGenerator

generateConfig

copyConfig

copySeednodeConfig
updateSeednodeConfig

copyNodeConfig
updateNodeConfig

createDockerNetwork

startSeedNode
startObservers
startValidators

if [ $USE_PROXY -eq 1 ]; then
buildProxyImage
prepareFolders_Proxy
copyProxyConfig
updateProxyConfigDocker
startProxyDocker
# Check if the file exists
if [ ! -f "$file_path" ]; then
echo "File $file_path not found."
exit 1
fi

# Read the file line by line
while IFS= read -r line; do
docker start $line
done < "$file_path"

rmdir ./tmp
21 changes: 21 additions & 0 deletions scripts/docker-testnet/stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -eux

# Delete the entire testnet folder, which includes configuration, executables and logs.

export MULTIVERSXTESTNETSCRIPTSDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

source "$MULTIVERSXTESTNETSCRIPTSDIR/variables.sh"

# Get the IDs of containers attached to the network
export CONTAINER_IDS=$(docker network inspect -f '{{range $k, $v := .Containers}}{{printf "%s\n" $k}}{{end}}' "$DOCKER_NETWORK_NAME")

mkdir -p ./tmp

# Stop each container
echo "Stopping containers..."
for CONTAINER_ID in $CONTAINER_IDS; do
docker stop "$CONTAINER_ID"
echo "$CONTAINER_ID" >> ./tmp/stopped_containers
done

0 comments on commit e3cd364

Please sign in to comment.