forked from LiskArchive/lisk-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile.migration
174 lines (160 loc) · 4.64 KB
/
Jenkinsfile.migration
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
/*
* Copyright © 2018 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/
properties([
parameters([
string(name: 'MIGRATE_FROM', defaultValue: 'master', description: 'Source branch to test migration', ),
string(name: 'MIGRATE_TO', defaultValue: 'development', description: 'Target branch to test migration', ),
string(name: 'NETWORK', defaultValue: 'test', description: 'The network used during `installLisk.sh`. It must be test or main. ', ),
booleanParam(name: 'USE_TEST_CONFIG', defaultValue: true, description: 'Use test genesis block and config', )
])
])
pipeline {
agent { node { label "core-migration" } }
stages {
stage("Prepare workspace") {
steps {
library identifier: 'lisk-jenkins@master', retriever: modernSCM(
[$class: 'GitSCMSource',
remote: 'https://github.com/LiskHQ/lisk-jenkins.git'])
}
}
stage("Create binary releases") {
parallel {
stage('Create source release') {
steps {
script {
def release = liskBuild(branch: params.MIGRATE_FROM, network: params.NETWORK, useTestConfig: params.USE_TEST_CONFIG)
env.SRC_IS_LATEST = release.latestVersion
env.SRC_VERSION = release.version
env.SRC_RELEASE = release.nonVersionedFile
}
}
}
stage('Create destination release') {
steps {
script {
def release = liskBuild(branch: params.MIGRATE_TO, network: params.NETWORK, useTestConfig: params.USE_TEST_CONFIG)
env.DEST_IS_LATEST = release.latestVersion
env.DEST_VERSION = release.version
env.DEST_RELEASE = release.nonVersionedFile
}
}
}
}
}
stage("Install source release") {
steps {
installLisk(env.SRC_RELEASE, params.NETWORK)
}
}
stage("Migrate to destination release") {
steps {
script {
env.TARGET_BLOCK_HEIGHT = getNetworkHeight() + getCutOffset()
}
dir("lisk-home") {
sh """
cp ${env.DEST_RELEASE} .
wget https://raw.githubusercontent.com/LiskHQ/lisk-scripts/0.2.0/downloaded/lisk_bridge.sh
bash lisk_bridge.sh -f `basename ${env.DEST_RELEASE}` -n ${params.NETWORK} -h ${env.TARGET_BLOCK_HEIGHT} -s ${WORKSPACE}/lisk-home/lisk-${params.NETWORK}
"""
}
}
}
stage("Verify migration") {
steps {
script {
waitForBlockHeight(env.TARGET_BLOCK_HEIGHT.toInteger() + getVerifyOffset())
}
}
}
}
post {
always {
dir("lisk-home/lisk-${params.NETWORK}") {
sh """
bash lisk.sh stop
"""
}
cleanWs()
}
}
}
def installLisk(buildFile, network) {
dir("lisk-home") {
sh """
cp ${buildFile} .
wget https://raw.githubusercontent.com/LiskHQ/lisk-scripts/0.2.0/downloaded/installLisk.sh
bash installLisk.sh install -r ${network} -f `basename ${buildFile}`
"""
}
}
def getCutOffset() {
if (params.USE_TEST_CONFIG == true) {
return 5
} else {
return 50
}
}
def getVerifyOffset() {
if (params.USE_TEST_CONFIG == true) {
return 5
} else {
return 0
}
}
def getNetworkHeight() {
if (params.USE_TEST_CONFIG == true) {
return getLocalBlockHeight()
} else {
dir("lisk-home/lisk-${params.NETWORK}") {
if(params.NETWORK == "main") {
sh """
curl -s https://node.lisk.io/api/loader/status/sync | jq -r '.height' > .lisk-network-height
"""
} else if (params.NETWORK == "test"){
sh """
curl -s https://testnet.lisk.io/api/loader/status/sync | jq -r '.height' > .lisk-network-height
"""
}
}
return readFile("lisk-home/lisk-${params.NETWORK}/.lisk-network-height").trim().toInteger()
}
}
def getLocalBlockHeight() {
dir("lisk-home/lisk-${params.NETWORK}") {
sh """
bash lisk.sh status | tail -1 | awk '{print \$4}' > .lisk-block-height
"""
}
return readFile("lisk-home/lisk-${params.NETWORK}/.lisk-block-height").trim().toInteger()
}
def waitForBlockHeight(targetBlockHeight, waitAttempts=0, previousHeight=0) {
def height = getLocalBlockHeight()
echo "Height: ${height}"
if(previousHeight != height) {
previousHeight = height
waitAttempts = 0
} else if (waitAttempts < 3) {
waitAttempts = waitAttempts + 1
} else {
error("Block height is not increasing from ${previousHeight} in ${waitAttempts} attempts.")
}
if(height < targetBlockHeight) {
sleep 10
waitForBlockHeight(targetBlockHeight, waitAttempts, previousHeight)
} else {
echo "Block height reaches to target."
}
}