-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathJenkinsfile.cd
More file actions
397 lines (333 loc) · 14.1 KB
/
Jenkinsfile.cd
File metadata and controls
397 lines (333 loc) · 14.1 KB
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
#!groovy
def sovLibrary = library(identifier: 'sovrin-aws-codebuild@v1.0.0', retriever: modernSCM(
github(credentialsId: 'sovbot-github', repoOwner: 'sovrin-foundation', repository: 'aws-codebuild-pipeline-plugin')
)).com.sovrin.pipeline
logger = sovLibrary.Logger.new(this)
logger.setGlobalLevel('TRACE')
notifier = sovLibrary.Notifier.new(this)
utils = sovLibrary.Utils.new(this)
String srcVersion
gitHubUserCredId = env.GITHUB_BOT_USER ?: 'sovbot-github'
sovrinPackagingRepo = env.SOVRIN_PACKAGING_REPO ?: 'https://github.com/sovrin-foundation/sovrin-packaging'
sovrinPackagingBranch = env.SOVRIN_PACKAGING_BRANCH ?: 'master'
def downloadPackagingUtils() {
git branch: sovrinPackagingBranch, credentialsId: gitHubUserCredId, url: sovrinPackagingRepo
sh "pip3 install -U plumbum deb-pkg-tools"
}
// TODO set proper labels
def nodeLabels = [
codeBuild: env.LIBSOVTOKEN_CODEBUILD_NODE_LABEL ?: 'codebuild',
macos: env.LIBSOVTOKEN_MACOS_NODE_LABEL ?: 'macos',
]
def codeBuildPipelines = {
def packageName = 'libsovtoken'
//put code build containers inside a vpc under our dev account
env.USE_VPC_CONFIG = true
env.SOVRIN_REPO_HOST = '192.168.101.193'
List _envBuildSrc = [
'devops',
'libsovtoken/Cargo.toml',
'libsovtoken/build_scripts/android/libsovtoken/libsovtoken.dependencies.txt',
'libsovtoken/build_scripts/android/android_settings.txt'
]
stage('Checkout sources from SCM') {
checkout scm
}
def sovrinRepo = sovLibrary.SovrinRepo.new(this)
def git = sovLibrary.Git.new(this)
def buildCtx = sovLibrary.AwsCodeBuildHelper.BuildCtx.new('libsovtoken')
def awsCBHelper = sovLibrary.AwsCodeBuildHelper.new(this, buildCtx)
if (!srcVersion) {
stage('Resolve current source version') {
srcVersion = utils.srcVersion(projectType: 'rust')
logger.info("Current source version: $srcVersion")
}
}
stage('Upload source to S3') {
awsCBHelper.uploadSourceToS3()
}
def androidBuild = {
def osname = 'xenial'
def prTag = "cd-$osname-android"
List goals = ['package_android']
List targetArchs = ['arm', 'armv7', 'arm64', 'x86', 'x86_64']
def buildImageTag
stage("$prTag: Resolve image tag") {
def _imgVersion = utils.shStdout("OSNAME=$osname make -C devops image_lst_android_build_version -s")
buildImageTag = "${_imgVersion}-${prTag}"
logger.info("CD docker image tag: $buildImageTag")
}
awsCBHelper.build() {
projectTag = prTag
// build spec for env image
envBuildSrc = _envBuildSrc // TODO make more accurate
envBuildCmds = [
'export PROJECT_DIR=$PWD',
'make -C devops image_lst_android_build'
]
envBuildLocalName = "sovrin/libsovtoken:$buildImageTag"
envBuildEnvv = [
[name: 'OSNAME', value: osname],
[name: 'LST_ANDROID_BUILD_DOCKER_TAG', value: buildImageTag],
]
// env and build spec
imageTag = buildImageTag
buildspec = 'devops/aws-codebuild/buildspec.cd.yml'
envv = [
[name: 'OSNAME', value: osname],
[name: 'ANDROID_ARCHS', value: "${targetArchs.join(' ')}"],
[name: 'MAKE_GOALS', value: "${goals.join(' ')}"],
[name: 'PACKAGE_NAME', value: packageName],
[name: 'GIT_SHA1_SHORT', value: git.sha1(shortN: true)],
[name: 'ARTIFACTS', value: "devops/_build/android/${packageName}*all.zip"],
]
onArtifacts = {
this.stage("$prTag: Archive logs") {
this.utils.archiveArtifacts("logs/*.log*") {
truncate = true
allowEmptyArchive = true
truncateFileSuffix = 'trunc.log'
}
}
}
}
stage('Upload android archives to Sovrin repo') {
String archName
def scriptDir = pwd()
dir("${awsCBHelper.buildCtx.projects[prTag].artifactsDir}") {
archName = utils.shStdout("ls $packageName*$srcVersion*all.zip")
logger.info("Uploading package '$archName' to sovrin repo")
withCredentials([file(credentialsId: 'SovrinRepoSSHKey', variable: 'sovrin_key')]) {
sh "$scriptDir/devops/android_upload.sh $srcVersion $sovrin_key $env.BRANCH_NAME $BUILD_NUMBER libsovtoken $archName"
}
}
notifier.email {
subject = '$PROJECT_NAME - Build # $BUILD_NUMBER: ' + "new android package '$archName' was published"
body = ("New android package '$archName' was built and published" +
'\n\nCheck console output at $BUILD_URL to view the details.')
}
}
}
def xenialBuild = {
def osname = 'xenial'
def prTag = "cd-$osname"
def goals = ['package']
def buildImageTag
def lastRevision
def debPVersion
def cratePVersion
// stage('Resolve last debian revision') {
// lastRevision = sovrinRepo.getLastRevision {
// delegate.packageName = packageName
// packageSrcVersion = srcVersion
// repoDistr = 'xenial-rc'
// }
//
// if (lastRevision) {
// logger.info("Found last revision number: $lastRevision")
// } else {
// logger.info("No previous revision was found")
// }
// }
stage('Set release parameters') {
logger.info("Finding Release version")
// def releaseVersion = env.BRANCH_NAME == 'stable' ? '' : "${lastRevision ? lastRevision[0] + 1: 1}.$BUILD_NUMBER"
def releaseVersion = env.BRANCH_NAME == 'stable' ? '' : "$BUILD_NUMBER"
logger.info("Release version for sovrin repo: $releaseVersion")
// debPVersion = utils.packageVersion('deb', srcVersion, releaseVersion, env.BRANCH_NAME == 'master')
debPVersion = env.BRANCH_NAME == 'stable' ? "$srcVersion": "$srcVersion~$releaseVersion"
logger.info("Package version for sovrin repo: $debPVersion")
// TODO crate and rpm
//cratePVersion = utils.packageVersion('crate', srcVersion, releaseVersion)
//logger.info("Package version for rust registry: $cratePVersion")
}
stage("$prTag: Resolve image tag") {
def _imgVersion = utils.shStdout("OSNAME=$osname make -C devops image_lst_base_version -s")
buildImageTag = "${_imgVersion}-${prTag}"
logger.info("CD docker image tag: $buildImageTag")
}
awsCBHelper.build() {
projectTag = prTag
// build spec for env image
envBuildSrc = _envBuildSrc // TODO make more accurate
envBuildCmds = [
'export PROJECT_DIR=$PWD',
'make -C devops image_lst_base'
]
envBuildLocalName = "sovrin/libsovtoken:$buildImageTag"
envBuildEnvv = [
[name: 'OSNAME', value: osname],
[name: 'LST_BASE_DOCKER_TAG', value: buildImageTag],
]
// env and build spec
imageTag = buildImageTag
buildspec = 'devops/aws-codebuild/buildspec.cd.yml'
envv = [
[name: 'OSNAME', value: osname],
[name: 'MAKE_GOALS', value: "${goals.join(' ')}"],
[name: 'ARTIFACTS', value: "libsovtoken/target/release/${packageName}*.*"],
[name: 'PACKAGE_NAME', value: packageName],
[name: 'FPM_P_VERSION', value: debPVersion],
// [name: 'CRATE_P_VERSION', value: cratePVersion],
]
onArtifacts = {
this.stage("$prTag: Archive logs") {
this.utils.archiveArtifacts("logs/*.log*") {
truncate = true
allowEmptyArchive = true
truncateFileSuffix = 'trunc.log'
}
}
}
}
stage('Upload deb to repositories') {
String debName
dir("${awsCBHelper.buildCtx.projects[prTag].artifactsDir}") {
dir("sovrin-packaging") {
downloadPackagingUtils()
}
debName = utils.shStdout("ls $packageName*$debPVersion*.deb")
logger.info("Uploading debian package '$debName' to sovrin repo")
sh "mkdir debs && mv $debName ./debs/"
withCredentials([file(credentialsId: 'SovrinRepoSSHKey', variable: 'sovrin_key')]) {
sh "./sovrin-packaging/upload_debs.py ./debs $env.SOVRIN_SDK_REPO_NAME $env.BRANCH_NAME --host $env.SOVRIN_REPO_HOST --ssh-key $sovrin_key"
}
}
notifier.email {
subject = '$PROJECT_NAME - Build # $BUILD_NUMBER: ' + "new deb '$debName' was published"
body = ("New debian package '$debName' was built and published" +
'\n\nCheck console output at $BUILD_URL to view the details.')
}
}
/*
['agency_dev', 'agency_qa'].each { distr ->
stage("Promote deb from $distr") {
sovrinRepo.promote {
repoDistr = distr
delegate.packageName = packageName
delegate.packageVersion = debPVersion
}
}
}
*/
}
Map builds = [
xenial: xenialBuild,
android: [
build: androidBuild,
nodeLabel: "$nodeLabels.codeBuild"
]
]
builds.failFast = false
stage("CodeBuild Build") {
utils.parallel builds
}
}
def macOSPipeline = {
stage("MacOS Build") {
def packageName = 'libsovtoken'
def xcodeMinVersion = '9.0'
def RUST_PATH = '~/.cargo/bin'
stage('Checks') {
echo "===================== Checks for XCode and Rust environment ========================"
INSTALLED_XCODE_VERSION = sh(script: '''xcodebuild -version | head -1 | cut -d' ' -f2''', returnStdout: true)
echo "INSTALLED_XCODE_VERSION = ${INSTALLED_XCODE_VERSION} and xcodeMinVersion = ${xcodeMinVersion}"
if ( INSTALLED_XCODE_VERSION <= xcodeMinVersion ) {
msg = "The XCode version must be greater or equal ${xcodeMinVersion}"
echo "${msg}"
error(msg)
}
RUST_HOME_EXIST = sh(script: "test -d ${RUST_PATH} && echo '1' || echo '0' ", returnStdout: true).trim()
if ( RUST_HOME_EXIST == '0' ) {
msg = "Rust home dir does not exist. Make sure that rust is installed in the ${RUST_PATH}."
echo "${msg}"
error(msg)
}
RUSTC_VERSION = sh(script: "${RUST_PATH}/rustc --version || echo '0' ", returnStdout: true).trim()
if ( RUSTC_VERSION == '0' ) {
msg = "rustc does not exist. Make sure that rust is installed in the ${RUST_PATH}."
echo "${msg}"
error(msg)
}
}
stage('Checkout sources from SCM') {
checkout scm
}
def sovrinRepo = sovLibrary.SovrinRepo.new(this)
def utils = sovLibrary.Utils.new(this)
if (!srcVersion) {
stage('Resolve current source version') {
srcVersion = utils.srcVersion(projectType: 'rust')
logger.info("Current source version: $srcVersion")
}
}
withEnv([
"PATH+RUST=${RUST_PATH}",
"PATH+BREW=/usr/local/bin",
"PATH+CURL=/usr/local/opt/curl/bin"
]) {
dir('libsovtoken/build_scripts/ios/mac/') {
stage('mac.01.libindy.setup') {
sh './mac.01.env.setup.sh'
}
stage('mac.14.libsovtoken.build.sh') {
sh "./mac.14.libsovtoken.build.sh"
}
}
dir('libsovtoken') {
pkgName = utils.shStdout("ls ${packageName}*.zip")
stash includes: pkgName, name: "iosArtifact"
}
}
}
}
def macosUpload = {
String packageName = "libsovtoken"
stage('Upload libsovtoken universal package to Sovrin repo') {
unstash name: "iosArtifact"
String pkgName = utils.shStdout("ls ${packageName}*.zip")
logger.info("Uploading libsovtoken package '$pkgName' to sovrin repo")
withCredentials([file(credentialsId: 'SovrinRepoSSHKey', variable: 'sovrin_key')]) {
version = "$srcVersion~$env.BUILD_NUMBER"
target = "/var/repository/repos/ios/$packageName/$env.BRANCH_NAME/$packageName-core"
sh "ssh -v -oStrictHostKeyChecking=no -i '$sovrin_key' repo@$SOVRIN_REPO_HOST mkdir -p $target/$version"
sh "scp -r -oStrictHostKeyChecking=no -i $sovrin_key $pkgName repo@$SOVRIN_REPO_HOST:$target/$version/"
}
}
}
pipelineWrapper({
//put code build containers inside a vpc under our dev account
env.USE_VPC_CONFIG = true
Map builds = [
codeBuild: [
build: codeBuildPipelines,
nodeLabel: "$nodeLabels.codeBuild"
],
macos: [
build: macOSPipeline,
nodeLabel: "$nodeLabels.macos"
]
]
builds.failFast = false
stage("Build") {
utils.parallel builds
}
Map publish = [
macosPublish: [
build: macosUpload,
nodeLabel: "$nodeLabels.codeBuild"
]
]
stage ('Publish') {
utils.parallel publish
}
}, { err ->
stage("Pipeline finalizing") {
if (err) {
logger.error("Pipeline failed with the error $err")
}
stage("Build result notification") {
notifier.email()
}
}
})