/
deploy.sh
executable file
·88 lines (76 loc) · 2.49 KB
/
deploy.sh
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
#!/bin/bash
set -ex
# JOB_NAME environment variable must be set. We count on Hudson for this.
controlScript=$WORKSPACE/resources/continuous-integration/deploy/jetty7x/control.sh
lastStableWAR=$WORKSPACE/../lastStable/org.mifos\$mifos-war/archive/org.mifos/mifos-war/*/*.war
deployRoot=$HOME/deploys/mifos-$JOB_NAME-deploy
targetWARlocation=$deployRoot/jetty7x/webapps/mifos.war
dbProperties=$WORKSPACE/db/target/release/db/mifos-db.properties
dbPropertiesTemplate=$WORKSPACE/db/target/release/db/mifos-db-template.properties
expandScript=$WORKSPACE/db/target/release/db/bin/expand_db.sh
contractScript=$WORKSPACE/db/target/release/db/bin/contract_db.sh
liquibaseScript=$WORKSPACE/db/target/release/db/bin/liquibase.sh
chmod +x $controlScript
chmod +x $expandScript
chmod +x $contractScript
chmod +x $liquibaseScript
function cUrl {
# If TEST_SERVER_PORT is set by Hudson, we can test if the deployed test server
# is online. Using parameterized builds the the preferred means for setting
# TEST_SERVER_PORT.
if [[ -n "$TEST_SERVER_PORT" ]]; then
can_hit_test_server=1
while [[ $can_hit_test_server -ne 0 ]]
do
# The purpose of this sleep is twofold:
# 1) on the first iteration, give tomcat a second to start up.
# 2) thereafter, pause between loop iterations so we don't exhaust
# resources on birch if some unforseen problem occurs.
sleep 1
set +e # or a failure would stop the script prematurely
curl --fail --location http://ci.mifos.org:$TEST_SERVER_PORT/mifos/
can_hit_test_server=$?
done
fi
}
function updateDbProperties {
sed "s/@USERNAME@/$USERNAME/g;
s/@PASSWORD@/$PASSWORD/g;
s/@SCHEMA_NAME@/$SCHEMA_NAME/g;
s/@DB_HOST@/$DB_HOST/g;
s/@DB_PORT@/$DB_PORT/g" $dbPropertiesTemplate > $dbProperties
}
function deployMifos {
rm -f $deployRoot/jetty7x/logs/*
rm -rf $deployRoot/jetty7x/webapps/mifos
cp $lastStableWAR $targetWARlocation
}
function startJetty {
$controlScript start
}
function stopJetty {
$controlScript stop
}
function doExpansion {
$expandScript
}
function doContraction {
$contractScript
}
# Test the previous version of application against new db
stopJetty
updateDbProperties
doExpansion
startJetty
cUrl
# Test new version of application against new db
stopJetty
deployMifos
startJetty
cUrl
# Test new version of application after contraction
stopJetty
updateDbProperties
doContraction
startJetty
cUrl