-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.yml
203 lines (155 loc) · 11.3 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
---
- hosts: localhost
connection: local
vars:
project_name: "myproject"
username: "system:admin"
password: "lala"
master_url: "https://127.0.0.1:8443/"
tasks:
- name: login as {{ username }} (must be cluster-admin)
shell: "oc login -u system:admin"
# shell: "oc login -u {{ username }} -p {{ password }} {{ master_url }}"
# shell: oc login https://127.0.0.1:8443 --token=FwgcAV8Wz0TPuLIQYzNY9kKvLSoMS5MUvA0UzVXFl9s
- 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 pod -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 config files to fabric tools containers
shell: "oc -n {{ project_name }} cp config fabric-tools:/fabric"
- name: Copy chaincode to pvc
shell: "oc -n {{ project_name }} cp chaincode/ fabric-tools:/fabric"
- name: Copy scripts to pvc
shell: "oc -n {{ project_name }} cp scripts fabric-tools:/fabric"
- name: Copy external-builder to pvc
shell: "oc -n {{ project_name }} cp external-builder fabric-tools:/fabric"
- 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 orderer genesis block
shell: oc -n "{{ project_name }}" exec fabric-tools -- bash -c "cp /fabric/config/configtx.yaml /fabric/ && cd /fabric && configtxgen -profile SampleMultiNodeEtcdRaft -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block"
- name: Generate channel configuration transaction
shell: oc -n "{{ project_name }}" exec fabric-tools -- bash -c "cp /fabric/config/configtx.yaml /fabric/ && cd /fabric && configtxgen -profile TwoOrgsChannel -channelID mychannel --outputCreateChannelTx ./channel-artifacts/channel.tx"
- name: Create Anchor Peers
shell: oc -n "{{ project_name }}" exec fabric-tools -- bash -c "{{ item }}"
with_items:
- "cd /fabric && configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP"
- "cd /fabric && configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP"
- name: Fix permissions
shell: oc -n "{{ project_name }}" exec fabric-tools -- bash -c "chmod a+rx /fabric/* -R"
- name: Create Orderer
shell: oc -n "{{ project_name }}" apply -f "{{ item }}"
with_items:
- kubernetes/blockchain-orderer_deploy.yaml
- kubernetes/blockchain-orderer_svc.yaml
- name: Create Orderer2
shell: oc -n "{{ project_name }}" apply -f "{{ item }}"
with_items:
- kubernetes/blockchain-orderer2_deploy.yaml
- kubernetes/blockchain-orderer2_svc.yaml
- name: Create Orderer3
shell: oc -n "{{ project_name }}" apply -f "{{ item }}"
with_items:
- kubernetes/blockchain-orderer3_deploy.yaml
- kubernetes/blockchain-orderer3_svc.yaml
- name: Create Orderer4
shell: oc -n "{{ project_name }}" apply -f "{{ item }}"
with_items:
- kubernetes/blockchain-orderer4_deploy.yaml
- kubernetes/blockchain-orderer4_svc.yaml
- name: Create Orderer5
shell: oc -n "{{ project_name }}" apply -f "{{ item }}"
with_items:
- kubernetes/blockchain-orderer5_deploy.yaml
- kubernetes/blockchain-orderer5_svc.yaml
#TODO: core.yaml mounten
- name: Create org1 and peer
shell: oc -n "{{ project_name }}" apply -f "{{ item }}"
with_items:
- kubernetes/blockchain-org1peer0_deploy.yaml
- kubernetes/blockchain-org1peer1_deploy.yaml
- kubernetes/blockchain-org1peer0_svc.yaml
- kubernetes/blockchain-org1peer1_svc.yaml
- name: Create org2 and peer
shell: oc -n "{{ project_name }}" apply -f "{{ item }}"
with_items:
- kubernetes/blockchain-org2peer0_deploy.yaml
- kubernetes/blockchain-org2peer1_deploy.yaml
- kubernetes/blockchain-org2peer0_svc.yaml
- kubernetes/blockchain-org2peer1_svc.yaml
- name: Wait till all pods are running
shell: oc get pods -o json
register: oc_get_pods
until: oc_get_pods.stdout|from_json|json_query('items[*].status.phase')|unique == ["Running"]
retries: 60
delay: 20
- pause: seconds=10
- name: Create channel
shell: >
oc -n "{{ project_name }}" exec fabric-tools -- bash -c 'export FABRIC_CFG_PATH=/fabric && export CORE_PEER_MSPCONFIGPATH=/fabric/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/ && export CORE_PEER_ADDRESS=org1peer0:30110 && export CORE_PEER_LOCALMSPID="Org1MSP" && export CORE_PEER_TLS_ROOTCERT_FILE=/fabric/crypto-config/peerOrganizations/org1.example.com/peers/org1peer0/tls/ca.crt && export CHANNEL_NAME=mychannel && export FABRIC_CFG_PATH=/fabric/config/ && peer channel create -o orderer:31010 -c $CHANNEL_NAME -f /fabric/channel-artifacts/channel.tx --tls --cafile /fabric/crypto-config/ordererOrganizations/example.com/orderers/orderer/msp/tlscacerts/tlsca.example.com-cert.pem'
register: channel_result
failed_when: "'version 0, but got version 1' not in channel_result.stderr and channel_result.rc != 0"
- pause: seconds=10
- name: Join channel Org1
shell: >
oc -n "{{ project_name }}" exec fabric-tools -- bash -c 'export CORE_PEER_MSPCONFIGPATH=/fabric/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/ && export CORE_PEER_ADDRESS=org1peer0:30110 && export CORE_PEER_LOCALMSPID="Org1MSP" && export CORE_PEER_TLS_ROOTCERT_FILE=/fabric/crypto-config/peerOrganizations/org1.example.com/peers/org1peer0/tls/ca.crt && export CHANNEL_NAME=mychannel && export FABRIC_CFG_PATH=/fabric/config/ && peer channel join -b $CHANNEL_NAME.block'
- name: Join channel Org2
shell: >
oc -n "{{ project_name }}" exec fabric-tools -- bash -c 'export CORE_PEER_MSPCONFIGPATH=/fabric/crypto-config/peerOrganizations/org2.example.com/users/[email protected]/msp/ && export CORE_PEER_ADDRESS=org2peer0:30110 && export CORE_PEER_LOCALMSPID="Org2MSP" && export CORE_PEER_TLS_ROOTCERT_FILE=/fabric/crypto-config/peerOrganizations/org2.example.com/peers/org2peer0/tls/ca.crt && export CHANNEL_NAME=mychannel && export FABRIC_CFG_PATH=/fabric/config/ && peer channel join -b $CHANNEL_NAME.block'
- name: Update anchor peers Org1
shell: >
oc -n "{{ project_name }}" exec fabric-tools -- bash -c 'export CORE_PEER_MSPCONFIGPATH=/fabric/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/ && export CORE_PEER_ADDRESS=org1peer0:30110 && export CORE_PEER_LOCALMSPID="Org1MSP" && export CORE_PEER_TLS_ROOTCERT_FILE=/fabric/crypto-config/peerOrganizations/org1.example.com/peers/org1peer0/tls/ca.crt && export CHANNEL_NAME=mychannel && export FABRIC_CFG_PATH=/fabric/config/ && peer channel update -o orderer:31010 -c $CHANNEL_NAME -f /fabric/channel-artifacts/Org1MSPanchors.tx --tls --cafile /fabric/crypto-config/ordererOrganizations/example.com/orderers/orderer/msp/tlscacerts/tlsca.example.com-cert.pem'
- name: Update anchor peers Org2
shell: >
oc -n "{{ project_name }}" exec fabric-tools -- bash -c 'export CORE_PEER_MSPCONFIGPATH=/fabric/crypto-config/peerOrganizations/org2.example.com/users/[email protected]/msp/ && export CORE_PEER_ADDRESS=org2peer0:30110 && export CORE_PEER_LOCALMSPID="Org2MSP" && export CORE_PEER_TLS_ROOTCERT_FILE=/fabric/crypto-config/peerOrganizations/org2.example.com/peers/org2peer0/tls/ca.crt && export CHANNEL_NAME=mychannel && export FABRIC_CFG_PATH=/fabric/config/ && peer channel update -o orderer:31010 -c $CHANNEL_NAME -f /fabric/channel-artifacts/Org2MSPanchors.tx --tls --cafile /fabric/crypto-config/ordererOrganizations/example.com/orderers/orderer/msp/tlscacerts/tlsca.example.com-cert.pem'
# - name: Let chaincode process give it to its best
# shell: >
# oc -n "{{ project_name }}" exec fabric-tools -- bash -c '/fabric/scripts/deployCC.sh'
# - 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 }}"