forked from feitnomore/hyperledger-fabric-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 13
/
install.yml
235 lines (188 loc) · 16.8 KB
/
install.yml
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
---
- hosts: localhost
connection: local
vars:
project_name: "myproject"
username: "myuser"
password: "mypass"
master_url: "https://master.example.com"
tasks:
- name: login as {{ username }} (must be cluster-admin)
shell: "oc login -u {{ username }} -p {{ password }} {{ master_url }}"
- name: Create project {{ project_name }}
shell: "oc new-project {{ project_name }}"
register: project_result
failed_when: "'AlreadyExists' not in project_result.stderr and project_result.rc != 0"
- name: Add permissions
shell: "oc adm policy add-scc-to-user {{ item }} -z default -n {{ project_name }}"
with_items:
- anyuid
- privileged
- name: Create pvc
shell: "oc apply -f kubernetes/fabric-pvc-nolabel.yaml -n {{ project_name }}"
- name: Create Fabric Tools Helper
shell: "oc apply -f kubernetes/fabric-tools.yaml -n {{ project_name }}"
- name: Wait fabric container to be running
shell: "oc get po -n {{ project_name }} | grep -i fabric"
register: fabric_container
until: fabric_container.stdout.find("Running") != -1
retries: 60
delay: 20
- name: Create fabric tools dirs
shell: "oc -n {{ project_name }} exec -it fabric-tools -- mkdir -p /fabric/config"
- name: Copy files to fabric tools containers
shell: "oc -n {{ project_name }} cp {{ item }} fabric-tools:/fabric/config/"
with_items:
- config/configtx.yaml
- config/crypto-config.yaml
- config/chaincode/
- instantiate_chaincode.sh
ignore_errors: true
- name: Cryptogen
shell: oc -n "{{ project_name }}" exec fabric-tools -- bash -c "cryptogen generate --config /fabric/config/crypto-config.yaml"
- name: Copy files 1
shell: oc -n "{{ project_name }}" exec fabric-tools -- cp -r crypto-config /fabric/
- name: Copy files 2
shell: oc -n "{{ project_name }}" exec fabric-tools -- bash -c 'for file in $(find /fabric/ -iname *_sk); do echo $file; dir=$(dirname $file); mv ${dir}/*_sk ${dir}/key.pem; done'
- name: Generate genesis block
shell: oc -n "{{ project_name }}" exec fabric-tools -- bash -c "cp /fabric/config/configtx.yaml /fabric/ && cd /fabric && configtxgen -profile FourOrgsOrdererGenesis -outputBlock genesis.block"
- name: Create Anchor Peers
shell: oc -n "{{ project_name }}" exec fabric-tools -- bash -c "{{ item }}"
with_items:
- "cd /fabric && configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./Org1MSPanchors.tx -channelID channel1 -asOrg Org1MSP"
- "cd /fabric && configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./Org2MSPanchors.tx -channelID channel1 -asOrg Org2MSP"
- "cd /fabric && configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./Org3MSPanchors.tx -channelID channel1 -asOrg Org3MSP"
- "cd /fabric && configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./Org4MSPanchors.tx -channelID channel1 -asOrg Org4MSP"
- name: Fix permissions
shell: oc -n "{{ project_name }}" exec fabric-tools -- bash -c "chmod a+rx /fabric/* -R"
- name: Create Blockchain-ca deploy
shell: oc -n "{{ project_name }}" apply -f kubernetes/blockchain-ca_deploy.yaml
- name: Create service deploy
shell: oc -n "{{ project_name }}" apply -f kubernetes/blockchain-ca_svc.yaml
- name: Install zookeeper and kafka
shell: "oc apply -f kafka -n {{ project_name }}"
- name: Create Orderer
shell: "oc -n {{ project_name }} apply -f kubernetes/blockchain-orderer_deploy.yaml"
- name: Create orderer svc
shell: "oc expose deployment blockchain-orderer --port=31010 -n {{ project_name }} || echo 'já existe'"
- name: Create org1 and peer
shell: oc -n "{{ project_name }}" apply -f "{{ item }}"
with_items:
- kubernetes/blockchain-org1peer1_deploy.yaml
- kubernetes/blockchain-org1peer2_deploy.yaml
- kubernetes/blockchain-org1peer1_svc.yaml
- kubernetes/blockchain-org1peer2_svc.yaml
- name: Create org2 and peer
shell: oc -n "{{ project_name }}" apply -f "{{ item }}"
with_items:
- kubernetes/blockchain-org2peer1_deploy.yaml
- kubernetes/blockchain-org2peer2_deploy.yaml
- kubernetes/blockchain-org2peer1_svc.yaml
- kubernetes/blockchain-org2peer2_svc.yaml
- name: Create org3 and peer
shell: oc -n "{{ project_name }}" apply -f "{{ item }}"
with_items:
- kubernetes/blockchain-org3peer1_deploy.yaml
- kubernetes/blockchain-org3peer2_deploy.yaml
- kubernetes/blockchain-org3peer1_svc.yaml
- kubernetes/blockchain-org3peer2_svc.yaml
- name: Create org4 and peer
shell: oc -n "{{ project_name }}" apply -f "{{ item }}"
with_items:
- kubernetes/blockchain-org4peer1_deploy.yaml
- kubernetes/blockchain-org4peer2_deploy.yaml
- kubernetes/blockchain-org4peer1_svc.yaml
- kubernetes/blockchain-org4peer2_svc.yaml
- name: Create channel
shell: >
oc -n "{{ project_name }}" exec fabric-tools -- bash -c 'export FABRIC_CFG_PATH=/fabric && export CHANNEL_NAME="channel1" && export ORDERER_URL="blockchain-orderer:31010" && export CORE_PEER_ADDRESSAUTODETECT="false" && export CORE_PEER_NETWORKID="nid1" && export CORE_PEER_LOCALMSPID="Org1MSP" && export CORE_PEER_MSPCONFIGPATH="/fabric/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/" && cd /fabric && configtxgen -profile FourOrgsChannel -outputCreateChannelTx ${CHANNEL_NAME}.tx -channelID ${CHANNEL_NAME} && export FABRIC_CFG_PATH=/etc/hyperledger/fabric && peer channel create -o ${ORDERER_URL} -c ${CHANNEL_NAME} -f /fabric/${CHANNEL_NAME}.tx'
register: channel_result
failed_when: "'version 0, but got version 1' not in channel_result.stderr and channel_result.rc != 0"
- name: Join Org1MSP to Our Channel
shell: >
oc -n "{{ project_name }}" exec fabric-tools -- bash -c 'export CHANNEL_NAME="channel1" && export CORE_PEER_NETWORKID="nid1" && export ORDERER_URL="blockchain-orderer:31010" && export FABRIC_CFG_PATH="/etc/hyperledger/fabric" && export CORE_PEER_LOCALMSPID="Org1MSP" && export CORE_PEER_MSPID="Org1MSP" && export CORE_PEER_MSPCONFIGPATH="/fabric/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" && export CORE_PEER_ADDRESS="blockchain-org1peer1:30110" && peer channel fetch newest -o ${ORDERER_URL} -c ${CHANNEL_NAME} && peer channel join -b ${CHANNEL_NAME}_newest.block && rm -rf /${CHANNEL_NAME}_newest.block && export CORE_PEER_ADDRESS="blockchain-org1peer2:30110" && peer channel fetch newest -o ${ORDERER_URL} -c ${CHANNEL_NAME} && peer channel join -b ${CHANNEL_NAME}_newest.block && rm -rf /${CHANNEL_NAME}_newest.block'
register: org1_result
failed_when: "'LedgerID already exists' not in org1_result.stderr and org1_result.rc != 0"
- name: Join Org2MSP to Our Channel
shell: >
oc -n "{{ project_name }}" exec fabric-tools -- bash -c 'export CHANNEL_NAME="channel1" && export CORE_PEER_NETWORKID="nid1" && export ORDERER_URL="blockchain-orderer:31010" && export FABRIC_CFG_PATH="/etc/hyperledger/fabric" && export CORE_PEER_LOCALMSPID="Org2MSP" && export CORE_PEER_MSPID="Org2MSP" && export CORE_PEER_MSPCONFIGPATH="/fabric/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp" && export CORE_PEER_ADDRESS="blockchain-org2peer1:30110" && peer channel fetch newest -o ${ORDERER_URL} -c ${CHANNEL_NAME} && peer channel join -b ${CHANNEL_NAME}_newest.block && rm -rf /${CHANNEL_NAME}_newest.block && export CORE_PEER_ADDRESS="blockchain-org2peer2:30110" && peer channel fetch newest -o ${ORDERER_URL} -c ${CHANNEL_NAME} && peer channel join -b ${CHANNEL_NAME}_newest.block && rm -rf /${CHANNEL_NAME}_newest.block'
register: org2_result
failed_when: "'LedgerID already exists' not in org2_result.stderr and org2_result.rc != 0"
- name: Join Org3MSP to Our Channel
shell: >
oc -n "{{ project_name }}" exec fabric-tools -- bash -c 'export CHANNEL_NAME="channel1" && export CORE_PEER_NETWORKID="nid1" && export ORDERER_URL="blockchain-orderer:31010" && export FABRIC_CFG_PATH="/etc/hyperledger/fabric" && export CORE_PEER_LOCALMSPID="Org3MSP" && export CORE_PEER_MSPID="Org3MSP" && export CORE_PEER_MSPCONFIGPATH="/fabric/crypto-config/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp" && export CORE_PEER_ADDRESS="blockchain-org3peer1:30110" && peer channel fetch newest -o ${ORDERER_URL} -c ${CHANNEL_NAME} && peer channel join -b ${CHANNEL_NAME}_newest.block && rm -rf /${CHANNEL_NAME}_newest.block && export CORE_PEER_ADDRESS="blockchain-org3peer2:30110" && peer channel fetch newest -o ${ORDERER_URL} -c ${CHANNEL_NAME} && peer channel join -b ${CHANNEL_NAME}_newest.block && rm -rf /${CHANNEL_NAME}_newest.block'
register: org3_result
failed_when: "'LedgerID already exists' not in org3_result.stderr and org3_result.rc != 0"
- name: Join Org4MSP to Our Channel
shell: >
oc -n "{{ project_name }}" exec fabric-tools -- bash -c 'export CHANNEL_NAME="channel1" && export CORE_PEER_NETWORKID="nid1" && export ORDERER_URL="blockchain-orderer:31010" && export FABRIC_CFG_PATH="/etc/hyperledger/fabric" && export CORE_PEER_LOCALMSPID="Org4MSP" && export CORE_PEER_MSPID="Org4MSP" && export CORE_PEER_MSPCONFIGPATH="/fabric/crypto-config/peerOrganizations/org4.example.com/users/Admin@org4.example.com/msp" && export CORE_PEER_ADDRESS="blockchain-org4peer1:30110" && peer channel fetch newest -o ${ORDERER_URL} -c ${CHANNEL_NAME} && peer channel join -b ${CHANNEL_NAME}_newest.block && rm -rf /${CHANNEL_NAME}_newest.block && export CORE_PEER_ADDRESS="blockchain-org4peer2:30110" && peer channel fetch newest -o ${ORDERER_URL} -c ${CHANNEL_NAME} && peer channel join -b ${CHANNEL_NAME}_newest.block && rm -rf /${CHANNEL_NAME}_newest.block'
register: org4_result
failed_when: "'LedgerID already exists' not in org4_result.stderr and org4_result.rc != 0"
- name: Install Chaincode on Org1MSP
shell: >
oc -n "{{ project_name }}" exec fabric-tools -- bash -c 'cp -r /fabric/config/chaincode $GOPATH/src/ && export CHAINCODE_NAME="cc" && export CHAINCODE_VERSION="1.0" && export FABRIC_CFG_PATH="/etc/hyperledger/fabric" && export CORE_PEER_MSPCONFIGPATH="/fabric/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" && export CORE_PEER_LOCALMSPID="Org1MSP" && export CORE_PEER_ADDRESS="blockchain-org1peer1:30110" && peer chaincode install -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -p chaincode_example02/ && export CORE_PEER_ADDRESS="blockchain-org1peer2:30110" && peer chaincode install -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -p chaincode_example02/'
- name: Install Chaincode on Org2MSP
shell: >
oc -n "{{ project_name }}" exec fabric-tools -- bash -c 'cp -r /fabric/config/chaincode $GOPATH/src/ && export CHAINCODE_NAME="cc" && export CHAINCODE_VERSION="1.0" && export FABRIC_CFG_PATH="/etc/hyperledger/fabric" && export CORE_PEER_MSPCONFIGPATH="/fabric/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp" && export CORE_PEER_LOCALMSPID="Org2MSP" && export CORE_PEER_ADDRESS="blockchain-org2peer1:30110" && peer chaincode install -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -p chaincode_example02/ && export CORE_PEER_ADDRESS="blockchain-org2peer2:30110" && peer chaincode install -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -p chaincode_example02/'
- name: Install Chaincode on Org3MSP
shell: >
oc -n "{{ project_name }}" exec -it fabric-tools -- bash -c 'cp -r /fabric/config/chaincode $GOPATH/src/ && export CHAINCODE_NAME="cc" && export CHAINCODE_VERSION="1.0" && export FABRIC_CFG_PATH="/etc/hyperledger/fabric" && export CORE_PEER_MSPCONFIGPATH="/fabric/crypto-config/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp" && export CORE_PEER_LOCALMSPID="Org3MSP" && export CORE_PEER_ADDRESS="blockchain-org3peer1:30110" && peer chaincode install -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -p chaincode_example02/ && export CORE_PEER_ADDRESS="blockchain-org3peer2:30110" && peer chaincode install -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -p chaincode_example02/'
- name: Install Chaincode on Org4MSP
shell: >
oc -n "{{ project_name }}" exec -it fabric-tools -- bash -c 'cp -r /fabric/config/chaincode $GOPATH/src/ && export CHAINCODE_NAME="cc" && export CHAINCODE_VERSION="1.0" && export FABRIC_CFG_PATH="/etc/hyperledger/fabric" && export CORE_PEER_MSPCONFIGPATH="/fabric/crypto-config/peerOrganizations/org4.example.com/users/Admin@org4.example.com/msp" && export CORE_PEER_LOCALMSPID="Org4MSP" && export CORE_PEER_ADDRESS="blockchain-org4peer1:30110" && peer chaincode install -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -p chaincode_example02/ && export CORE_PEER_ADDRESS="blockchain-org4peer2:30110" && peer chaincode install -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -p chaincode_example02/'
- name: Instantiate Chaincode
shell: oc -n "{{ project_name }}" exec -it fabric-tools -- bash -c '/fabric/config/instantiate_chaincode.sh'
register: chaincode_result
failed_when: "'already exists' not in chaincode_result.stderr and chaincode_result.rc != 0"
- name: Update channel from org1 to reflect Anchor Peers
shell: |
pod=$(oc get pods -n "{{ project_name }}" | grep blockchain-org1peer1 | awk '{print $1}')
oc exec $pod -- peer channel update -f /fabric/Org1MSPanchors.tx -c channel1 -o blockchain-orderer:31010
register: channel_org1
failed_when: "'version 0, but got version 1' not in channel_org1.stderr and channel_org1.rc != 0"
- name: Update channel from org2 to reflect Anchor Peers
shell: |
pod=$(oc get pods -n "{{ project_name }}" | grep blockchain-org2peer1 | awk '{print $1}')
oc exec $pod -- peer channel update -f /fabric/Org2MSPanchors.tx -c channel1 -o blockchain-orderer:31010
register: channel_org2
failed_when: "'version 0, but got version 1' not in channel_org2.stderr and channel_org2.rc != 0"
- name: Update channel from org3 to reflect Anchor Peers
shell: |
pod=$(oc get pods -n "{{ project_name }}" | grep blockchain-org3peer1 | awk '{print $1}')
oc exec $pod -- peer channel update -f /fabric/Org3MSPanchors.tx -c channel1 -o blockchain-orderer:31010
register: channel_org3
failed_when: "'version 0, but got version 1' not in channel_org3.stderr and channel_org3.rc != 0"
- name: Update channel from org4 to reflect Anchor Peers
shell: |
pod=$(oc get pods -n "{{ project_name }}" | grep blockchain-org4peer1 | awk '{print $1}')
oc exec $pod -- peer channel update -f /fabric/Org4MSPanchors.tx -c channel1 -o blockchain-orderer:31010
register: channel_org4
failed_when: "'version 0, but got version 1' not in channel_org4.stderr and channel_org4.rc != 0"
- name: Deploy Hyperledger Explorer Database
shell: "oc apply -f kubernetes/blockchain-explorer-db_deploy.yaml -n {{ project_name }}"
- name: Create Explorer Service
shell: "oc apply -f kubernetes/blockchain-explorer-db_svc.yaml -n {{ project_name }}"
- name: Wait for postgresql to be ready
shell: oc get po -n "{{ project_name }}" | grep -i blockchain-explorer-db
register: postgresql_explorer
until: postgresql_explorer.stdout.find("Running") != -1
retries: 60
delay: 40
- name: Populate database
shell: |
pod=$(oc get pods | grep blockchain-explorer-db | awk '{print $1}')
oc -n "{{ project_name }}" exec $pod -- bash -c 'mkdir -p /fabric/config/explorer/db/ && mkdir -p /fabric/config/explorer/app/ && cd /fabric/config/explorer/db/ && wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/master/app/persistence/fabric/postgreSQL/db/createdb.sh -O createdb.sh && wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/master/app/persistence/fabric/postgreSQL/db/explorerpg.sql -O explorerpg.sql && wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/master/app/persistence/fabric/postgreSQL/db/processenv.js -O processenv.js && wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/master/app/persistence/fabric/postgreSQL/db/updatepg.sql -O updatepg.sql && apk update && apk add jq ; apk add nodejs ; apk add sudo ; rm -rf /var/cache/apk/* && chmod +x ./createdb.sh && ./createdb.sh'
- name: Copy network file
shell: oc -n "{{ project_name }}" cp config/explorer/app/config.json fabric-tools:/fabric/config/explorer/app/
ignore_errors: true
- name: Copy run.sh
shell: chmod +x config/explorer/app/run.sh && oc -n "{{ project_name }}" cp config/explorer/app/run.sh fabric-tools:/fabric/config/explorer/app/
ignore_errors: true
- name: Deploy explorer
shell: "oc apply -f kubernetes/blockchain-explorer-app_deploy.yaml -n {{ project_name }}"
- name: Create explorer svc
shell: "oc expose deployment blockchain-explorer-app --port=8080 -n {{ project_name }} || echo 'ja existe'"
- name: Create explorer route
shell: "oc expose svc/blockchain-explorer-app -n {{ project_name }} || echo 'ja existe'"
- name: Remove helper pod
shell: "oc delete -f kubernetes/fabric-tools.yaml -n {{ project_name }}"