-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdrupal.xml
477 lines (385 loc) · 18.7 KB
/
drupal.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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
<?xml version="1.0"?>
<!--
@file drupal.xml
Targets for managing Drupal.
Include this file in your build.xml with:
<import file="vendor/palantirnet/the-build/targets/drupal.xml" />
@see defaults.yml
Copyright 2016, 2018 Palantir.net, Inc.
-->
<project name="Drupal" default="drupal-build">
<fail unless="build.dir" />
<fail unless="build.env" />
<fail unless="projectname" />
<fail unless="drupal.root" />
<!--
Target: drupal-validate-clean-config
Validate that the Drupal config directory doesn't have local modifications,
to ensure consistent installation.
-->
<target name="drupal-validate-clean-config" depends="set-site" hidden="true">
<!-- Assembling this property at run time. -->
<property name="drupal.validate_clean_config.dir" value="${build.dir}/${drupal.root}/${drupal.site.config_sync_directory}" />
<!-- Use git to list local (not yet committed) changes to the config directory. -->
<exec command="git status --porcelain ${drupal.validate_clean_config.dir}" outputProperty="modified_files" />
<if>
<and>
<!-- Git output will be empty if there are no local changes. -->
<not><equals arg1="${modified_files}" arg2="" /></not>
<!-- Bypass this check with a truthy value. -->
<not><equals arg1="${drupal.validate_clean_config.bypass}" arg2="true" /></not>
</and>
<then>
<!-- Whitespace is intentional -->
<echo>Aborting install; your Drupal config directory is not clean. You may either:
Ignore this problem and re-run your phing command with the flag:
-Ddrupal.validate_clean_config.bypass=yes
- OR -
Check in your local changes:
git add ${drupal.validate_clean_config.dir}
git commit
- OR -
Clean up your config directory (destructive):
git clean -f ${drupal.validate_clean_config.dir} && git checkout -- ${drupal.validate_clean_config.dir}
</echo>
<fail message="There are local changes in your Drupal config directory." />
</then>
<elseif>
<not><equals arg1="${modified_files}" arg2="" /></not>
<then>
<!-- Whitespace is intentional -->
<echo>Continuing install with these local changes in your Drupal config directory:
${modified_files}
</echo>
</then>
</elseif>
<else>
<echo>Ready to install: no local changes to your Drupal config directory.</echo>
</else>
</if>
</target>
<!--
Target: drupal-dump-db
Generate a consistent database dump with:
- A real admin password
- The site in maintenance mode
- Structure only for cache, search, and log tables
-->
<target name="drupal-dump-db" depends="set-site" description="Generate a database dump of the site in maintenance mode with a new admin password.">
<fail unless="drupal.site.admin_user" />
<!-- prompt for a prod admin password -->
<propertyprompt propertyName="pass" promptText="Drupal admin password" defaultValue="admin" useExistingValue="true" />
<drush command="user-password">
<option name="password" value="${pass}" />
<param>${drupal.site.admin_user}</param>
</drush>
<!-- put the site in maintenance mode -->
<drush command="sset">
<param>system.maintenance_mode</param>
<param>1</param>
</drush>
<!-- get a commit label to use in the db dump name -->
<gitdescribe repository="${build.dir}" tags="true" always="true" outputProperty="git_describe_output" />
<property name="build_commit_ref" value="${git_describe_output}">
<filterchain>
<striplinebreaks />
</filterchain>
</property>
<!-- dump the database -->
<drush command="sql-dump">
<option name="structure-tables-list" value="cache,cache_*,history,search_*,sessions,watchdog" />
<option name="gzip" />
<option name="result-file" value="${build.dir}/artifacts/db-${build_commit_ref}.sql" />
</drush>
<!-- now we can go back to the worst password ever -->
<drush command="user-password">
<option name="password" value="admin" />
<param>${drupal.site.admin_user}</param>
</drush>
<!-- and take the site out of maintenance mode -->
<drush command="sset">
<param>system.maintenance_mode</param>
<param>0</param>
</drush>
</target>
<!-- Target: drupal-load-db
@todo make this more user-friendly, ESPECIALLY now that drupal site properties are nested like this!
-->
<target name="drupal-load-db" depends="set-site,drupal-has-database-connection" description="Load a database export.">
<fail unless="drupal.site.load_db.export_pattern" />
<fail unless="drupal.site.load_db.contents_command" />
<fail unless="drupal.site.load_db.mysql_command" />
<!-- If no database file is set, look for one based on the 'export_pattern'. -->
<if>
<not><isset property="drupal.site.load_db.file" /></not>
<then>
<!-- Use the last listed file that matches the drupal.site.load_db.export_pattern property -->
<exec dir="${build.dir}" command="ls ${drupal.site.load_db.export_pattern} | tail -1" outputProperty="drupal.site.load_db.discovered_file" />
<!-- ... but respect drupal.site.load_db.file if it was already set. -->
<property name="drupal.site.load_db.file" value="${drupal.site.load_db.discovered_file}" />
</then>
</if>
<!-- Validate that we've found a file to load -->
<if>
<equals arg1="${drupal.site.load_db.file}" arg2="" />
<then>
<echo>Missing database export at '${drupal.site.load_db.export_pattern}'
Please download a database export to:
${drupal.site.load_db.export_pattern}
Alternatively, you can specify the export file prefix; for example:
phing [YOUR-TARGET] -Ddrupal.site.load_db.export_pattern=artifacts/prod-*
Or, you can specify the export file directly:
phing [YOUR-TARGET] -Ddrupal.site.load_db.file=artifacts/my_db.sql.gz
</echo>
<fail message="Missing database export." />
</then>
</if>
<!-- Load the contents of the file into Drupal -->
<property name="drupal.site.load_db.command" value="${drupal.site.load_db.contents_command} ${drupal.site.load_db.file} | ${drupal.site.load_db.mysql_command}" />
<echo>$> ${drupal.site.load_db.command}</echo>
<exec dir="${build.dir}" command="${drupal.site.load_db.command}" checkreturn="true" logoutput="true" />
</target>
<!-- Target: drupal-has-database-connection
Check for a Drupal database connection. If the database doesn't exist and we have
the permissions, the database will be created.
-->
<target name="drupal-has-database-connection" depends="set-site" hidden="true">
<!-- We have to format the test query differently when using "ddev drush" vs. when using "drush" directly. -->
<property name="test_query" value="SELECT 1" />
<exec command="which ddev" returnProperty="which_ddev" />
<if>
<and>
<available file="${build.dir}/.ddev/config.yaml" />
<equals arg1="${which_ddev}" arg2="0" />
<not><isset property="env.IS_DDEV_PROJECT" /></not>
</and>
<then>
<property name="test_query" override="true">\"SELECT 1\"</property>
</then>
</if>
<trycatch>
<try>
<drush command="sql-query">
<param>${test_query}</param>
</drush>
<echo msg="Drupal database connection available." />
</try>
<catch>
<trycatch>
<try>
<!-- If there's a database and it is accessible, this code will
not be run. This code can help with setting up new
multisites, since they will use new databases that may or may
not exist yet.
-->
<drush command="sql-create" assume="yes" />
<echo msg="Drupal database connection available." />
</try>
<catch>
<fail msg="Drupal database connection not available." />
</catch>
</trycatch>
</catch>
</trycatch>
</target>
<!-- Target: drupal-install-if-no-config
Check for Drupal config, and if it's not present, offer to install Drupal.
-->
<target name="drupal-install-if-no-config" depends="set-site" hidden="true">
<if>
<!-- Check for the core.extension.yml config file, which is present in any
complete exported Drupal configuration. -->
<not><available file="${drupal.root}/${drupal.site.config_sync_directory}/core.extension.yml" /></not>
<then>
<echo>No exported Drupal config available to install from.</echo>
<!-- Prompt before installing. -->
<input propertyName="install_now" validArgs="y,n" message="Install Drupal now " promptChar="?" />
<if>
<equals arg1="${install_now}" arg2="y" />
<then>
<phing dir="${application.startdir}" target="drupal-first-install" inheritAll="false">
<property name="build.site" value="${build.site}" />
</phing>
</then>
<else>
<fail msg="Install cancelled." />
</else>
</if>
</then>
<else>
<echo msg="Nothing to do." />
</else>
</if>
</target>
<!-- Target: drupal-first-install
Scripted install and of Drupal for use when installing the-build, allowing the
installation process to create the initial Drupal config.
Technically this depends on the 'drupal-has-database-connection' target, but both
of the places where this is called from code already have separate dependencies
on that target.
-->
<target name="drupal-first-install" depends="set-site" hidden="true">
<fail unless="drupal.site.admin_user" />
<symlink link="${build.dir}/${drupal.root}/modules/contrib/the_build_utility" target="${build.thebuild.dir}/defaults/standard/modules/the_build_utility" relative="true" />
<composer command="require" composer="${composer.composer}">
<arg value="drupal/admin_toolbar" />
<arg value="drupal/config_split" />
<arg value="drupal/devel" />
<arg value="drupal/workbench" />
<arg value="drupal/workbench_tabs" />
</composer>
<drush command="site-install" assume="yes">
<option name="site-name">${projectname}</option>
<option name="account-name">${drupal.site.admin_user}</option>
<option name="account-pass">admin</option>
<param>standard</param>
</drush>
<drush command="pm-enable" assume="yes">
<param>the_build_utility</param>
</drush>
<phingcall target="drupal-change-profile">
<property name="new_profile" value="minimal" />
</phingcall>
<drush command="pm-uninstall" assume="yes">
<param>the_build_utility</param>
</drush>
<drush command="config-export" assume="yes" />
<!-- Whitespace is intentional. -->
<echo>
Drupal has been installed with the install profile "standard". If you'd prefer a different profile, run the installer yourself:
drush site-install minimal
Future installs via 'phing install' will be run using 'drush site:install --existing-config'.
Your config has been exported to ${drupal.root}/${drupal.site.config_sync_directory}</echo>
</target>
<target name="drupal-change-profile" description="Change the install profile on an existing Drupal site.">
<fail unless="new_profile" />
<!-- Get the name of the current profile. -->
<drush command="config-get" returnProperty="current_profile">
<param>core.extension</param>
<param>profile</param>
<option name="format">csv</option>
</drush>
<!-- If the current profile is enabled in the core extensions list, disable it. -->
<drush command="config-get" returnProperty="current_profile_weight">
<param>core.extension</param>
<param>module.${current_profile}</param>
<option name="format">csv</option>
</drush>
<if>
<not><equals arg1="${current_profile_weight}" arg2="" /></not>
<then>
<drush command="config-delete" assume="yes">
<param>core.extension</param>
<param>module.${current_profile}</param>
</drush>
</then>
</if>
<!-- Enable the new profile. -->
<drush command="config-set" assume="yes">
<param>core.extension</param>
<param>module.${new_profile}</param>
<param>1000</param>
</drush>
<!-- Update the profile setting itself. -->
<drush command="config-set" assume="yes">
<param>core.extension</param>
<param>profile</param>
<param>${new_profile}</param>
</drush>
</target>
<target name="drupal-add-multisite" description="Set up a new Drupal multisite.">
<if>
<equals arg1="${build.host}" arg2="pantheon" />
<then>
<fail msg="Pantheon does not support Drupal multisites." />
</then>
</if>
<!--
Prompt the user for this required information.
-->
<propertyprompt propertyName="_multisite.dir" promptText="Drupal sites subdirectory" promptCharacter=":" />
<propertyprompt propertyName="_multisite.uri" promptText="Drupal URI" promptCharacter=":" />
<!--
Set up the Drupal site directory.
-->
<phing buildfile="${build.thebuild.dir}/targets/install.xml" target="drupal-sites-directory">
<property name="drupal.site.dir" value="${_multisite.dir}" override="true" />
<property name="drupal.site.uri" value="${_multisite.uri}" override="true" />
</phing>
<!--
Add the new site to sites.php so that Drupal can route requests to the new multisite.
-->
<!-- Create sites.php for Drupal if it doesn't already exist. -->
<copy file="${build.dir}/${drupal.root}/sites/example.sites.php" tofile="${build.dir}/${drupal.root}/sites/sites.php" overwrite="false" />
<!-- Process the URI for use as a $sites key in Drupal's sites.php file. -->
<property name="_multisite.sites_php_domain" value="${_multisite.uri}">
<filterchain>
<replaceregexp>
<regexp pattern="(https?://)?(.+?)/?" replace="\2" ignoreCase="true"/>
</replaceregexp>
</filterchain>
</property>
<!-- Append the new array entry. -->
<!-- Whitespace is intentional. -->
<echo file="${build.dir}/${drupal.root}/sites/sites.php" append="true">
$sites['${_multisite.sites_php_domain}'] = '${_multisite.dir}';
</echo>
<echo msg="Added the new multisite to Drupal's sites.php file" />
<!--
Generate property configuration for the user to add to their .the-build/build.yml file.
-->
<!-- Generate a hash salt for Drupal. -->
<php expression="hash('sha256', print_r($_SERVER, TRUE))" returnProperty="_multisite.hash_salt" />
<!-- Process the directory name so that it contains a limited set of characters. -->
<property name="_multisite.key" value="${_multisite.dir}">
<filterchain>
<replaceregexp>
<regexp pattern="[^-_a-z0-9]" replace="_" ignoreCase="true"/>
</replaceregexp>
</filterchain>
</property>
<!-- Add the multisite configuration to the default build properties file. -->
<property name="_multisite.config">@multisite_placeholder@
${_multisite.key}:
dir: ${_multisite.dir}
uri: ${_multisite.uri}
hash_salt: ${_multisite.hash_salt}</property>
<reflexive file=".the-build/build.yml">
<filterchain>
<replacetokens>
<token key="multisite_placeholder" value="${_multisite.config}" />
</replacetokens>
</filterchain>
</reflexive>
<!-- If the '@multisite_placeholder@' is missing from the default properties file, the developer will have to
add the configuration manually. -->
<exec command="grep '@multisite_placeholder@' .the-build/build.yml" returnProperty="_multisite.placeholder_missing" />
<if>
<equals arg1="${_multisite.placeholder_missing}" arg2="1" />
<then>
<!-- Whitespace is intentional. -->
<echo>
To build and install this site, you need to add the following configuration to your .the-build/build.yml file:
drupal:
sites:
# ${_multisite.config}
</echo>
</then>
</if>
<!-- Add a Drush alias for the multisite. -->
<copy file="${build.thebuild.dir}/defaults/install/drush/sites/projectname.site.yml" tofile="${application.startdir}/drush/sites/${_multisite.key}.site.yml" overwrite="true">
<filterchain>
<replacetokens>
<token key="uri" value="${_multisite.uri}" />
</replacetokens>
</filterchain>
</copy>
<!-- Whitespace is intentional. -->
<echo>
Finally, you can install the new multisite with: `phing install -Dbuild.site=${_multisite.key}`
You may also need to:
* Add the domain for your new multisite to your development environment configuration
* Create a new 'profile' in your behat.yml configuration, and updating your behat.args property
* Update your .circleci/config.yml to run tests for your new multisite</echo>
</target>
</project>