forked from skaut/SRS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
276 lines (229 loc) · 12.3 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
<?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 command="composer install" passthru="true"/>
<phingcall target="static-analysis"/>
<phingcall target="coding-standard"/>
<exec command="php www/index.php orm:validate-schema --skip-sync"/>
<phingcall target="tests"/>
</target>
<target name="prepare-tarball" description="Prepares deployable tarball with everything built">
<exec command="git rev-parse --short HEAD" outputProperty="build.hash"/>
<property name="build.dir" value="${tempDir}/builds/${build.hash}"/>
<exec command="yarn install" passthru="true"/>
<exec command="yarn build" passthru="true"/>
<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 command="composer --working-dir=${build.dir} install
--no-interaction
--optimize-autoloader
--classmap-authoritative
--no-dev"
passthru="true"/>
<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}"/>
<exec command="ssh ${deploy.ssh.target} -p ${deploy.ssh.port} '${command}'" passthru="true" checkreturn="true"/>
</target>
<target name="deploy:copy-tarball">
<property name="command" value="scp -P ${port} ${file} '${target}:${toDirectory}'"/>
<echo message="Copying files to ${deploy.ssh.target}"/>
<echo message="${command}"/>
<exec command="${command}" passthru="true" checkreturn="true"/>
</target>
<target name="deploy:cleanup">
<echo message="Getting previous releases"/>
<property name="command" value="echo $(ssh -p ${deploy.ssh.port} ${deploy.ssh.target} 'ls ${deploy.releasesDir}' | grep -v '^${deploy.releaseHash}$')"/>
<echo message="${command}"/>
<exec outputProperty="previousReleases" command="${command}" checkreturn="true"/>
<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.releasesDir" value="${deploy.workDir}/releases"/>
<exec command="git rev-parse --short HEAD" outputProperty="build.hash"/>
<property name="deploy.lebeda" refid="env.DEPLOY_LEBEDA"/>
<property name="deploy.ssh.host" refid="env.DEPLOY_SSH_HOST"/>
<property name="deploy.ssh.username" refid="env.DEPLOY_SSH_USERNAME"/>
<property name="deploy.ssh.port" refid="env.DEPLOY_SSH_PORT"/>
<property name="deploy.ssh.target" value="${deploy.ssh.username}@${deploy.ssh.host}"/>
<property name="deploy.releaseHash" value="${DSTAMP}-${TSTAMP}-${build.hash}"/>
<property name="deploy.release" value="${deploy.releasesDir}/${deploy.releaseHash}"/>
<!-- 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="target" value="${deploy.ssh.target}"/>
<property name="port" value="${deploy.ssh.port}"/>
<property name="file" value="${tempDir}/builds/${deploy.releaseHash}.tar.gz"/>
<property name="toDirectory" value="${deploy.releasesDir}"/>
</phingcall>
<property name="tarball" value="${deploy.release}.tar.gz"/>
<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="php81-cli "${deploy.release}/www/console.php ${command}""
else="php8.1 ${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 command="vendor/bin/codecept run unit" passthru="true" checkreturn="true"/>
</target>
<target name="tests-integration">
<exec command="vendor/bin/codecept run integration" passthru="true" checkreturn="true"/>
</target>
<target name="tests-performance">
<exec command="vendor/bin/codecept run performance" passthru="true" checkreturn="true"/>
</target>
<target name="tests">
<phingcall target="tests-unit"/>
<phingcall target="tests-integration"/>
</target>
<target name="tests-with-coverage">
<exec command="php -d zend_extension=xdebug.so -d xdebug.mode=coverage vendor/bin/codecept run unit,integration --coverage-xml"
passthru="true" checkreturn="true"/>
</target>
<target name="static-analysis">
<exec command="php -d memory_limit=1024M vendor/bin/phpstan analyse -l 6 -c phpstan.neon app --no-progress"
passthru="true" checkreturn="true"/>
</target>
<target name="coding-standard">
<exec command="vendor/bin/phpcs" passthru="true" checkreturn="true"/>
</target>
</project>