-
Notifications
You must be signed in to change notification settings - Fork 3
436 lines (386 loc) · 17.2 KB
/
tomcat-deploy.yml
File metadata and controls
436 lines (386 loc) · 17.2 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
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
name: Tomcat Deployment Test
on:
push:
branches: [ main, master, develop ]
pull_request:
branches: [ main, master, develop ]
workflow_dispatch:
jobs:
build-and-deploy-tomcat:
name: Build WARs and Deploy to Tomcat
runs-on: ubuntu-latest
permissions:
contents: read
services:
postgres:
image: postgres:12
env:
POSTGRES_DB: treebasedb
POSTGRES_USER: treebase_user
POSTGRES_PASSWORD: treebase_pass
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
- name: Configure Maven settings for better reliability
run: |
mkdir -p ~/.m2
cat > ~/.m2/settings.xml << 'EOF'
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<id>default</id>
<properties>
<downloadSources>false</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
</properties>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>default</activeProfile>
</activeProfiles>
</settings>
EOF
- name: Configure database properties for building
run: |
mkdir -p /tmp/mesquite
# Create jdbc.properties for treebase-core
cat > treebase-core/src/main/resources/jdbc.properties << EOF
jdbc.driverClassName=org.postgresql.Driver
jdbc.url=jdbc:postgresql://localhost:5432/treebasedb
jdbc.username=treebase_user
jdbc.password=treebase_pass
mesquite.folder_dir=/tmp/mesquite
EOF
# Create context.xml for treebase-web
cat > treebase-web/src/main/webapp/META-INF/context.xml << EOF
<?xml version="1.0" encoding="UTF-8"?>
<Context reloadable="true">
<Resource name="jdbc/TreebaseDB" auth="Container"
type="javax.sql.DataSource"
description="The JNDI DataSource for the Treebase postgres instance."
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/treebasedb"
username="treebase_user"
password="treebase_pass"
maxActive="20" maxIdle="10" maxWait="-1" />
<Environment name="tb2/MesquiteFolder" value="/tmp/mesquite"
type="java.lang.String" override="false"
description="Absolute path to the directory where headless Mesquite is unpacked on the host system."/>
<Environment name="tb2/SiteUrl" value="http://localhost:8080/treebase-web/"
type="java.lang.String" override="false"
description="The base URL from which this Treebase instance is served."/>
<Environment name="tb2/PurlBase" value="http://purl.org/phylo/treebase/phylows/"
type="java.lang.String" override="false"
description="The base URL of a PURL service that redirects to this Treebase instance."/>
<Environment name="tb2/SmtpHost" value="localhost"
type="java.lang.String" override="false"
description="Host name of an SMTP server that your instance can use without authentication."/>
</Context>
EOF
# Create jdbc.properties for OAI-PMH data provider
mkdir -p oai-pmh_data_provider/data_provider_web/src/main/resources
cat > oai-pmh_data_provider/data_provider_web/src/main/resources/jdbc.properties << EOF
jdbc.driverClassName=org.postgresql.Driver
jdbc.url=jdbc:postgresql://localhost:5432/treebasedb
jdbc.username=treebase_user
jdbc.password=treebase_pass
mesquite.folder_dir=/tmp/mesquite
EOF
# Create context.xml for OAI-PMH data provider
mkdir -p oai-pmh_data_provider/data_provider_web/src/main/webapp/META-INF
cat > oai-pmh_data_provider/data_provider_web/src/main/webapp/META-INF/context.xml << EOF
<?xml version="1.0" encoding="UTF-8"?>
<Context reloadable="true">
<Resource name="jdbc/TreebaseDB" auth="Container"
type="javax.sql.DataSource"
description="The JNDI DataSource for the Treebase postgres instance."
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/treebasedb"
username="treebase_user"
password="treebase_pass"
maxActive="20" maxIdle="10" maxWait="-1" />
<Environment name="tb2/MesquiteFolder" value="/tmp/mesquite"
type="java.lang.String" override="false"
description="Absolute path to the directory where headless Mesquite is unpacked on the host system."/>
<Environment name="tb2/SiteUrl" value="http://localhost:8080/data_provider_web/"
type="java.lang.String" override="false"
description="The base URL from which this Treebase instance is served."/>
<Environment name="tb2/PurlBase" value="http://purl.org/phylo/treebase/phylows/"
type="java.lang.String" override="false"
description="The base URL of a PURL service that redirects to this Treebase instance."/>
<Environment name="tb2/SmtpHost" value="localhost"
type="java.lang.String" override="false"
description="Host name of an SMTP server that your instance can use without authentication."/>
</Context>
EOF
- name: Initialize database schema
run: |
sudo apt-get update
sudo apt-get install -y postgresql-client
cd treebase-core/db/schema
PGPASSWORD=treebase_pass psql -h localhost -U treebase_user -d treebasedb -f init_db_uptodate.pg
- name: Build treebase-core and install to local repository
run: |
# Retry Maven build up to 3 times to handle transient Maven Central issues
for i in 1 2 3; do
echo "Build attempt $i..."
if mvn -B clean install -DskipTests -f treebase-core/pom.xml; then
echo "Build succeeded on attempt $i"
break
else
if [ $i -lt 3 ]; then
echo "Build failed on attempt $i, retrying in 10 seconds..."
sleep 10
else
echo "Build failed after 3 attempts"
exit 1
fi
fi
done
- name: Build treebase-web WAR
run: |
# Retry Maven build up to 3 times to handle transient Maven Central issues
for i in 1 2 3; do
echo "Build attempt $i..."
if mvn -B clean package -DskipTests -f treebase-web/pom.xml; then
echo "Build succeeded on attempt $i"
break
else
if [ $i -lt 3 ]; then
echo "Build failed on attempt $i, retrying in 10 seconds..."
sleep 10
else
echo "Build failed after 3 attempts"
exit 1
fi
fi
done
- name: Build OAI-PMH data provider WAR
run: |
# Retry Maven build up to 3 times to handle transient Maven Central issues
for i in 1 2 3; do
echo "Build attempt $i..."
if mvn -B clean package -DskipTests -f oai-pmh_data_provider/pom.xml; then
echo "Build succeeded on attempt $i"
break
else
if [ $i -lt 3 ]; then
echo "Build failed on attempt $i, retrying in 10 seconds..."
sleep 10
else
echo "Build failed after 3 attempts"
exit 1
fi
fi
done
- name: Verify WAR files were created
run: |
echo "Checking for treebase-web.war..."
ls -lh treebase-web/target/treebase-web.war
echo "Checking for data_provider_web.war..."
ls -lh oai-pmh_data_provider/data_provider_web/target/data_provider_web.war
- name: Install Tomcat 9
run: |
# Download and install Tomcat 9
cd /tmp
wget -q https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.85/bin/apache-tomcat-9.0.85.tar.gz
tar xzf apache-tomcat-9.0.85.tar.gz
export CATALINA_HOME=/tmp/apache-tomcat-9.0.85
echo "CATALINA_HOME=/tmp/apache-tomcat-9.0.85" >> $GITHUB_ENV
# Download PostgreSQL JDBC driver
wget -q -O $CATALINA_HOME/lib/postgresql-42.7.1.jar https://jdbc.postgresql.org/download/postgresql-42.7.1.jar
# Make scripts executable
chmod +x $CATALINA_HOME/bin/*.sh
- name: Deploy WAR files to Tomcat
run: |
# Copy WAR files to Tomcat webapps directory
cp treebase-web/target/treebase-web.war $CATALINA_HOME/webapps/
cp oai-pmh_data_provider/data_provider_web/target/data_provider_web.war $CATALINA_HOME/webapps/
echo "WAR files deployed to Tomcat webapps directory:"
ls -lh $CATALINA_HOME/webapps/*.war
# Copy DTD files to workspace root to fix validator configuration
# The validator XML files reference ./dtd/validator_1_3_0.dtd which gets resolved
# relative to the working directory during Spring initialization
echo "Copying DTD files to workspace root for validator..."
cp -r $GITHUB_WORKSPACE/treebase-web/src/main/webapp/WEB-INF/dtd $GITHUB_WORKSPACE/dtd
ls -la $GITHUB_WORKSPACE/dtd/
- name: Start Tomcat and deploy applications
run: |
# Set Java options for Tomcat
export JAVA_OPTS="-Djava.awt.headless=true -Xmx512m -XX:+UseG1GC"
export CATALINA_OPTS="--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED"
# Start Tomcat
JAVA_OPTS="$JAVA_OPTS" CATALINA_OPTS="$CATALINA_OPTS" $CATALINA_HOME/bin/catalina.sh start
echo "Tomcat started. Waiting for applications to deploy and initialize..."
# Wait for applications to fully deploy (60 seconds should be sufficient)
sleep 60
# Verify Tomcat is still running
if ! pgrep -f "catalina" > /dev/null; then
echo "ERROR: Tomcat process died during startup!"
echo "Showing last 100 lines of catalina.out:"
tail -100 $CATALINA_HOME/logs/catalina.out || true
exit 1
fi
echo "Tomcat is running. Applications should be deployed."
- name: Check Tomcat logs for severe errors
run: |
echo "=========================================="
echo "Checking Tomcat logs for SEVERE errors..."
echo "=========================================="
# Display summary of all log files first
echo ""
echo "All Tomcat log files:"
ls -lh $CATALINA_HOME/logs/
echo ""
# Initialize counters
TOTAL_SEVERE=0
TOTAL_ERROR=0
HAS_FAILURES=0
# Check all .log files and catalina.out
echo "Scanning all log files for errors..."
for logfile in $CATALINA_HOME/logs/*.log $CATALINA_HOME/logs/catalina.out; do
if [ -f "$logfile" ]; then
BASENAME=$(basename "$logfile")
echo ""
echo "----------------------------------------"
echo "Checking: $BASENAME"
echo "----------------------------------------"
SEVERE_COUNT=$(grep -c "SEVERE" "$logfile" 2>/dev/null || true)
ERROR_COUNT=$(grep -c " ERROR " "$logfile" 2>/dev/null || true)
# Also check for common error patterns
EXCEPTION_COUNT=$(grep -c "Exception" "$logfile" 2>/dev/null || true)
TOTAL_SEVERE=$((TOTAL_SEVERE + SEVERE_COUNT))
TOTAL_ERROR=$((TOTAL_ERROR + ERROR_COUNT))
echo " SEVERE: $SEVERE_COUNT"
echo " ERROR: $ERROR_COUNT"
echo " Exceptions: $EXCEPTION_COUNT"
# Show SEVERE errors with context
if [ $SEVERE_COUNT -gt 0 ]; then
echo ""
echo " SEVERE errors in $BASENAME:"
grep -B 3 -A 10 "SEVERE" "$logfile" 2>/dev/null | head -100 || true
HAS_FAILURES=1
fi
fi
done
# Show last 100 lines of catalina.out for full context
echo ""
echo "=========================================="
echo "Last 100 lines of catalina.out:"
echo "=========================================="
if [ -f "$CATALINA_HOME/logs/catalina.out" ]; then
tail -100 "$CATALINA_HOME/logs/catalina.out"
fi
# Final summary and exit decision
echo ""
echo "=========================================="
echo "LOG CHECK SUMMARY"
echo "=========================================="
echo "Total SEVERE errors across all logs: $TOTAL_SEVERE"
echo "Total ERROR messages across all logs: $TOTAL_ERROR"
echo ""
if [ $HAS_FAILURES -eq 1 ]; then
echo "❌ FAILED: SEVERE errors detected in Tomcat logs"
echo "Please review the errors above and the uploaded log artifacts"
echo "=========================================="
exit 1
else
echo "✓ SUCCESS: No SEVERE errors found in Tomcat logs"
echo "=========================================="
fi
- name: Test application endpoints
run: |
echo "=========================================="
echo "Testing application endpoints..."
echo "=========================================="
FAILED=0
# Test treebase-web
echo "Testing treebase-web..."
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/treebase-web/ || echo "000")
echo "treebase-web HTTP status: $HTTP_CODE"
if [ "$HTTP_CODE" = "200" ] || [ "$HTTP_CODE" = "302" ]; then
echo "✓ treebase-web is responding"
else
echo "✗ treebase-web returned unexpected status: $HTTP_CODE"
# Show error response body for debugging
echo "Response body:"
curl -s http://localhost:8080/treebase-web/ | head -100
FAILED=1
fi
# Test data_provider_web
echo "Testing data_provider_web..."
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/data_provider_web/ || echo "000")
echo "data_provider_web HTTP status: $HTTP_CODE"
if [ "$HTTP_CODE" = "200" ] || [ "$HTTP_CODE" = "302" ] || [ "$HTTP_CODE" = "404" ]; then
echo "✓ data_provider_web is deployed (status: $HTTP_CODE)"
else
echo "✗ data_provider_web returned unexpected status: $HTTP_CODE"
# Show error response body for debugging
echo "Response body:"
curl -s http://localhost:8080/data_provider_web/ | head -100
FAILED=1
fi
if [ "$FAILED" = "1" ]; then
echo "=========================================="
echo "FAILURE: One or more endpoints returned errors"
echo "=========================================="
exit 1
fi
- name: Upload Tomcat logs as artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: tomcat-logs
path: /tmp/apache-tomcat-9.0.85/logs/
retention-days: 7
- name: Shutdown Tomcat
if: always()
run: |
if [ -f "$CATALINA_HOME/bin/catalina.sh" ]; then
$CATALINA_HOME/bin/catalina.sh stop || true
sleep 5
# Force kill if still running
pkill -9 -f catalina || true
fi