-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.xml
238 lines (212 loc) · 12.4 KB
/
deploy.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
<?xml version="1.0" encoding="UTF-8"?>
<project name="tama" basedir=".">
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="lib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<typedef resource="org/motechproject/build/deployMacroDefs.xml">
<classpath>
<pathelement location="lib/motech-delivery-ops-0.3-SNAPSHOT.jar"/>
</classpath>
</typedef>
<property file="${basedir}/properties/${env}/deploy.properties"/>
<property file="${basedir}/properties/${env}/ivr.properties"/>
<!-- *********************** DOWNLOAD ARTIFACTS************************* -->
<target name="download.tama.from.hudson">
<echo message="Downloading TAMA from http://${hudson.server}:${hudson.port}/job/${hudson.job.name}/${hudson.build.number}/org.motechproject.tama$tama/artifact/org.motechproject.tama/tama/${hudson.release.version}/tama-${hudson.release.version}.war"/>
<exec executable="bash" failonerror="true">
<arg file="${basedir}/scripts/download_artifact.sh"/>
<arg value="http://${hudson.server}:${hudson.port}/j_acegi_security_check"/>
<arg value="http://${hudson.server}:${hudson.port}/job/${hudson.job.name}/${hudson.build.number}/${hudson.artifact.path}/artifact/org.motechproject.tama/tama/${hudson.release.version}/tama-${hudson.release.version}.war"/>
<arg value="${download.dir}/${app.name}.war"/>
<arg value="${hudson.username}"/>
<arg value="${hudson.password}"/>
</exec>
<echo message="downloaded tama-${hudson.release.version}.war from hudson"/>
</target>
<target name="copy.tama.to.tomcat">
<copy.app.war.to.tomcat tomcat.home="${tomcat.home}" app.name="${app.name}" download.dir="${download.dir}"/>
</target>
<target name="copy.local.war">
<echo message="Deploying to tomcat at ${tomcat.url} with tomcat home ${tomcat.home}"/>
<delete dir="${tomcat.home}/webapps/${app.name}"/>
<copy file="${download.dir}/${local.war.file}" tofile="${tomcat.home}/webapps/${app.name}.war"
overwrite="true"/>
<delete dir="${tomcat.home}/work/Catalina/localhost/${app.name}"/>
</target>
<target name="start.tomcat" description="start tomcat">
<echo message="Starting tomcat..."/>
<echo message="Waiting for tomcat to start with tomcat home at ${tomcat.home}"/>
<exec executable="/sbin/service" dir="${tomcat.home}">
<arg line="${tomcat.service} start"/>
</exec>
<waitfor checkevery="100" checkeveryunit="millisecond" maxwait="2" maxwaitunit="minute" timeoutproperty="tomcat.timeout">
<http url="http://localhost:${tomcat.port}"/>
</waitfor>
<fail if="tomcat.timeout" message="Error starting up tomcat..."/>
<echo message="Tomcat started"/>
</target>
<target name="stop.tomcat" description="stop tomcat">
<echo message="Stopping tomcat..."/>
<echo message="Waiting for tomcat to stop with tomcat home at ${tomcat.home}"/>
<exec executable="/sbin/service" dir="${tomcat.home}">
<arg line="${tomcat.service} stop"/>
</exec>
<waitfor checkevery="100" checkeveryunit="millisecond" maxwait="2" maxwaitunit="minute" timeoutproperty="tomcat.timeout">
<not>
<http url="http://localhost:${tomcat.port}"/>
</not>
</waitfor>
<fail if="tomcat.timeout" message="Error shutting down tomcat..."/>
<echo message="Tomcat stopped"/>
</target>
<target name="restart.tomcat" description="restart tomcat">
<antcall target="stop.tomcat" />
<antcall target="start.tomcat" />
</target>
<path id="lib.path">
<fileset dir="${tomcat.home}/webapps/${app.name}/WEB-INF/lib" includes="**/*.jar"/>
</path>
<target name="load.seed.data">
<load.seed.data tomcat.home="${tomcat.home}" app.name="${app.name}"
couchdb.seed.main.class="${couchdb.seed.main.class}" db.name="${couchdb.tama.db.name}"/>
</target>
<target name="load.audio.seed">
<echo message="Dropping Audio files..."/>
<foreach list="motech-cmslite" target="drop.couch.db" param="dbname"/>
<echo message="Seeding audio files.."/>
<java fork="false" classname="org.motechproject.tama.refdata.seed.AudioSeed">
<classpath>
<path location="${tomcat.home}/webapps/${app.name}/WEB-INF/classes"/>
<path refid="lib.path"/>
</classpath>
</java>
<echo message="Done seeding audio files"/>
</target>
<target name="drop.audio.seed">
<drop.couch.db couch.db.server="${couchdb.server}" couch.db.port="${couchdb.port}" db.name="${couchdb.platform.cmslite.db.name}"/>
</target>
<target name="cache.audio.files.in.kookoo">
<echo message="Caching audio files.."/>
<java fork="false" classname="${cache.audio.files.main.class}">
<classpath>
<path location="${tomcat.home}/webapps/${app.name}/WEB-INF/classes"/>
<path refid="lib.path"/>
</classpath>
<arg value="${kookoo.api.key}"/>
<arg value="${content.location.url}"/>
</java>
<echo message="Done caching audio files"/>
</target>
<target name="drop.couch.db">
<drop.couch.db couch.db.server="${couchdb.server}" couch.db.port="${couchdb.port}" db.name="${dbname}"/>
</target>
<target name="drop.all.dbs">
<foreach list="${couchdb.all.dbs}" target="drop.couch.db" param="dbname"/>
</target>
<!-- *************************RECREATE QUARTZ SCHEMA************************* -->
<target name="load.quartz.schema">
<echo message="Quartz schema loading: START"/>
<path id="dependencies">
<fileset file="${project.basedir}/../lib/postgresql-9.1-901.jdbc4.jar"/>
</path>
<exec executable="dropdb" failonerror="false">
<arg line="-U ${postgres.user} ${postgres.db}"/>
</exec>
<exec executable="createdb">
<arg line="-U ${postgres.user} ${postgres.db}"/>
</exec>
<sql driver="${postgres.driver}"
url="jdbc:postgresql://${postgres.server}/${postgres.db}"
userid="${postgres.user}"
classpathref="dependencies"
password="${postgres.password}"
src="${project.basedir}/../sql/quartz_tables.sql"/>
<echo message="Quartz schema loading: END"/>
</target>
<!-- *************************SET PROPERTIES************************* -->
<target name="set.properties">
<copy overwrite="true" todir="${tomcat.home}/webapps/${app.name}/WEB-INF/classes"
file="${basedir}/properties/${env}/quartz.properties"/>
<copy overwrite="true" todir="${tomcat.home}/webapps/${app.name}/WEB-INF/classes"
file="${basedir}/properties/${env}/couchdb.properties"/>
<copy overwrite="true" todir="${tomcat.home}/webapps/${app.name}/WEB-INF/classes"
file="${basedir}/properties/${env}/seed.properties"/>
<copy overwrite="true" todir="${tomcat.home}/webapps/${app.name}/WEB-INF/classes"
file="${basedir}/properties/${env}/activemq.properties"/>
<copy overwrite="true" todir="${tomcat.home}/webapps/${app.name}/WEB-INF/classes"
file="${basedir}/properties/${env}/ivr.properties"/>
<copy overwrite="true" todir="${tomcat.home}/webapps/${app.name}/WEB-INF/classes"
file="${basedir}/properties/${env}/dailypillreminder.properties"/>
<copy overwrite="true" todir="${tomcat.home}/webapps/${app.name}/WEB-INF/classes"
file="${basedir}/properties/${env}/fourdayrecall.properties"/>
<copy overwrite="true" todir="${tomcat.home}/webapps/${app.name}/WEB-INF/classes"
file="${basedir}/properties/${env}/healthtips.properties"/>
<copy overwrite="true" todir="${tomcat.home}/webapps/${app.name}/WEB-INF/classes"
file="${basedir}/properties/${env}/timeSlot.properties"/>
<copy overwrite="true" todir="${tomcat.home}/webapps/${app.name}/WEB-INF/classes"
file="${basedir}/properties/${env}/appointments.properties"/>
<copy overwrite="true" todir="${tomcat.home}/webapps/${app.name}/WEB-INF/classes"
file="${basedir}/properties/${env}/log4j.xml"/>
<copy overwrite="true" todir="${tomcat.home}/webapps/${app.name}/WEB-INF/classes"
file="${basedir}/properties/${env}/sms-http-template.json"/>
<copy overwrite="true" todir="${tomcat.home}/webapps/${app.name}/WEB-INF/classes"
file="${basedir}/properties/${env}/tama.properties"/>
<copy overwrite="true" todir="${tomcat.home}/webapps/${app.name}/WEB-INF/classes"
file="${basedir}/properties/${env}/clinicianSMS.properties"/>
<copy overwrite="true" todir="${tomcat.home}/webapps/${app.name}/WEB-INF/classes"
file="${basedir}/properties/${env}/tamaReports.properties"/>
<copy overwrite="true" todir="${tomcat.home}/webapps/${app.name}/WEB-INF/classes"
file="${basedir}/properties/${env}/diagnostics.properties"/>
<antcall target="unwire.motech.delivery.tools"/>
</target>
<target name="unwire.motech.delivery.tools">
<if>
<equals arg1="${with.tools}" arg2="true" />
<then>
<echo message="TAMA tools installed." />
</then>
<else>
<echo message="Removing TAMA tools." />
<delete failonerror="false">
<fileset dir="${tomcat.home}/webapps/${app.name}/WEB-INF/lib"
includes="motech-job-handler-invoker*"/>
<fileset dir="${tomcat.home}/webapps/${app.name}/WEB-INF/lib"
includes="motech-datetime-simulator*"/>
</delete>
<copy overwrite="true" todir="${tomcat.home}/webapps/${app.name}/WEB-INF/classes"
file="${basedir}/properties/${env}/placeholderPluginContext.xml"/>
</else>
</if>
<if>
<equals arg1="${env}" arg2="prod" />
<then>
<echo message="Removing emulator." />
<delete failonerror="false" includeemptydirs="true">
<fileset dir="${tomcat.home}/webapps/${app.name}" includes="emulator/**" defaultexcludes="false"/>
</delete>
</then>
<else>
<echo message="Emulator installed." />
</else>
</if>
</target>
<!-- *************************DEPLOY TARGETS************************* -->
<target name="deploy.tama.from.hudson.and.reset.db"
depends="stop.tomcat, drop.all.dbs, load.quartz.schema, download.tama.from.hudson, copy.tama.to.tomcat, start.tomcat, set.properties, load.seed.data, restart.tomcat"
description="Deploy TAMA by 1) fetching artifact from hudson, 2) recreate tama-web couchdb database with seed data 3) clearing quartz jobdatastore 4) set properties for war"/>
<target name="deploy.tama.from.hudson.and.migrate.without.reset.db"
depends="stop.tomcat, download.tama.from.hudson, copy.tama.to.tomcat, start.tomcat, set.properties, drop.audio.seed, load.audio.seed, load.seed.data, restart.tomcat"/>
<target name="deploy.tama.from.hudson.and.reset.audio.data"
depends="stop.tomcat, download.tama.from.hudson, copy.tama.to.tomcat, start.tomcat, set.properties, drop.audio.seed, load.audio.seed, restart.tomcat"/>
<target name="deploy.tama.from.hudson"
depends="stop.tomcat, download.tama.from.hudson, copy.tama.to.tomcat, start.tomcat, set.properties, restart.tomcat"
description="Deploy TAMA from hudson without recreating database and seed data"/>
<target name="deploy.tama.from.local.and.reset.db"
depends="stop.tomcat, drop.all.dbs, load.quartz.schema, copy.local.war, start.tomcat, set.properties, load.seed.data, restart.tomcat"
description="Deploy TAMA from locally downloaded war(set 'local.war.file' in deploy.properties) in artifacts folder. Also recreates the TAMA database."/>
<target name="deploy.tama.from.local"
depends="stop.tomcat, copy.local.war, start.tomcat, set.properties, restart.tomcat"
description="Deploy TAMA from locally downloaded war(set 'local.war.file' in deploy.properties) in artifacts folder without recreating database and seed data"/>
</project>