-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathtest_deploy.sh
executable file
·156 lines (113 loc) · 5.1 KB
/
test_deploy.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
# Copyright 2020 DSR Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -euo pipefail
source integration_tests/cli/common.sh
# TODO
# - firewall check: install ufw (might be a part of dockerfile) and configure to allow ledger connections
DCL_USER="dcl"
DCL_USER_HOME="/var/lib/dcl"
DCL_DIR="$DCL_USER_HOME/.dcl"
GENESIS_FILE="$DCL_DIR/config/genesis.json"
GVN_NAME="test_deploy_gvn"
VN_NAME="test_deploy_vn"
CHAIN_ID=dcl_test_deploy
cleanup() {
make test_deploy_env_clean
}
trap cleanup EXIT
function docker_exec {
docker exec -u "$DCL_USER" "$@"
}
test_divider
echo "PROVISIONING"
GOPATH=${GOPATH:-${HOME}/go}
GOBIN=${GOBIN:-${GOPATH}/bin}
mkdir -p "$GOBIN"
docker build -f integration_tests/deploy/Dockerfile-build -t dcl-deploy-build .
docker container create --name dcl-deploy-build-inst dcl-deploy-build
docker cp dcl-deploy-build-inst:/go/bin/dcld "$GOBIN"/
docker cp dcl-deploy-build-inst:/go/bin/cosmovisor "$GOBIN"/
docker rm dcl-deploy-build-inst
make test_deploy_env_build
GVN_IP="$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $GVN_NAME)"
VN_IP="$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $VN_NAME)"
test_divider
echo "CLUSTER NODES PREPARATION"
for node in "$GVN_NAME" "$VN_NAME"; do
echo "$node: install cosmovisor"
docker cp "$GOBIN"/cosmovisor "$node":/usr/bin
# TODO firewall routine (requires ufw installed)
echo "$node: upload release artifacts"
docker cp deployment/cosmovisor.service "$node":"$DCL_USER_HOME"
docker cp "$GOBIN"/dcld "$node":"$DCL_USER_HOME"
docker cp deployment/scripts/run_dcl_node "$node":"$DCL_USER_HOME"
docker cp deployment/scripts/test_peers_conn "$node":"$DCL_USER_HOME"
docker_exec "$node" ./dcld version
echo "$node: init"
docker_exec "$node" bash -c "./dcld init $node --chain-id $CHAIN_ID 2>init.stderr"
echo "$node: Create NodeAdmin and Trustee keys"
docker_exec "$node" ./dcld config keyring-backend test
docker_exec "$node" ./dcld keys add "${node}_admin"
docker_exec "$node" ./dcld keys add "${node}_tr"
done
echo "Generating persistent peers list"
GVN_ID="$(docker_exec "$GVN_NAME" grep -o 'node_id.*$' init.stderr | awk -F'"' '{print $3}')"
VN_ID="$(docker_exec "$VN_NAME" grep -o 'node_id.*$' init.stderr | awk -F'"' '{print $3}')"
PERSISTENT_PEERS="$GVN_ID@$GVN_IP:26656,$VN_ID@$VN_IP:26656"
for node in "$GVN_NAME" "$VN_NAME"; do
docker_exec "$node" bash -c "echo '$PERSISTENT_PEERS' >persistent_peers.txt"
done
test_divider
echo "GENESIS NODE RUN"
docker_exec -e KEYRING_BACKEND=test "$GVN_NAME" \
./run_dcl_node -t genesis -c "$CHAIN_ID" \
--gen-key-name "${GVN_NAME}_admin" --gen-key-name-trustee "${GVN_NAME}_tr" \
"$GVN_NAME"
docker_exec "$GVN_NAME" systemctl status cosmovisor
# we should be fine with shell limits here
genesis_data="$(docker_exec "$GVN_NAME" cat "$GENESIS_FILE")"
test_divider
echo "VALIDATOR NODE RUN"
echo "VN: Set genesis data"
docker_exec "$VN_NAME" bash -c "echo '$genesis_data' >genesis.json"
echo "VN: Verify connections to other nodes"
docker_exec "$VN_NAME" ./test_peers_conn
echo "VN: run"
docker_exec -e KEYRING_BACKEND=test "$VN_NAME" ./run_dcl_node -c "$CHAIN_ID" "$VN_NAME"
docker_exec "$VN_NAME" systemctl status cosmovisor
test_divider
echo "VALIDATOR NODE REGISTRATION"
echo "$GVN_NAME: approve \"$VN_NAME\" to validator set"
vn_addr=$(docker_exec "$VN_NAME" ./dcld tendermint show-address)
vn_pubkey=$(docker_exec "$VN_NAME" ./dcld tendermint show-validator)
vn_admin_name="${VN_NAME}_admin"
vn_admin_addr="$(docker_exec "$VN_NAME" ./dcld keys show "$vn_admin_name" -a)"
vn_admin_pubkey="$(docker_exec "$VN_NAME" ./dcld keys show "$vn_admin_name" -p)"
# ensure that the genesis node is ready
wait_for_height 2 15 normal "tcp://$GVN_IP:26657"
result="$(docker_exec "$GVN_NAME" ./dcld tx auth propose-add-account --address "$vn_admin_addr" --pubkey "$vn_admin_pubkey" --roles="NodeAdmin" --from "${GVN_NAME}_tr" --yes)"
result=$(get_txn_result "$result")
#dcld tx auth approve-add-account --address="$vn_admin_addr" --from alice --yes
echo "$GVN_NAME: Add Node \"$VN_NAME\" to validator set"
# ensure that the validator node is ready
wait_for_height 4 30 normal "tcp://$VN_IP:26657"
result="$(docker_exec "$VN_NAME" ./dcld tx validator add-node --pubkey="$vn_pubkey" --moniker="$VN_NAME" --from="$vn_admin_name" --yes)"
result=$(get_txn_result "$result")
sleep 10
echo "Check node \"$VN_NAME\" is in the validator set"
result=$(docker_exec "$GVN_NAME" ./dcld query validator all-nodes)
check_response "$result" "\"moniker\": \"$VN_NAME\""
check_response "$result" "\"pubKey\":$vn_pubkey" raw
echo "PASSED"