-
Notifications
You must be signed in to change notification settings - Fork 0
/
augmint-cli.sh
executable file
·95 lines (73 loc) · 3.2 KB
/
augmint-cli.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env bash
CONTRACTS_VERSION=`yarn list --pattern @augmint/contracts --depth=0 -s` # output: └─ @augmint/[email protected]
DOCKER_IMAGE="augmint/contracts:v${CONTRACTS_VERSION##*@}"
CONTAINER_NAME=ganache
echo ""
echo "augmint-cli : start / stop augmint contracts. Docker image: $DOCKER_IMAGE"
echo ""
if ! [ -x "$(command -v docker)" ] ; then
echo 'Error: docker is not installed.' >&2
exit 1
fi
function run_ganache {
docker run --init --detach --name $CONTAINER_NAME -p 8545:8545 $DOCKER_IMAGE --db ./dockerLocalchaindb \
--gasLimit 0x47D5DE --gasPrice 1000000000 --networkId 999 --noVMErrorsOnRPCResponse $ADDITIONAL_GANACHE_LAUNCH_FLAGS \
-m "hello build tongue rack parade express shine salute glare rate spice stock"
}
function stop_container_if_running {
if [ "$(docker ps --quiet --filter name=^/$CONTAINER_NAME$)" ]; then
echo "Container '$CONTAINER_NAME' is running. Stopping."
docker stop $CONTAINER_NAME
fi
}
function remove_container_if_image_mismatched {
existingImage=$(docker ps --quiet -all --format "{{.Image}}" --filter name=^/$CONTAINER_NAME$)
if [ "$existingImage" != "" -a "$existingImage" != "$DOCKER_IMAGE" ]; then
echo "WARNING: ganache docker container image mismatch."
echo " There is already a docker container named '$CONTAINER_NAME' using image $existingImage."
echo " expected image is $DOCKER_IMAGE for current augmint.js version."
echo " It's likely because of an augmint-js upgrade since last local run of container. Removing existing $CONTAINER_NAME container."
stop_container_if_running
docker rm $CONTAINER_NAME
fi
}
function print_instructions {
echo " Usage: $0 ganache {start | stop | run} [<additional ganache launch flags. eg. --blockTime 1>]"
echo " start: tries to start container named $CONTAINER_NAME . If fails then runs (downloads, creates and starts) the container from $DOCKER_IMAGE"
echo " stop: plain docker stop $DOCKER_IMAGE (doesn't check if exists)"
echo " run: stops and removes the $CONTAINER_NAME container if exists. then runs it "
}
case "$1" in
ganache )
ADDITIONAL_GANACHE_LAUNCH_FLAGS=${@:3}
case "$2" in
run )
remove_container_if_image_mismatched
stop_container_if_running
if [ "$(docker ps --quiet -all --filter name=^/$CONTAINER_NAME$)" ]; then
echo "Container '$CONTAINER_NAME' exists. Removing before run."
docker rm $CONTAINER_NAME
fi
run_ganache
;;
start )
remove_container_if_image_mismatched
if [ "$(docker ps --quiet -all --filter name=^/$CONTAINER_NAME$)" ]; then
docker start $CONTAINER_NAME
else
echo "Container '$CONTAINER_NAME' doesn't exist. Using docker run to create and start."
run_ganache
fi
;;
stop )
docker stop ganache
;;
* )
print_instructions
;;
esac
;;
*)
print_instructions
;;
esac