forked from liferay/liferay-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-test-analytics-cloud.xml
524 lines (400 loc) · 15.1 KB
/
build-test-analytics-cloud.xml
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
<?xml version="1.0"?>
<project basedir="." name="portal-test-analytics-cloud" xmlns:antelope="antlib:ise.antelope.tasks">
<import file="build-test.xml" />
<macrodef name="create-analytics-cloud-docker-compose">
<sequential>
<fail message="Please set the property ${env.DOCKER_ENABLED}." unless="env.DOCKER_ENABLED" />
<delete file="${analytics.cloud.asah.dir}/docker-compose.test.yml" />
<copy
file="${analytics.cloud.asah.dir}/docker-compose.yml"
tofile="${analytics.cloud.asah.dir}/docker-compose.test.yml"
/>
<property location="${analytics.cloud.asah.dir}/docker-compose.test.yml" name="analytics.cloud.docker.test.yaml" />
<replaceregexp
file="${analytics.cloud.docker.test.yaml}"
match="container_name: faro"
replace="container_name: ${analytics.cloud.faro.container.name}"
/>
<replaceregexp
file="${analytics.cloud.docker.test.yaml}"
match="\"8080:8080\""
replace=""${analytics.cloud.faro.dxp.port}:8080""
/>
<replaceregexp
file="${analytics.cloud.docker.test.yaml}"
match="\"9090:8080\""
replace=""${analytics.cloud.asah.trino.port}:8080""
/>
<replaceregexp
file="${analytics.cloud.docker.test.yaml}"
match="\"11311:11311\""
replace=""${analytics.cloud.faro.osgi.console.port}:11311""
/>
<replaceregexp
file="${analytics.cloud.docker.test.yaml}"
match="http://wedeploy-elasticsearch:9200"
replace="http://wedeploy-elasticsearch:${analytics.cloud.asah.elasticsearch.port}"
/>
<replaceregexp
file="${analytics.cloud.docker.test.yaml}"
match="\"9200:9200\""
replace=""${analytics.cloud.asah.elasticsearch.port}:9200""
/>
<local name="short.hostname" />
<propertyregex
input="${env.HOSTNAME}"
override="true"
property="short.hostname"
regexp="(cloud-[^\.]+|test-\d+-\d+-\d+)(\.lax\.liferay\.com)?"
replace="\1"
/>
<if>
<isset property="short.hostname" />
<then>
<echo append="true" file="${analytics.cloud.docker.test.yaml}"><![CDATA[
networks:
default:
external:
name: ${short.hostname}]]></echo>
</then>
</if>
</sequential>
</macrodef>
<macrodef name="print-analytics-cloud-logs">
<sequential>
<property location="${analytics.cloud.asah.dir}/docker-compose.test.yml" name="analytics.cloud.docker.test.yaml" />
<local name="container.names" />
<beanshell>
<![CDATA[
import com.liferay.jenkins.results.parser.JenkinsResultsParserUtil;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public static List getContainerNames() {
File dockerComposeFile = new File(project.getProperty("analytics.cloud.docker.test.yaml"));
if (!dockerComposeFile.exists()) {
return new ArrayList();
}
List containerNames = new ArrayList();
String content = JenkinsResultsParserUtil.read(dockerComposeFile);
Pattern pattern = Pattern.compile("container_name: (.*)");
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {
containerNames.add(matcher.group(1));
}
return containerNames;
}
project.setProperty("container.names", JenkinsResultsParserUtil.join(",", getContainerNames()))
]]>
</beanshell>
<local name="docker.logs.dir" />
<condition else="/tmp/docker-logs" property="docker.logs.dir" value="${env.BUILD_DIR}/docker-logs">
<and>
<isset property="env.BUILD_DIR" />
<isset property="env.BUILD_USER_CONTENT_URL" />
</and>
</condition>
<mkdir dir="${docker.logs.dir}" />
<for list="${container.names}" param="container.name">
<sequential>
<local name="container.file.name" />
<beanshell>
<![CDATA[
public int getRetryCount() {
String retryCount = project.getProperty("analytics.cloud.retry.count");
if (retryCount.matches("\\d+")) {
return Integer.valueOf(retryCount);
}
return 3;
}
for (int i = 0; i < getRetryCount(); i++) {
String containerFileName = "@{container.name}.log";
if (i > 0) {
containerFileName = "@{container.name}." + i + ".log";
}
File containerFile = new File(project.getProperty("docker.logs.dir"), containerFileName);
if (containerFile.exists()) {
continue;
}
project.setProperty("container.file.name", containerFileName);
break;
}
]]>
</beanshell>
<execute failonerror="false">
<![CDATA[
docker logs @{container.name} > ${docker.logs.dir}/${container.file.name}
]]>
</execute>
<if>
<isset property="env.BUILD_USER_CONTENT_URL" />
<then>
<echo>${env.BUILD_USER_CONTENT_URL}/docker-logs/${container.file.name}</echo>
</then>
<else>
<print-file file.name="${docker.logs.dir}/${container.file.name}" />
</else>
</if>
</sequential>
</for>
</sequential>
</macrodef>
<macrodef name="pull-docker-image-dependencies">
<attribute default="" name="analytics.cloud.image.names.excludes" />
<attribute name="analytics.cloud.repository.dir" />
<sequential>
<local name="analytics.cloud.image.names.excludes" />
<property name="analytics.cloud.image.names.excludes" value="@{analytics.cloud.image.names.excludes}" />
<beanshell>
<![CDATA[
import com.liferay.jenkins.results.parser.JenkinsResultsParserUtil;
String excludedImageNames = project.getProperty("analytics.cloud.image.names.excludes");
JenkinsResultsParserUtil.pullDockerImageDependencies(new File("@{analytics.cloud.repository.dir}"), excludedImageNames.split(","));
]]>
</beanshell>
</sequential>
</macrodef>
<macrodef name="start-analytics-cloud">
<sequential>
<fail message="Please set the property ${env.DOCKER_ENABLED}." unless="env.DOCKER_ENABLED" />
<create-analytics-cloud-docker-compose />
<property location="${analytics.cloud.asah.dir}/docker-compose.test.yml" name="analytics.cloud.docker.test.yaml" />
<local name="analytics.cloud.faro.build.gradle" />
<condition else="${analytics.cloud.faro.dir}/build.gradle" property="analytics.cloud.faro.build.gradle" value="${analytics.cloud.faro.dir}/build-ext.gradle">
<available file="${analytics.cloud.faro.dir}/build-ext.gradle" />
</condition>
<replaceregexp
file="${analytics.cloud.faro.build.gradle}"
match="def dockerContainerId = \"([^\"]+)\""
replace="def dockerContainerId = \"${analytics.cloud.faro.container.name}\""
/>
<replaceregexp
file="${analytics.cloud.faro.build.gradle}"
match="network \"([^\"]+)\""
replace="network \"${analytics.cloud.project.name}_default\""
/>
<replaceregexp
file="${analytics.cloud.faro.dir}/osb-faro-docker/local/Dockerfile"
match="FARO_URL=http://localhost:8080"
replace="FARO_URL=${analytics.cloud.faro.frontend.url}"
/>
<echo file="${analytics.cloud.asah.dir}/local.env">OSB_ASAH_BACKEND_URL=${analytics.cloud.asah.backend.url}
OSB_ASAH_POSTGRESQL_ENABLED=false
OSB_ASAH_PUBLISHER_URL=${analytics.cloud.asah.publisher.url}
OSB_FARO_FRONTEND_URL=${analytics.cloud.faro.frontend.url}</echo>
<if>
<equals arg1="${analytics.cloud.asah.build}" arg2="true" />
<then>
<pull-docker-image-dependencies
analytics.cloud.image.names.excludes="${analytics.cloud.asah.image.names.excludes}"
analytics.cloud.repository.dir="${analytics.cloud.asah.dir}"
/>
<execute dir="${analytics.cloud.asah.dir}">
./gradlew jar -Dliferay.ci=true
./gradlew clean assemble -Dliferay.ci=true
docker-compose --file=${analytics.cloud.docker.test.yaml} --project-name=${analytics.cloud.project.name} build
</execute>
</then>
</if>
<if>
<equals arg1="${analytics.cloud.faro.build}" arg2="true" />
<then>
<pull-docker-image-dependencies
analytics.cloud.image.names.excludes="${analytics.cloud.faro.image.names.excludes}"
analytics.cloud.repository.dir="${analytics.cloud.faro.dir}"
/>
<local name="portal.gradlew" />
<property location="${project.dir}/gradlew" name="portal.gradlew" />
<loadfile
property="analytics.cloud.docker.test.yaml.content"
srcfile="${analytics.cloud.docker.test.yaml}"
/>
<propertyregex
input="${analytics.cloud.docker.test.yaml.content}"
override="true"
property="analytics.cloud.faro.tag.name"
regexp="[\S\s]*image: (liferay\/com-liferay-osb-faro\:[^\s]+)[\S\s]*"
replace="\1"
/>
<execute dir="${analytics.cloud.faro.dir}">
${portal.gradlew} createDocker -Pcom.liferay.osb.faro.environment.name=local -Dliferay.ci=true
docker tag ${analytics.cloud.faro.image.name} ${analytics.cloud.faro.tag.name}
docker rm ${analytics.cloud.faro.container.name}
</execute>
</then>
</if>
<property location="${analytics.cloud.asah.dir}/start_analytics_cloud.sh" name="analytics.cloud.start.sh" />
<echo file="${analytics.cloud.start.sh}">
#!/bin/bash
touch local.env
docker-compose --file=${analytics.cloud.docker.test.yaml} --project-name=${analytics.cloud.project.name} up --detach
while [[ -n $(docker ps | grep "health: starting") ]] || [[ -n $(docker ps | grep "unhealthy") ]]
do
echo "Waiting for docker compose to be healthy."
sleep 30
done
while [[ -z $(docker logs ${analytics.cloud.faro.container.name} | grep "Completed demo data creation") ]]
do
echo "Waiting for faro to startup."
sleep 15
done
docker logs ${analytics.cloud.faro.container.name}
docker container prune -f
docker image prune -f
docker volume prune -f
</echo>
<trycatch>
<try>
<retry retrycount="${analytics.cloud.retry.count}" retrydelay="30000">
<sequential>
<trycatch property="analytics.cloud.error">
<try>
<local name="analytics.cloud.start.result" />
<exec dir="${analytics.cloud.asah.dir}" executable="/bin/bash" resultproperty="analytics.cloud.start.result" timeout="${analytics.cloud.start.timeout}">
<arg value="${analytics.cloud.start.sh}" />
</exec>
<if>
<not>
<equals arg1="${analytics.cloud.start.result}" arg2="0" />
</not>
<then>
<fail message="Failed to start Analytics Cloud with error code ${analytics.cloud.start.result}." />
</then>
</if>
</try>
<catch>
<print-analytics-cloud-logs />
<stop-analytics-cloud />
<fail message="${analytics.cloud.error}" />
</catch>
</trycatch>
</sequential>
</retry>
</try>
<catch>
<echo>Failed to create Analytics Cloud demo data.</echo>
<fail message="${analytics.cloud.error}" />
</catch>
</trycatch>
<delete file="${analytics.cloud.start.sh}" />
</sequential>
</macrodef>
<macrodef name="start-analytics-cloud-integration">
<sequential>
<fail message="Please set the property ${env.DOCKER_ENABLED}." unless="env.DOCKER_ENABLED" />
<replaceregexp
file="${analytics.cloud.asah.dir}/docker-compose.integration-test.yml"
match="\"9200:9200\""
replace=""${analytics.cloud.asah.elasticsearch.port}:9200""
/>
<local name="short.hostname" />
<propertyregex
input="${env.HOSTNAME}"
override="true"
property="short.hostname"
regexp="(cloud-[^\.]+|test-\d+-\d+-\d+)(\.lax\.liferay\.com)?"
replace="\1"
/>
<if>
<isset property="short.hostname" />
<then>
<echo append="true" file="${analytics.cloud.asah.dir}/docker-compose.integration-test.yml"><![CDATA[
networks:
default:
external:
name: ${short.hostname}]]></echo>
</then>
</if>
<pull-docker-image-dependencies
analytics.cloud.image.names.excludes="${analytics.cloud.asah.image.names.excludes}"
analytics.cloud.repository.dir="${analytics.cloud.asah.dir}"
/>
<execute dir="${analytics.cloud.asah.dir}">
docker-compose -f docker-compose.integration-test.yml up -d
docker ps
</execute>
<exec executable="/bin/bash" outputproperty="network.ip.address">
<arg value="-c" />
<arg value="docker inspect ${short.hostname} -f '{{range .NetworkSettings.Networks}}{{.Gateway}}{{end}}'" />
</exec>
<echo file="${analytics.cloud.asah.dir}/temp-build-ext.gradle">import org.apache.tools.ant.taskdefs.condition.Os
subprojects {
tasks.withType(Test) {
doFirst {
environment "LCP_ENGINE_ELASTICSEARCH_SERVER_IP", "${network.ip.address}"
environment "LCP_PROJECT_ID", "test"
environment "POSTGRESQL_SERVER_IP", "test_postgresql"
environment "OSB_ASAH_BIG_QUERY_URL", "http://${network.ip.address}:9050"
environment "OSB_ASAH_PUBSUB_EMULATOR_URL", "http://${network.ip.address}:8095"
environment "OSB_ASAH_REDIS_URL", "http://${network.ip.address}:6379"
environment.remove("GOOGLE_APPLICATION_CREDENTIALS")
}
maxHeapSize = "4096m"
}
}
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
subprojects {
afterEvaluate {
project.tasks.withType(Test) {
environment "DOCKER_COMPOSE_LOCATION", "C:/Program Files/Docker/Docker/resources/bin/docker-compose.exe"
environment "DOCKER_LOCATION", "C:/Program Files/Docker/Docker/resources/bin/docker.exe"
}
}
}
}</echo>
<copy
file="${analytics.cloud.asah.dir}/temp-build-ext.gradle"
tofile="${analytics.cloud.asah.dir}/build-ext.gradle"
/>
<execute dir="${analytics.cloud.asah.dir}">
docker ps
docker network ls
docker network inspect ${short.hostname}
cat build-ext.gradle
./gradlew testIntegration
</execute>
</sequential>
</macrodef>
<macrodef name="stop-analytics-cloud">
<sequential>
<fail message="Please set the property ${env.DOCKER_ENABLED}." unless="env.DOCKER_ENABLED" />
<create-analytics-cloud-docker-compose />
<property location="${analytics.cloud.asah.dir}/docker-compose.test.yml" name="analytics.cloud.docker.test.yaml" />
<execute dir="${analytics.cloud.asah.dir}">
docker ps -a
touch local.env
docker-compose --file=${analytics.cloud.docker.test.yaml} --project-name=${analytics.cloud.project.name} down --volumes
docker container prune -f
docker image prune -f
docker volume prune -f
</execute>
</sequential>
</macrodef>
<macrodef name="stop-analytics-cloud-integration">
<sequential>
<fail message="Please set the property ${env.DOCKER_ENABLED}." unless="env.DOCKER_ENABLED" />
<execute dir="${analytics.cloud.asah.dir}">
docker ps -a
docker-compose -f docker-compose.integration-test.yml down --volumes
docker container prune -f
docker image prune -f
docker volume prune -f
</execute>
</sequential>
</macrodef>
<target name="start-analytics-cloud">
<stop-analytics-cloud />
<start-analytics-cloud />
</target>
<target name="start-analytics-cloud-integration">
<stop-analytics-cloud-integration />
<start-analytics-cloud-integration />
</target>
<target name="stop-analytics-cloud">
<print-analytics-cloud-logs />
<stop-analytics-cloud />
</target>
<target name="stop-analytics-cloud-integration">
<print-analytics-cloud-logs />
<stop-analytics-cloud-integration />
</target>
</project>