-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.xml
313 lines (261 loc) · 13.1 KB
/
build.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
<?xml version="1.0" encoding="UTF-8" ?>
<project name="SRS" basedir="." default="main">
<property name="tempDir" value="temp"/>
<target name="main" description="Runs tests and prepares deployable tarball">
<exec executable="composer" passthru="true">
<arg value="install"/>
</exec>
<phingcall target="static-analysis"/>
<phingcall target="coding-standard"/>
<exec executable="php">
<arg value="www/index.php"/>
<arg value="orm:validate-schema"/>
<arg value="--skip-sync"/>
</exec>
<phingcall target="tests"/>
</target>
<target name="prepare-tarball" description="Prepares deployable tarball with everything built">
<exec executable="git" outputProperty="build.hash">
<arg line="rev-parse --short HEAD"/>
</exec>
<property name="build.dir" value="${tempDir}/builds/${build.hash}"/>
<exec executable="yarn" passthru="true">
<arg value="install"/>
</exec>
<exec executable="yarn" passthru="true">
<arg value="build"/>
</exec>
<delete dir="${build.dir}"/>
<mkdir dir="${build.dir}"/>
<copy todir="${build.dir}">
<fileset dir=".">
<include name="app/**"/>
<include name="backup/**"/>
<include name="log/**"/>
<include name="migrations/**"/>
<include name="temp/**"/>
<include name="vendor/**"/>
<include name="www/**"/>
<include name="composer.*"/>
<exclude name="app/config/*local.neon"/>
<exclude name="**/.gitignore"/>
</fileset>
</copy>
<property environment="env"/>
<copy file="./app/config/production.local.neon" tofile="${build.dir}/app/config/local.neon">
<filterchain>
<replacetokens begintoken="__" endtoken="__">
<token key="CONFIG_SKAUTIS_APPLICATION_ID" value="${env.CONFIG_SKAUTIS_APPLICATION_ID}"/>
<token key="CONFIG_SKAUTIS_TEST_MODE" value="${env.CONFIG_SKAUTIS_TEST_MODE}"/>
<token key="CONFIG_DATABASE_HOST" value="${env.CONFIG_DATABASE_HOST}"/>
<token key="CONFIG_DATABASE_USER" value="${env.CONFIG_DATABASE_USER}"/>
<token key="CONFIG_DATABASE_PASSWORD" value="${env.CONFIG_DATABASE_PASSWORD}"/>
<token key="CONFIG_DATABASE_NAME" value="${env.CONFIG_DATABASE_NAME}"/>
<token key="CONFIG_MAIL_SMTP" value="${env.CONFIG_MAIL_SMTP}"/>
<token key="CONFIG_MAIL_HOST" value="${env.CONFIG_MAIL_HOST}"/>
<token key="CONFIG_MAIL_PORT" value="${env.CONFIG_MAIL_PORT}"/>
<token key="CONFIG_MAIL_USERNAME" value="${env.CONFIG_MAIL_USERNAME}"/>
<token key="CONFIG_MAIL_PASSWORD" value="${env.CONFIG_MAIL_PASSWORD}"/>
<token key="CONFIG_MAIL_SECURE" value="${env.CONFIG_MAIL_SECURE}"/>
<token key="CONFIG_MAILING_SENDER_EMAIL" value="${env.CONFIG_MAILING_SENDER_EMAIL}"/>
<token key="CONFIG_RECAPTCHA_SITE_KEY" value="${env.CONFIG_RECAPTCHA_SITE_KEY}"/>
<token key="CONFIG_RECAPTCHA_SECRET_KEY" value="${env.CONFIG_RECAPTCHA_SECRET_KEY}"/>
</replacetokens>
<expandproperties/>
</filterchain>
</copy>
<exec executable="composer" passthru="true">
<arg value="--working-dir=${build.dir}"/>
<arg value="install"/>
<arg value="--no-interaction"/>
<arg value="--optimize-autoloader"/>
<arg value="--classmap-authoritative"/>
<arg value="--no-dev"/>
</exec>
<delete>
<fileset dir="${build.dir}">
<!-- Temp files -->
<include name="temp/**"/>
<!-- Logs -->
<include name="log/**"/>
<!-- Webloader -->
<include name="www/webtemp/**"/>
<exclude name="**/.htaccess"/>
</fileset>
</delete>
<tar destfile="${build.dir}.tar.gz" compression="gzip">
<fileset dir="${tempDir}/builds">
<include name="${build.hash}/**"/>
</fileset>
</tar>
<delete dir="${build.dir}"/>
</target>
<target name="deploy:ssh">
<echo message="${comment}..."/>
<echo message="${command}"/>
<ssh host="${deploy.ssh.host}" port="${deploy.ssh.port}" username="${deploy.ssh.username}" privkeyfile="id_rsa"
pubkeyfile="id_rsa.pub" command="${command}"/>
</target>
<target name="deploy:copy-tarball">
<echo message="Copying ${file} to ${toDirectory}"/>
<scp host="${deploy.ssh.host}" port="${deploy.ssh.port}" username="${deploy.ssh.username}" privkeyfile="id_rsa"
pubkeyfile="id_rsa.pub" file="${file}" todir="${toDirectory}"/>
</target>
<target name="deploy:cleanup">
<ssh host="${deploy.ssh.host}" port="${deploy.ssh.port}" username="${deploy.ssh.username}" privkeyfile="id_rsa"
pubkeyfile="id_rsa.pub" command="ls ${deploy.releasesDir}" property="allReleases"/>
<exec executable="bash" outputProperty="previousReleases" checkreturn="true">
<arg value="-c"/>
<arg line='"echo '${allReleases}' | grep -v '^${deploy.releaseHash}$' | tr '\n' ' '"'/>
</exec>
<phingcall target="deploy:ssh">
<property name="comment" value="Deleting files"/>
<property name="command" value="cd ${deploy.releasesDir} && rm -rf ${previousReleases}"/>
</phingcall>
</target>
<target name="deploy">
<tstamp/>
<!-- Prepare variables -->
<property environment="env"/>
<property name="deploy.workDir" refid="env.DEPLOY_DIRECTORY"/>
<property name="deploy.lebeda" refid="env.DEPLOY_LEBEDA"/>
<property name="deploy.ssh.host" refid="env.DEPLOY_SSH_HOST"/>
<property name="deploy.ssh.port" refid="env.DEPLOY_SSH_PORT"/>
<property name="deploy.ssh.username" refid="env.DEPLOY_SSH_USERNAME"/>
<exec executable="git" outputProperty="build.hash">
<arg line="rev-parse --short HEAD"/>
</exec>
<property name="deploy.releasesDir" value="${deploy.workDir}/releases"/>
<property name="deploy.releaseHash" value="${DSTAMP}-${TSTAMP}-${build.hash}"/>
<property name="deploy.release" value="${deploy.releasesDir}/${deploy.releaseHash}"/>
<property name="tarball" value="${deploy.release}.tar.gz"/>
<!-- Build tarball -->
<phingcall target="prepare-tarball">
<property name="build.hash" value="${deploy.releaseHash}"/>
</phingcall>
<phingcall target="deploy:ssh">
<property name="comment" value="Creating releases directory if not exists"/>
<property name="command" value="mkdir -p ${deploy.releasesDir}"/>
</phingcall>
<phingcall target="deploy:copy-tarball">
<property name="file" value="${tempDir}/builds/${deploy.releaseHash}.tar.gz"/>
<property name="toDirectory" value="${deploy.releasesDir}"/>
</phingcall>
<phingcall target="deploy:ssh">
<property name="comment" value="Extracting tarball to release directory"/>
<property name="command" value="tar -xzf ${tarball} -C ${deploy.releasesDir}"/>
</phingcall>
<phingcall target="deploy:ssh">
<property name="comment" value="Removing tarball"/>
<property name="command" value="rm ${tarball}"/>
</phingcall>
<phingcall target="deploy:ssh">
<property name="comment" value="Copying custom CSS"/>
<property name="command"
value="cp ${deploy.workDir}/www/css/web/style.css ${deploy.release}/www/css/web || true"/>
</phingcall>
<phingcall target="deploy:ssh">
<property name="comment" value="Copying old log directory"/>
<property name="command" value="cp -r ${deploy.workDir}/www/../log ${deploy.release} || true"/>
</phingcall>
<phingcall target="deploy:ssh">
<property name="comment" value="Copying old backup directory"/>
<property name="command" value="cp -r ${deploy.workDir}/www/../backup ${deploy.release} || true"/>
</phingcall>
<phingcall target="deploy:ssh">
<property name="comment" value="Copying old img directory"/>
<property name="command" value="cp -r ${deploy.workDir}/www/img ${deploy.release}/www || true"/>
</phingcall>
<phingcall target="deploy:ssh">
<property name="comment" value="Copying old files directory"/>
<property name="command" value="cp -r ${deploy.workDir}/www/files ${deploy.release}/www || true"/>
</phingcall>
<phingcall target="deploy:ssh">
<property name="comment" value="Setting access rights for temp directory"/>
<property name="command" value="chmod -R 777 ${deploy.release}/temp"/>
</phingcall>
<phingcall target="deploy:ssh">
<property name="comment" value="Setting access rights for log directory"/>
<property name="command" value="chmod -R 777 ${deploy.release}/log"/>
</phingcall>
<phingcall target="deploy:ssh">
<property name="comment" value="Setting access rights for backup directory"/>
<property name="command" value="chmod -R 777 ${deploy.release}/backup"/>
</phingcall>
<phingcall target="deploy:ssh">
<property name="comment" value="Setting access rights for files directory"/>
<property name="command" value="chmod -R 777 ${deploy.release}/www/files"/>
</phingcall>
<phingcall target="deploy:ssh">
<property name="comment" value="Setting access rights for webtemp directory"/>
<property name="command" value="chmod -R 777 ${deploy.release}/www/webtemp"/>
</phingcall>
<phingcall target="deploy:app-command">
<property name="comment" value="Generating doctrine proxies"/>
<property name="command" value="orm:generate-proxies"/>
</phingcall>
<phingcall target="deploy:app-command">
<property name="comment" value="Backing up database"/>
<property name="command" value="app:database:backup"/>
</phingcall>
<phingcall target="deploy:app-command">
<property name="comment" value="Running database migrations"/>
<property name="command" value="migrations:migrate --no-interaction"/>
</phingcall>
<phingcall target="deploy:ssh">
<property name="comment" value="Swapping release to ${deploy.releaseHash}"/>
<property name="command"
value="rm -rf ${deploy.workDir}/www && ln -s ${deploy.release}/www ${deploy.workDir}/www"/>
</phingcall>
<phingcall target="deploy:cleanup"/>
</target>
<target name="deploy:app-command">
<condition property="phpCommand"
value="php83-cli "${deploy.release}/www/console.php ${command}""
else="php8.3 ${deploy.release}/www/console.php ${command}">
<equals arg1="${deploy.lebeda}" arg2="true"/>
</condition>
<phingcall target="deploy:ssh">
<property name="command" value="${phpCommand}"/>
</phingcall>
</target>
<target name="tests-unit">
<exec executable="vendor/bin/codecept" passthru="true" checkreturn="true">
<arg value="run"/>
<arg value="unit"/>
</exec>
</target>
<target name="tests-integration">
<exec executable="vendor/bin/codecept" passthru="true" checkreturn="true">
<arg value="run"/>
<arg value="integration"/>
</exec>
</target>
<target name="tests-performance">
<exec executable="vendor/bin/codecept" passthru="true" checkreturn="true">
<arg value="run"/>
<arg value="performance"/>
</exec>
</target>
<target name="tests">
<phingcall target="tests-unit"/>
<phingcall target="tests-integration"/>
</target>
<target name="tests-with-coverage">
<exec executable="php" passthru="true" checkreturn="true">
<arg value="-d zend_extension=xdebug.so"/>
<arg value="-d xdebug.mode=coverage"/>
<arg value="vendor/bin/codecept"/>
<arg value="run"/>
<arg value="unit,integration"/>
<arg value="--coverage-xml"/>
</exec>
</target>
<target name="static-analysis">
<phpstan executable="vendor/bin/phpstan" command="analyse" passthru="true" checkReturn="true" paths="app"
configuration="phpstan.neon" level="6" noProgress="true" memoryLimit="1024M"/>
</target>
<target name="coding-standard">
<exec executable="vendor/bin/phpcs" passthru="true" checkreturn="true"/>
</target>
</project>