forked from mobilecoinfoundation/mobilecoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
252 lines (228 loc) · 9.1 KB
/
Jenkinsfile
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
def COLOR_MAP = ['SUCCESS': 'good', 'FAILURE': 'danger', 'UNSTABLE': 'danger', 'ABORTED': 'danger']
pipeline {
options {
parallelsAlwaysFailFast()
}
agent {
kubernetes {
slaveConnectTimeout 240000
activeDeadlineSeconds 43200
yamlFile 'jenkins/build-pod.yaml'
}
}
stages {
stage('Source and Environment Setup') {
steps {
script {
// SGX Compile mode
env.SGX_MODE = "HW"
// Intel Attestation Service compile/runtime mode
env.IAS_MODE = "DEV"
// Network name, results in node names like nodeX.$NETWORK.mobilecoin.com
env.NETWORK = "cd"
// Owner of the Docker repos for pushing container images
env.DOCKER_OWNER = "mobilecoin"
// Container repository for the consensus service
env.CONSENSUS_NODE_DOCKER_REPO = "node_hw"
// Container repository for the mobilecoind service
env.MOBILECOIND_DOCKER_REPO = "mobilecoind"
// Container repository for the mobilecoind service
env.BOOTSTRAP_TOOLS_DOCKER_REPO = "bootstrap-tools"
// Set a dateformat string to be used as a docker tag
env.TAG_VERSION = sh(returnStdout: true, script: 'date +"v%Y%m%d%H%m%S"').trim()
}
// Stash sources for later use on multiple Jenkins nodes
stash name: 'sources', useDefaultExcludes: false, includes: '**', excludes: '**/.git, **/.git/**'
}
}
stage('Cargo Build') {
// Reusing the default agent/pod config
steps {
container('rust-builder-default') {
// Show the environment for posterity
sh 'printenv | sort'
// Can be swapped out for specific build commands
sh 'cargo build --release'
// Build mobilecoind without default features
sh 'cargo build --release -p mc-mobilecoind --no-default-features'
// Staging area for binary packaging
sh 'mkdir -p $WORKSPACE/ops/bin'
// Copy relevant binaries to staging area
sh '''
for file in $(find $WORKSPACE/target/release -maxdepth 1 -type f "(" -name '*.so' -o -executable ")" -not -name '*_test' ); do
cp -v ${file} $WORKSPACE/ops/bin/
done
ls -la $WORKSPACE/ops/bin
'''
// Copy the one-shot test-certificates into the staging area
sh 'mkdir -p $WORKSPACE/ops/attest && cp -a $WORKSPACE/attest/test_certs $WORKSPACE/ops/attest/test_certs'
// Make directories and populate sample_data
dir('ops') {
sh 'mkdir -p sample_data/ledger'
sh 'mkdir -p sample_data/keys'
}
// Generate sample data
dir('ops/sample_data') {
// Generate lots of account keys to keep balances smaller
sh '../bin/sample-keys --num 1000'
sh '../bin/generate-sample-ledger -t 100'
// Remove extra keys otherwise test_client will try all combinations
sh 'for i in $(seq 6 999); do rm -rf keys/*_${i}.*; done'
sh 'rm -f ./ledger/lock.mdb'
}
// Stash the ops data/binaries for usage in later steps
stash name: 'ops_data', includes: 'ops/**'
}
}
}
stage('Build Images') {
parallel {
stage('Build Consensus Service container') {
options {
skipDefaultCheckout true
}
agent {
kubernetes {
slaveConnectTimeout 240000
activeDeadlineSeconds 43200
yamlFile 'jenkins/packaging-pod.yaml'
}
}
steps {
container('jnlp'){
unstash name: 'sources'
unstash name: 'ops_data'
}
container('kaniko'){
sh '''
for i in 1 2 3; do
/kaniko/executor -f $WORKSPACE/ops/Dockerfile-consensus -c $WORKSPACE/ops \
--build-arg ORIGIN_DATA_DIR=sample_data \
--build-arg GIT_COMMIT=${GIT_COMMIT} \
--build-arg BRANCH=${NETWORK} \
--destination=$DOCKER_OWNER/$CONSENSUS_NODE_DOCKER_REPO:${NETWORK}-${TAG_VERSION} \
--destination=$DOCKER_OWNER/$CONSENSUS_NODE_DOCKER_REPO:${NETWORK}-latest \
--cleanup \
&& break || sleep 5;
done
'''
}
}
}
stage('Build mobilecoind container') {
options {
skipDefaultCheckout true
}
agent {
kubernetes {
slaveConnectTimeout 240000
activeDeadlineSeconds 43200
yamlFile 'jenkins/packaging-pod.yaml'
}
}
steps {
container('jnlp'){
unstash name: 'sources'
unstash name: 'ops_data'
}
container('kaniko'){
sh '''
for i in 1 2 3; do
/kaniko/executor -f $WORKSPACE/ops/Dockerfile-mobilecoind -c $WORKSPACE/ops \
--build-arg ORIGIN_DATA_DIR=sample_data \
--build-arg GIT_COMMIT=${GIT_COMMIT} \
--build-arg BRANCH=${NETWORK} \
--destination=$DOCKER_OWNER/$MOBILECOIND_DOCKER_REPO:${NETWORK}-${TAG_VERSION} \
--destination=$DOCKER_OWNER/$MOBILECOIND_DOCKER_REPO:${NETWORK}-latest \
--cleanup \
&& break || sleep 5;
done
'''
}
}
}
}
}
stage('Deploy and Test') {
options {
lock resource: env.NETWORK
}
stages {
stage('Deploy to k8s') {
options {
skipDefaultCheckout true
}
agent {
kubernetes {
slaveConnectTimeout 240000
activeDeadlineSeconds 43200
yamlFile 'jenkins/kubectl-pod.yaml'
}
}
steps {
container('jnlp') {
unstash name: 'sources'
dir('deploy') {
sh './generate-manifests -n ${NETWORK} -t ${NETWORK}-${TAG_VERSION}'
}
}
container('kubectl') {
dir('deploy/build') {
script {
sh(script: 'kubectl get po -n ${NETWORK}')
// Delete the consensus nodes, and {discovery, mobilecoind, ledger} nodes if any
sh(script: 'for i in 03* 04*; do kubectl delete --ignore-not-found -n ${NETWORK} -f ${i}; done')
// Update the 01* configs
sh(script: 'for i in 01*yaml; do kubectl apply -n ${NETWORK} -f ${i}; done')
// Launch the consensus node deployments
sh(script: 'for i in 03*yaml; do kubectl apply -n ${NETWORK} -f ${i}; done')
// Wait until the deployments have achieved an Available state.
sh(script: 'for i in 1 2 3 4 5; do kubectl wait --for=condition=Available deploy/node${i} -n ${NETWORK} --timeout=2500s; done')
// Deploy an internal mobilecoind to test with
sh(script: 'kubectl apply -n ${NETWORK} -f 04-mobilecoind.yaml')
// Wait for mobilecoind to achieve and Available state
sh(script: 'kubectl wait --for=condition=Available deploy/mobilecoind -n ${NETWORK} --timeout=480s')
sh(script: 'kubectl get po -n ${NETWORK}')
}
}
}
}
}
stage('Wallet Integration Test') {
steps {
container('rust-builder-default') {
dir('mobilecoind/strategies') {
sh 'pip3 install -r requirements.txt'
sh '''
python3 -m grpc_tools.protoc -I$WORKSPACE/api/proto \
--python_out=. $WORKSPACE/api/proto/external.proto
'''
sh '''
python3 -m grpc_tools.protoc -I$WORKSPACE/api/proto \
--python_out=. $WORKSPACE/api/proto/blockchain.proto
'''
sh '''
python3 -m grpc_tools.protoc \
-I$WORKSPACE/mobilecoind/api/proto -I$WORKSPACE/api/proto -I$WORKSPACE/consensus/api/proto \
--python_out=. --grpc_python_out=. $WORKSPACE/mobilecoind/api/proto/mobilecoind_api.proto
'''
sh '''
python3 test_client.py \
--key-dir $WORKSPACE/ops/sample_data/keys \
--mobilecoind-host mobilecoind.${NETWORK}.svc.cluster.local\
--mobilecoind-port 3229
'''
}
}
}
}
}
}
}
post {
always {
slackSend color: COLOR_MAP[currentBuild.currentResult],
message: "*${currentBuild.currentResult}:*\nJob: ${env.JOB_NAME}\nCommit: ${env.GIT_COMMIT}\nDocker Tag: ${env.NETWORK}-${env.TAG_VERSION}\nBuild: ${env.BUILD_NUMBER}\nDuration: ${currentBuild.durationString}\nMore info at: ${env.BUILD_URL}"
}
}
}