-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.gradle
285 lines (249 loc) · 9.12 KB
/
build.gradle
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
plugins {
id "com.bmuschko.docker-remote-api" version "6.7.0"
}
// Tasks and configuration related to building Orbeon
ant.importBuild('orbeon/build.xml') { antTargetName -> 'orbeon-' + antTargetName }
def orbeonCommitHash() {
def cmd = "git show -s --format=git%h --abbrev=7"
def hash = null
try {
def proc = cmd.execute(null, file("${rootDir}/orbeon"))
hash = proc.text.trim()
} catch (Exception e) {
println("Could not execute git command: " + e.message)
hash = null
}
return hash
}
// Orbeon variables
ext.orbeonHash = orbeonCommitHash();
ext.vanillaOrbeonWarName = "orbeon-${ant.properties['version.number']}${ant.properties['edition']}-${orbeonHash}.war"
ext.orbeonFilterJarName = "orbeon-xforms-filter-${ant.properties['version.number']}${ant.properties['edition']}-${orbeonHash}.jar"
ext.orbeonAntWarTasks = ['orbeon-exits-task', 'orbeon-exist-import-sample-data-to-build', 'orbeon-orbeon-dist-war']
/*
** This was required for building Orbeon Forms 2021.1CE, however is not required in the 2020.1.5CE version.
** We use the 2020.1.5CE version currently, as it is the last one compatible with JAVA 8, which MISP2
** itself uses.
tasks
.matching { task -> task.name.startsWith('orbeon-') }
.each { task -> task.doFirst {
if (System.getenv('GITHUB_TOKEN') == null) {
throw new GradleException('Orbeon builds require the environmental variable "GITHUB_TOKEN" to be set to a GitHub ' +
'token with access to repositories allowed so that it can download private dependencies')
}
}
}
*/
tasks
.matching { task -> orbeonAntWarTasks.contains(task.name) }
.each { task -> task.outputs.upToDateWhen {
file("${buildDir}/${vanillaOrbeonWarName}").exists()
}
}
tasks.getByName('orbeon-war-common').outputs.upToDateWhen {
file("${buildDir}/${vanillaOrbeonWarName}").exists() ||
file("${buildDir}/${orbeonFilterJarName}").exists()
}
tasks.getByName('orbeon-xforms-filter-jar').outputs.file('orbeon/build/lib/orbeon-xforms-filter.jar')
tasks.register('buildVanillaOrbeonWar') {
dependsOn('orbeon-orbeon-dist-war')
outputs.file(layout.buildDirectory.file(vanillaOrbeonWarName))
doLast {
copy {
from "orbeon/build/distrib/${ant.properties['versioned-name']}.war"
into layout.buildDirectory
rename {
vanillaOrbeonWarName
}
}
}
}
tasks.register('buildOrbeonFilter') {
dependsOn('orbeon-xforms-filter-jar')
outputs.file(layout.buildDirectory.file(orbeonFilterJarName))
doLast {
copy {
from 'orbeon/build/lib/orbeon-xforms-filter.jar'
into layout.buildDirectory
rename {
orbeonFilterJarName
}
}
}
}
tasks.register('clean'){
dependsOn('orbeon-mega-clean')
doLast {
delete buildDir
}
}
// Tasks for installing components to the docker-compose development environment
// Not type of Copy because it causes issues with the docker volume specified as output
tasks.register('deployDevOrbeon') {
dependsOn(':orbeon-war:war')
outputs.file('docker-dev/webapps/orbeon.war')
outputs.upToDateWhen { false }
doLast {
copy {
from tasks.getByPath(':orbeon-war:war').outputs.files.singleFile
into 'docker-dev/webapps'
}
}
}
tasks.register('deployDevMisp') {
dependsOn(':web-app:devWar')
outputs.file('docker-dev/webapps/misp2.war')
outputs.upToDateWhen { false }
doLast {
copy {
from tasks.getByPath(':web-app:devWar').outputs.files.singleFile
into 'docker-dev/webapps'
rename {
'misp2.war'
}
}
}
}
tasks.register('deployDevAdminTool') {
dependsOn(':admin-tool:shadowJar')
outputs.file('docker-dev/utils/AdminTool.jar')
outputs.upToDateWhen { false }
doLast {
copy {
from tasks.getByPath(':admin-tool:shadowJar').outputs.files.singleFile
into 'docker-dev/utils'
}
}
}
// Utility functions for integration tests
// Used to check if the integration environment MISP2 is operational
boolean checkMisp2ITRunning() {
def connection = new URL('http://localhost:9090/misp2').openConnection()
connection.requestMethod = 'HEAD'
try {
connection.responseCode == 200
} catch (IOException error) {
false
}
}
// Tasks to run integration tests on web-app
tasks.register('createITNetwork', com.bmuschko.gradle.docker.tasks.network.DockerCreateNetwork) {
networkName = 'misp2-it-network'
}
tasks.register('pullITPostgres', com.bmuschko.gradle.docker.tasks.image.DockerPullImage) {
image = 'postgres:10-alpine'
}
tasks.register('pullITTomcat', com.bmuschko.gradle.docker.tasks.image.DockerPullImage) {
image = 'tomcat:8'
}
tasks.register('pullSeleniumDriver', com.bmuschko.gradle.docker.tasks.image.DockerPullImage) {
image = 'selenium/standalone-chrome:4.3.0'
}
tasks.register('createITPostgres', com.bmuschko.gradle.docker.tasks.container.DockerCreateContainer) {
dependsOn pullITPostgres, createITNetwork
targetImageId pullITPostgres.getImage()
hostConfig.network = createITNetwork.getNetworkId()
hostConfig.binds = ["${rootDir}/web-app/src/test/resources/db/initdb.d": "/docker-entrypoint-initdb.d"]
containerName = 'misp2-it-postgres'
envVars = [
"POSTGRES_PASSWORD": "secret",
"POSTGRES_HOST_AUTH_METHOD": "trust"
]
}
tasks.register('createITTomcat', com.bmuschko.gradle.docker.tasks.container.DockerCreateContainer) {
dependsOn pullITTomcat, createITNetwork, ':web-app:itTestWar', ':orbeon-war:war'
targetImageId pullITTomcat.getImage()
hostConfig.network = createITNetwork.getNetworkId()
hostConfig.portBindings = [
"9090:8080"
]
containerName = 'misp2-it-tomcat'
mustRunAfter ':web-app:itTestWar', ':orbeon-war:war'
}
tasks.register('createSeleniumDriver', com.bmuschko.gradle.docker.tasks.container.DockerCreateContainer) {
dependsOn pullSeleniumDriver, createITNetwork
targetImageId pullSeleniumDriver.getImage()
// Since the tests currently send requests both through to driver and JAVA HTTP client, we can't rely on
// the internal docker networking.
//hostConfig.network = createITNetwork.getNetworkId()
//hostConfig.portBindings = [
// "4444:4444"
//]
hostConfig.network = 'host' // No need to forward ports since we use the hosts network
envVars = [
"SE_VNC_NO_PASSWORD": "1",
"SE_VNC_VIEW_ONLY": "1"
]
hostConfig.shmSize = 2147483648 //https://github.com/SeleniumHQ/docker-selenium#--shm-size2g
containerName = 'misp2-it-webdriver'
}
// FIXME: For some reason inlining these in the copy task breaks the JAVA language server JDT.LS
// Maybe there is a better solution?
ext.itMisp2WarLocation = tasks.getByPath(':web-app:itTestWar').outputs.files.singleFile
ext.itOrbeon2WarLocation = tasks.getByPath(':orbeon-war:war').outputs.files.singleFile
tasks.register('copyMISPToIT', com.bmuschko.gradle.docker.tasks.container.DockerCopyFileToContainer) {
dependsOn createITTomcat
targetContainerId createITTomcat.getContainerId()
withFile("${rootDir}/web-app/src/test/resources/certs/mobiili_id_trust_store.p12", '/tmp')
withFile(itMisp2WarLocation, '/usr/local/tomcat/webapps')
withFile(itOrbeon2WarLocation, '/usr/local/tomcat/webapps')
}
tasks.register('startITPostgres', com.bmuschko.gradle.docker.tasks.container.DockerStartContainer) {
dependsOn createITPostgres
targetContainerId createITPostgres.getContainerId()
}
tasks.register('startITTomcat', com.bmuschko.gradle.docker.tasks.container.DockerStartContainer) {
dependsOn copyMISPToIT
targetContainerId createITTomcat.getContainerId()
}
tasks.register('startSeleniumDriver', com.bmuschko.gradle.docker.tasks.container.DockerStartContainer) {
dependsOn createSeleniumDriver
targetContainerId createSeleniumDriver.getContainerId()
}
tasks.register('logITTomcat', com.bmuschko.gradle.docker.tasks.container.DockerLogsContainer) {
dependsOn startITTomcat
targetContainerId createITTomcat.getContainerId()
stdErr = true
stdOut = true
}
tasks.register('test') {
dependsOn startITPostgres, logITTomcat, startSeleniumDriver
doFirst {
def url = ''
def i = 0
println "Waiting for MISP2 to start ..."
while (!checkMisp2ITRunning() && i < 10) {
sleep(5000)
i++
}
println "MISP2 is running"
}
finalizedBy 'web-app:test'
}
// Clean up docker images and network
tasks.register('removeITPostgres', com.bmuschko.gradle.docker.tasks.container.DockerRemoveContainer) {
force = true
removeVolumes = true
targetContainerId createITPostgres.getContainerId()
mustRunAfter(test)
}
tasks.register('removeITTomcat', com.bmuschko.gradle.docker.tasks.container.DockerRemoveContainer) {
force = true
removeVolumes = true
targetContainerId createITTomcat.getContainerId()
mustRunAfter(test)
}
tasks.register('removeSeleniumDriver', com.bmuschko.gradle.docker.tasks.container.DockerRemoveContainer) {
force = true
removeVolumes = true
targetContainerId createSeleniumDriver.getContainerId()
mustRunAfter(test)
}
tasks.register('removeITNetwork', com.bmuschko.gradle.docker.tasks.network.DockerRemoveNetwork) {
targetNetworkId createITNetwork.getNetworkId()
mustRunAfter(test)
}
createITNetwork.finalizedBy(removeITNetwork)
createITPostgres.finalizedBy(removeITPostgres)
createITTomcat.finalizedBy(removeITTomcat)
createSeleniumDriver.finalizedBy(removeSeleniumDriver)