-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ant
283 lines (227 loc) · 9.5 KB
/
build.ant
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
<!--
Rhizi build targets
-->
<project name="rhizi-server"
default="pkg-deb"
xmlns:if="ant:if"
xmlns:unless="ant:unless">
<macrodef name="rsync">
<attribute name="src" />
<attribute name="dst" />
<attribute name="extraOpts" default="" />
<sequential>
<exec dir="${basedir}" executable="/usr/bin/rsync" failonerror="true">
<arg line="-avz @{extraOpts}" />
<arg value="@{src}" />
<arg value="@{dst}" />
<!-- note: RSYNC_CONNECT_PROG has not effect when dst is local dir path -->
<env key="RSYNC_CONNECT_PROG"
value="ssh root@%H nc 127.0.0.1 873" />
</exec>
</sequential>
</macrodef>
<macrodef name="scp_macro"
description="a .ssh/config aware scp invocation macro">
<!-- user arg intentionally unsupported, rely on .ssh/config -->
<attribute name="src" />
<attribute name="todir" />
<attribute name="remotehost" />
<attribute name="extraOpts" default="" />
<sequential>
<exec dir="${basedir}" executable="/usr/bin/scp" failonerror="true">
<arg line="@{extraOpts}" />
<arg line="@{src}" />
<arg value="@{remotehost}:@{todir}" />
</exec>
</sequential>
</macrodef>
<macrodef name="client-optimize">
<attribute name="root" />
<attribute name="build" />
<sequential>
<exec dir="@{root}" executable="/usr/bin/r.js" failonerror="true">
<arg line="-o @{build}" />
</exec>
</sequential>
</macrodef>
<macrodef name="generate_version_tag">
<attribute name="outputDir" />
<sequential>
<exec dir="${basedir}"
executable="/usr/bin/git"
output="@{outputDir}/version.txt">
<arg line="describe" />
</exec>
</sequential>
</macrodef>
<property name="buildDir" value="build" />
<property name="deploy_target_dir" value="deploy-local" />
<property name="remoteDeployServer" value="rz-0.unige.ch" />
<property name="targetDomain"
value="default"
description="controls the source of domain fragments" />
<property name="doClientOptimize" value="false" />
<property name="localServerUseSymlink" value="true" />
<property name="fragmentd_root_path" value="res/local" />
<tstamp>
<format property="versionQualifier" pattern="yyyyMMddHHmm" />
</tstamp>
<target name="clean" description="remove all work folders">
<delete dir="dist" />
<delete dir="${buildDir}" />
</target>
<target name="deploy-local.clean">
<symlink action="delete" link="${deploy_target_dir}/static/fragment.d" />
<symlink action="delete" link="${deploy_target_dir}/bin" />
<symlink action="delete" link="${deploy_target_dir}/rhizi" />
<delete verbose="true" includeemptydirs="true">
<fileset dir="${deploy_target_dir}"
includes="**/*"
defaultexcludes="false"
followsymlinks="false" />
</delete>
</target>
<target name="deploy-local"
depends="deploy-local.clean"
description="locally deploy webapp">
<!-- [!] trailing '/' on rsync src targets critical -->
<local name="fragment_d_path" />
<property name="fragment_d_path"
value="${deploy_target_dir}/fragment.d" />
<mkdir dir="${deploy_target_dir}" />
<mkdir dir="${deploy_target_dir}/etc" />
<mkdir dir="${deploy_target_dir}/static" />
<parallel>
<!-- client code -->
<rsync src="client/" dst="${deploy_target_dir}/static/js" />
<!-- [!] use absolute paths on all symlink targets -->
<symlink if:true="${localServerUseSymlink}"
action="single"
link="${deploy_target_dir}/bin"
resource="${basedir}/bin" />
<symlink if:true="${localServerUseSymlink}"
action="single"
link="${deploy_target_dir}/rhizi"
resource="${basedir}/rhizi" />
<symlink if:true="${localServerUseSymlink}"
action="single"
link="${deploy_target_dir}/static/fragment.d"
resource="${basedir}/${fragment_d_path}" />
<rsync unless:true="${localServerUseSymlink}"
src="rhizi/"
dst="${deploy_target_dir}/bin" />
<!-- conf -->
<copy file="res/etc/rhizi-server.conf"
tofile="${deploy_target_dir}/etc/rhizi-server.conf" />
<!-- res -->
<rsync src="res/client/" dst="${deploy_target_dir}/static" />
<!-- auth -->
<copy file="res/etc/user_db.db"
tofile="${deploy_target_dir}/user_db.db"
failonerror="false" />
<!-- default fragments: templates -->
<rsync src="${fragmentd_root_path}/" dst="${fragment_d_path}" />
</parallel>
<client-optimize if:true="${doClientOptimize}"
root="client/"
build="build.js" />
<parallel>
<!-- requires default fragment rsync to have finished -->
<generate_version_tag outputdir="${fragment_d_path}/template.d" />
<replaceregexp file="${deploy_target_dir}/static/js/app.js">
<regexp pattern="\$\{fragment_d_path\}" />
<substitution expression="/static/fragment.d" />
</replaceregexp>
</parallel>
</target>
<target name="deploy-remote" depends="deploy-local">
<!-- [!] trailing '/' on rsync src targets critical -->
<local name="rsync_module" />
<property name="rsync_module" value="rhizi.net" />
<property name="filter_list_str"
value="-f '- __pycache__/' -f '- *.pyc'" />
<client-optimize if:true="${doClientOptimize}"
root="client/"
build="build.js" />
<!-- -l: traverse bin/ -> ../src-py link -->
<rsync src="${deploy_target_dir}/"
extraopts="--delete -lL ${filter_list_str}"
dst="rsync://${remoteDeployServer}/${rsync_module}/rhizi.net/" />
<parallel>
<!-- apply production patches -->
<rsync extraopts="--delete"
src="res/production-patch-set/${targetDomain}/rhizi-server.production.conf"
dst="rsync://${remoteDeployServer}/${rsync_module}/rhizi.net/etc/rhizi-server.conf" />
<rsync src="bin"
dst="rsync://${remoteDeployServer}/${rsync_module}/" />
</parallel>
</target>
<target name="pkg-deb__mux" description="package as .deb">
<antcall target="pkg-deb__common">
<!-- FIXME: use rhizi-mux -->
<param name="package_name" value="rhizi-mux" />
<param name="pkg_variant" value="rhizi-mux" />
</antcall>
</target>
<target name="pkg-deb__single" description="package as .deb">
<antcall target="pkg-deb__common">
<param name="package_name" value="rhizi" />
<param name="pkg_variant" value="rhizi-single" />
</antcall>
</target>
<target name="pkg-deb__common" depends="clean" description="package as .deb">
<fail unless="pkg_variant" />
<fail unless="package_name" />
<property name="pkg_version" value="0.3.5" />
<property name="pkg_debname" value="${package_name}_${pkg_version}" />
<property name="pkg_fullname" value="${package_name}-${pkg_version}" />
<property name="build_dir__deb_pkg"
value="${buildDir}/deb-pkg__${pkg_variant}/${pkg_fullname}" />
<mkdir dir="dist" />
<mkdir dir="${build_dir__deb_pkg}" />
<exec dir="${basedir}" executable="/usr/bin/git">
<arg value="clone" />
<arg line="--depth 1" />
<arg value="file://${basedir}" />
<arg value="${build_dir__deb_pkg}" />
</exec>
<copy todir="${build_dir__deb_pkg}/debian">
<fileset dir="res/debian/pkg__rhizi-common" />
<fileset dir="res/debian/pkg__${pkg_variant}" />
</copy>
<!-- set debian/control package name -->
<replaceregexp file="${build_dir__deb_pkg}/debian/control">
<regexp pattern="\$\{package-name\}" />
<substitution expression="${package_name}" />
</replaceregexp>
<replaceregexp file="${build_dir__deb_pkg}/client/app.js">
<regexp pattern="\$\{fragment_d_path\}" />
<substitution expression="/fragment.d" />
</replaceregexp>
<!-- generate version fragment -->
<generate_version_tag outputdir="${build_dir__deb_pkg}/${fragmentd_root_path}/template.d" />
<delete verbose="true" includeemptydirs="true">
<fileset dir="${build_dir__deb_pkg}" includes="Makefile" />
<fileset dir="${build_dir__deb_pkg}" includes="**/*.scss" />
<!-- TODO: use when depending on libjs-jquery, libjs-underscore
<fileset file="${build_dir__deb_pkg}/res/client/lib/jquery.js" />
<fileset file="${build_dir__deb_pkg}/res/client/lib/underscore.js" />
-->
</delete>
<!-- debuild flags:
-b: binary-only build
-us: do not sign the source package
-uc: do not sign .changes
-->
<exec dir="${build_dir__deb_pkg}" executable="/usr/bin/debuild">
<arg value="-b" />
<arg value="-us" />
<arg value="-uc" />
</exec>
</target>
<target name="pkg-deb.list">
<exec executable="/usr/bin/dpkg">
<arg line="-c ${buildDir}/${pkg_debname}_amd64.deb" />
</exec>
</target>
</project>