-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabric-k8s.sh
executable file
·291 lines (255 loc) · 7.27 KB
/
fabric-k8s.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#!/bin/bash
export SLA_CHANNEL_NAME=sla
export VRU_CHANNEL_NAME=vru
export PARTS_CHANNEL_NAME=parts
export SLA2_CHANNEL_NAME=sla2.0
export SLA_CHAINCODE_NAME=slasc-bridge
export VRU_CHAINCODE_NAME=vru-positions
export PARTS_CHAINCODE_NAME=parts
export SLA_CC_SRC_PATH="${PWD}/ccas_sla"
export VRU_CC_SRC_PATH="${PWD}/ccas_vru"
export PARTS_CC_SRC_PATH="${PWD}/ccas_parts"
export PLEDGER_NETWORK_CONTAINER_REGISTRY_PORT=443
export PLEDGER_NETWORK_CONTAINER_REGISTRY_HOSTNAME=147.102.19.6
export PLEDGER_NETWORK_CONTAINER_REGISTRY_ADDRESS=$PLEDGER_NETWORK_CONTAINER_REGISTRY_HOSTNAME/pledger
export PLEDGER_NETWORK_NO_VOLUMES=0
export SKIP_SLA1=0
export SKIP_SLA2=0
export SELF_SIGNED_REGISTRY=0
export SKIP_DNS=0
export RANDOM_TAG=0
export REGISTRY=${PLEDGER_NETWORK_CONTAINER_REGISTRY_ADDRESS}
export PUSH=1
export HOST_PATH=${HOME}
function login() {
./network-k8s.sh docker login
}
function build() {
./network-k8s.sh docker build "$REGISTRY" "$PUSH"
}
function init() {
if [ "${RUNTIME}" == "kind" ]; then
./network-k8s.sh kind
fi
if [ "${RUNTIME}" == "minikube" ]; then
if [ "$(docker ps | grep -c minikube)" == 0 ]; then
minikube start
fi
fi
./network-k8s.sh cluster init
}
function destroy() {
./network-k8s.sh cluster clean
if [ "${RUNTIME}" == "kind" ]; then
./network-k8s.sh unkind
fi
}
function up() {
./network-k8s.sh cas
./network-k8s.sh channel init
./network-k8s.sh up
}
function down() {
./network-k8s.sh down
}
function set_channels() {
if [ $SKIP_SLA1 -eq 0 ]; then
./network-k8s.sh channel create "$SLA_CHANNEL_NAME" 1
fi
./network-k8s.sh channel create "$VRU_CHANNEL_NAME" 2
./network-k8s.sh channel create "$PARTS_CHANNEL_NAME" 3
if [ $SKIP_SLA2 -eq 0 ]; then
./network-k8s.sh channel create "$SLA2_CHANNEL_NAME" 4
fi
}
function deploy_chaincodes() {
if [ $SKIP_SLA1 -eq 0 ]; then
export CHANNEL_NAME=${SLA_CHANNEL_NAME}
./network-k8s.sh chaincode deploy 1 $SLA_CHAINCODE_NAME "$SLA_CC_SRC_PATH"
fi
export CHANNEL_NAME=${VRU_CHANNEL_NAME}
./network-k8s.sh chaincode deploy 2 $VRU_CHAINCODE_NAME "$VRU_CC_SRC_PATH"
export CHANNEL_NAME=${PARTS_CHANNEL_NAME}
./network-k8s.sh chaincode deploy 3 $PARTS_CHAINCODE_NAME "$PARTS_CC_SRC_PATH"
}
function init_application_config() {
./network-k8s.sh application init
}
function identity_management() {
./network-k8s.sh application identity_management
}
function sla_client() {
./network-k8s.sh application sla
}
function vru_client() {
./network-k8s.sh application vru
}
function parts_client() {
./network-k8s.sh application parts
}
function sla2_client() {
./network-k8s.sh application sla2
}
function api() {
./network-k8s.sh application api
}
function explorer() {
./network-k8s.sh application explorer
}
function applications() {
init_application_config
if [ $SKIP_SLA1 -eq 0 ]; then
sla_client
fi
vru_client
parts_client
if [ $SKIP_SLA2 -eq 0 ]; then
sla2_client
fi
identity_management
api
explorer
}
function print_help() {
echo "USAGE:"
echo "$0 RUNTIME COMMAND [ARGUMENTS]"
echo ""
echo "TESTED RUNTIMES (mileage may vary):"
echo " kind: Kubernetes-in-Docker cluster"
echo " microk8s: Microk8s cluster"
echo " minikube"
echo ""
echo "COMMAND:"
echo " build: Build all docker images"
echo " deploy: Bring up the chaincodes and the clients"
echo " destroy: Bring down the cluster"
echo " down: Bring down all the peers, CAs and all the other members of the channels"
echo " init: Set up the the cluster, the ingress and cert-manager"
echo " login: Login to the container registry. See README for more info"
echo " up: Bring up all the peers, CAs and orderers of the network, as well as the channels"
echo ""
echo "ARGUMENTS:"
echo " --self-signed-registry: Upload self-signed registry credentials to cluster"
echo " --skip-sla-1: Skip the deployment of the SLAv1 channel, chaincode and client"
echo " --skip-sla-2: Skip the deployment of the SLAv2 channel and client"
echo " --no-volumes: Do not create volumes for storage"
echo " --no-push: Used only with *build*. Do not push images to registry."
echo " --registry: Set a registry/path for the images (useful also when pushing)"
echo " --random-tag: Set a random tag for images - to avoid a bug where microk8s pulls an earlier image with the same tag"
echo " --add-metrics-server: Skips installing the metrics server"
}
## Parse mode
if [[ $# -lt 2 ]]; then
print_help "$@"
exit 0
else
RUNTIME=$1
MODE=$2
shift 2
fi
if [[ $# -ge 1 ]]; then
while [ $# -gt 0 ]; do
FLAG=$1
case $FLAG in
--no-volumes)
export PLEDGER_NETWORK_NO_VOLUMES=1
shift
;;
--self-signed-registry)
export SELF_SIGNED_REGISTRY=1
shift
;;
--skip-sla-1)
export SKIP_SLA1=1
shift
;;
--skip-sla-2)
export SKIP_SLA2=1
shift
;;
--registry)
export REGISTRY=$2
shift 2
;;
--no-push)
export PUSH=0
shift
;;
--skip-dns)
export SKIP_DNS=1
shift
;;
--random-tag)
export RANDOM_TAG=1
shift
;;
--with-metrics-server)
export WITH_METRICS_SERVER=1
shift
;;
*)
print_help
exit 0
;;
esac
done
fi
if [ "${RUNTIME}" == "kind" ]; then
kubectl config use-context kind-kind
export PLEDGER_NETWORK_CLUSTER_RUNTIME=kind
export PLEDGER_NETWORK_CLUSTER_NAME=kind
export PLEDGER_NETWORK_NGINX_HTTP_PORT=8080
export PLEDGER_NETWORK_NGINX_HTTPS_PORT=8443
elif [ "${RUNTIME}" == "microk8s" ]; then
kubectl config use-context microk8s
export PLEDGER_NETWORK_CLUSTER_RUNTIME=microk8s
export PLEDGER_NETWORK_CLUSTER_NAME=microk8s
export PLEDGER_NETWORK_NGINX_HTTP_PORT=8080
export PLEDGER_NETWORK_NGINX_HTTPS_PORT=8443
elif [ "${RUNTIME}" == "minikube" ]; then
kubectl config use-context minikube
export PLEDGER_NETWORK_CLUSTER_RUNTIME=minikube
export PLEDGER_NETWORK_CLUSTER_NAME=minikube
export PLEDGER_NETWORK_NGINX_HTTP_PORT=8080
export PLEDGER_NETWORK_NGINX_HTTPS_PORT=8443
else
print_help
exit 1
fi
if [ "${MODE}" == "init" ]; then
init
elif [ "${MODE}" == "destroy" ]; then
destroy
elif [ "${MODE}" == "up" ]; then
up
elif [ "${MODE}" == "channels" ]; then
set_channels
elif [ "${MODE}" == "login" ]; then
login
elif [ "${MODE}" == "build" ]; then
build
elif [ "${MODE}" == "chaincodes" ]; then
deploy_chaincodes
elif [ "${MODE}" == "applications" ]; then
applications
elif [ "${MODE}" == "explorer" ]; then
explorer
elif [ "${MODE}" == "api" ]; then
api
elif [ "${MODE}" == "sla2" ]; then
sla2_client
elif [ "${MODE}" == "down" ]; then
down
elif [ "${MODE}" == "full" ]; then
down
destroy
init
up
set_channels
login
deploy_chaincodes
applications
else
print_help
exit 1
fi