-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathJenkinsfile
executable file
·254 lines (213 loc) · 10.6 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
253
254
#!/usr/bin/groovy
// Set build parameters
def isUserDevBranch = env.BRANCH_NAME != "dev" && env.BRANCH_NAME != "master" && !env.BRANCH_NAME.startsWith("release")
def userInput = [
buildDocker: true,
buildWindows: isUserDevBranch ? false : true,
buildOSX: false
];
// The built version, defined via `git describe` in scripts/ci/setEnv.sh call
def VIEWER_VERSION;
if (/*!isUserDevBranch*/ false) { // @warning @todo uncomment to force windows build on dev
echo 'Master/Dev branch: serious test & build business enforced...'
}
else {
echo 'User personal branch: let the user choose what he wants to build...'
// Let user override default settings (max 30 seconds to do so)
try {
timeout(time: 30, unit: 'SECONDS') {
userInput = input(
id: 'userInput', message: 'Configure build', parameters: [
[$class: 'BooleanParameterDefinition', defaultValue: userInput['buildDocker'], description: 'Build Docker (/!\\ false -> disable tests & deployment)', name: 'buildDocker'],
[$class: 'BooleanParameterDefinition', defaultValue: userInput['buildWindows'], description: 'Build Windows', name: 'buildWindows'],
[$class: 'BooleanParameterDefinition', defaultValue: userInput['buildOSX'], description: 'Build OSX', name: 'buildOSX']
]
)
}
} catch (err) {
// Do nothing, keep default settings (since user has not answered)
echo "User personal branch: user either has aborted or hasn't chosen the build settings within the 30 seconds delay..."
}
}
// Print the build parameters
echo 'Build Docker : ' + (userInput['buildDocker'] ? 'OK' : 'KO (/!\\ tests disabled)')
echo 'Build Windows : ' + (userInput['buildWindows'] ? 'OK' : 'KO')
echo 'Build OSX : ' + (userInput['buildOSX'] ? 'OK' : 'KO')
// Lock overall build to avoid issues related to slow unit test runs or docker ip/name conflicts for instance
// This allow to benefits the optimization of using a common workspace for every branches (for instance, test
// preparation docker image is reused in new branches), but can increase slowness if the branch content differences
// is heavy (in terms of disk space). Use jenkins' dir plugin instead of ws plugin to have control over our own locking mechanism.
// @warning make sure not to use the jenkins' dir plugin if this lock is removed.
// @warning make sure we do not rely on `:latest-local` docker tags anymore if this lock is removed.
lock(resource: 'webviewer', inversePrecedence: false) {
def workspacePath = '../_common-wvb-ws'
// Init environment
stage('Retrieve: sources') {
node('master && docker') { dir(path: workspacePath) { wrap([$class: 'AnsiColorBuildWrapper']) {
// Clean up workspace first on non development branches
if (!isUserDevBranch) {
deleteDir()
}
checkout scm
sh 'scripts/ci/ciLogDockerState.sh prebuild'
sh 'scripts/ci/setEnv.sh ${BRANCH_NAME}'
// Retrieve GIT version `git describe --tags --long --dirty=-dirty` (used to inject version in backend via Version.h)
sh '. ${REPOSITORY_PATH:-$(git rev-parse --show-toplevel)}/.env && echo ${VIEWER_VERSION} > .viewer_version'
VIEWER_VERSION = readFile('.viewer_version').trim()
sh 'rm .viewer_version'
}}}
}
// Build frontend
stage('Build: js') {
node('master && docker') { dir(path: workspacePath) { wrap([$class: 'AnsiColorBuildWrapper']) {
sh 'scripts/ci/ciBuildFrontend.sh'
}}}
}
// Publish temporary frontend so we can embed it within orthanc plugin
stage('Publish: js -> AWS (commitId)') {
node('master && docker') { dir(path: workspacePath) { wrap([$class: 'AnsiColorBuildWrapper']) {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'aws-orthanc.osimis.io']]) {
sh 'scripts/ci/ciPushFrontend.sh tagWithCommitId'
}
}}}
}
def buildMap = [:]
// Build windows
if (userInput['buildWindows']) {
buildMap.put('windows', {
stage('Build: windows') {
node('windows && vs2015') { dir(path: workspacePath) {
// Clean up workspace first on non development branches as
// well as development branches with visual studio. We do
// this because visual studio seems to keep AUTOGENERATED
// c++ binary object file cache even when the corresponding
// frontend folder has changed. Thus, we enforce it to be
// rebuilt.
deleteDir()
//stage('Retrieve sources') {}
checkout scm
//stage('Build C++ Windows plugin') {}
bat "cd scripts & cd ci & powershell.exe ./ciBuildWindows.ps1 %BRANCH_NAME% ${VIEWER_VERSION} build"
}}
}
})
}
// Build osx
if (userInput['buildOSX']) {
buildMap.put('osx', {
stage('Build: osx') {
node('osx && xcode') { dir(path: workspacePath) {
// Clean up workspace first on non development branches
if (!isUserDevBranch) {
deleteDir()
}
//stage('Retrieve sources') {}
checkout scm
//stage('Build C++ OSX plugin') {}
sh "cd scripts/ci && ./ciBuildOSX.sh $BRANCH_NAME ${VIEWER_VERSION} build"
}}
}
})
}
// Build docker & launch tests
if (userInput['buildDocker']) {
buildMap.put('docker', {
stage('Build: LSB') {
node('master && docker') { dir(path: workspacePath) { wrap([$class: 'AnsiColorBuildWrapper']) {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'aws-orthanc.osimis.io']]) {
sh 'scripts/ci/ciBuildLsb.sh'
}
}}}
}
})
}
parallel(buildMap)
// Deploy docker image
if (userInput['buildDocker']) {
stage('Deploy: docker demo') {
node('master && docker') { dir(path: workspacePath) { wrap([$class: 'AnsiColorBuildWrapper']) {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'aws-orthanc.osimis.io']]) {
Random random = new Random();
// Set subnet (divide by 16 for /28 mask - `bash -c` because dash doesn't support $RANDOM)
def demoSubnet = sh(
script: 'bash -c \'echo "10.$(($RANDOM % 256)).$(($RANDOM % 256)).$(($RANDOM % (256 / 16) * 16))/28"\'',
returnStdout: true
).trim()
// Chose random port
// @todo remove DEMO_PORT from setEnv
int minPort = 20000
int maxPort = 40000
int demoPort = random.nextInt(maxPort - minPort + 1) + minPort;
// Build demo
sh 'scripts/ci/setEnv.sh ${BRANCH_NAME}'
sh "demo/scripts/buildDocker.sh"
// Load docker registry (required by docker-compose)
docker.withRegistry('https://index.docker.io/v1/', 'dockerhub-jenkinsosimis') {
// Set docker-compose project name
def dockerProject = "wvb_demo_${BRANCH_NAME}"
// Stop previous demo (if already exists)
sh "SUBNET=${demoSubnet} PORT=${demoPort} docker-compose -p ${dockerProject} down || true"
// Start demo
sh "SUBNET=${demoSubnet} PORT=${demoPort} docker-compose -p ${dockerProject} up -d orthanc_populated"
}
// Retrieve ticket number
def ticketNumber = '?'
if (isUserDevBranch) {
try {
ticketNumber = ((env.BRANCH_NAME =~ /.+(?:\-|\/)(\w+\-\d+).*/)[0][1])
} catch(err) {
// ignore incompatible branch name
}
}
// Send message on slack with address
slackSend color: '#800080', message: "wvb: ${BRANCH_NAME} deployed.\n- http://qa.wvb.osidev.net:${demoPort}"
}
}}}
}
}
// Wait for docker build (& integration tests) before running publishing scripts
// ...
def publishMap = [:]
// Publish osx release
if (userInput['buildOSX']) {
publishMap.put('osx', {
stage('Publish: osx') {
node('osx') { dir(path: workspacePath) {
//stage('Retrieve sources') {}
checkout scm
//stage('Publish C++ OSX plugin') {}
sh "cd scripts/ci && ./ciBuildOSX.sh $BRANCH_NAME ${VIEWER_VERSION} publish"
}}
}
})
}
// Publish windows release
if (userInput['buildWindows']) {
publishMap.put('windows', {
stage('Publish: C++ Windows plugin') {
node('windows && vs2015') { dir(path: workspacePath) {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'aws-orthanc.osimis.io']]) {
bat "cd scripts & cd ci & powershell.exe ./ciBuildWindows.ps1 %BRANCH_NAME% ${VIEWER_VERSION} publish"
}
}}
}
})
}
// note: the LSB is published directly. We do not publish the osimis/orthanc-webviewer-plugin docker image anymore
parallel(publishMap)
// Publish js code for in-lify integration (until we use iframe) & wvp usage as a library
stage('Publish: js -> AWS (release)') {
node('master && docker') { dir(path: workspacePath) { wrap([$class: 'AnsiColorBuildWrapper']) {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'aws-orthanc.osimis.io']]) {
sh 'scripts/ci/ciPushFrontend.sh tagWithReleaseTag'
}
}}}
}
// Clean up
stage('Clean up') {
node('master && docker') { dir(path: workspacePath) { wrap([$class: 'AnsiColorBuildWrapper']) {
sh 'scripts/ci/ciLogDockerState.sh postbuild'
sh 'scripts/ci/ciCleanup.sh'
}}}
}
}