Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploys: Update WP theme paths for multisite subsites #854

Merged
merged 3 commits into from
Sep 20, 2017

Conversation

fullyint
Copy link
Contributor

This PR is the final piece of the former #848 and addresses https://discourse.roots.io/t/multisite-subsite-using-twentyfifteen-theme/9871/5. This PR enables Trellis deploys to update template_root and stylesheet_root WP options also for multisite subsites, not just the primary site.

To disable: Multisite operators who wish to avoid the processing time may define update_wp_theme_paths: false in a group_vars file or on the fly:

ansible-playbook deploy.yml -e env=production -e site=example.com -e update_wp_theme_paths=false

Implementation notes

xargs for multisite. See also https://danielbachhuber.com/tip/run-wp-cli-command-wordpress-multisite/

bool filter is necessary for proper interpretation of cli -e update_wp_theme_paths=false (otherwise the var remains a string "false" interpreted as boolean true).

select statement in with_subelements limits the items executed instead of via the when condition. This prevents skipped output, which could otherwise be very lengthy if an installation has many subsites. Consider a multisite installation with only two sites. When one site is changed and one is skipped, this PR's output contains only this:

TASK [deploy : Update WP theme paths] *************************************************************
changed: [test] => (item=({'option': 'template_root'}, u'http://test2.example.test/ /srv/www/exampl
e.com/releases/20170730231750/web/wp/wp-content/themes'))

changed: [test] => (item=({'option': 'stylesheet_root'}, u'http://test2.example.test/ /srv/www/exam
ple.com/releases/20170730231750/web/wp/wp-content/themes'))

Compare output from using a when condition instead of the select statement in with_subelements:

TASK [deploy : Update WP theme paths] *************************************************************
skipping: [test] => (item=({'_ansible_parsed': True, 'stderr_lines': [], '_ansible_item_result': Tr
ue, u'end': u'2017-07-30 23:18:16.665821', '_ansible_no_log': False, u'stdout': u'http://example.te
st/wp/ \nhttp://test2.example.test/ /srv/www/example.com/releases/20170730190452/web/wp/wp-content/
themes', u'cmd': u' wp site list --field=url | xargs -I {} bash -c \'export url="{}"; echo -n "$url
 " && wp option get template_root --skip-plugins --skip-themes --url=$url || echo\'\n ', u'rc': 0, 
'item': u'template_root', u'delta': u'0:00:01.619913', u'stderr': u'', u'changed': False, u'invocat
ion': {u'module_args': {u'warn': True, u'executable': None, u'chdir': u'/srv/www/example.com/curren
t', u'_raw_params': u' wp site list --field=url | xargs -I {} bash -c \'export url="{}"; echo -n "$
url " && wp option get template_root --skip-plugins --skip-themes --url=$url || echo\'\n ', u'remov
es': None, u'creates': None, u'_uses_shell': True}}, 'failed_when_result': False, u'start': u'2017-
07-30 23:18:15.045908', 'failed': False}, u'http://example.test/wp/ '))

changed: [test] => (item=({'_ansible_parsed': True, 'stderr_lines': [], '_ansible_item_result': Tru
e, u'end': u'2017-07-30 23:18:16.665821', '_ansible_no_log': False, u'stdout': u'http://example.tes
t/wp/ \nhttp://test2.example.test/ /srv/www/example.com/releases/20170730190452/web/wp/wp-content/t
hemes', u'cmd': u' wp site list --field=url | xargs -I {} bash -c \'export url="{}"; echo -n "$url 
" && wp option get template_root --skip-plugins --skip-themes --url=$url || echo\'\n ', u'rc': 0, '
item': u'template_root', u'delta': u'0:00:01.619913', u'stderr': u'', u'changed': False, u'invocati
on': {u'module_args': {u'warn': True, u'executable': None, u'chdir': u'/srv/www/example.com/current
', u'_raw_params': u' wp site list --field=url | xargs -I {} bash -c \'export url="{}"; echo -n "$u
rl " && wp option get template_root --skip-plugins --skip-themes --url=$url || echo\'\n ', u'remove
s': None, u'creates': None, u'_uses_shell': True}}, 'failed_when_result': False, u'start': u'2017-0
7-30 23:18:15.045908', 'failed': False}, u'http://test2.example.test/ /srv/www/example.com/releases
/20170730190452/web/wp/wp-content/themes'))

skipping: [test] => (item=({'_ansible_parsed': True, 'stderr_lines': [], '_ansible_item_result': Tr
ue, u'end': u'2017-07-30 23:18:19.421725', '_ansible_no_log': False, u'stdout': u'http://example.te
st/wp/ \nhttp://test2.example.test/ /srv/www/example.com/releases/20170730190452/web/wp/wp-content/
themes', u'cmd': u' wp site list --field=url | xargs -I {} bash -c \'export url="{}"; echo -n "$url 
" && wp option get stylesheet_root --skip-plugins --skip-themes --url=$url || echo\'\n ', u'rc': 0
, 'item': u'stylesheet_root', u'delta': u'0:00:01.708665', u'stderr': u'', u'changed': False, u'inv
ocation': {u'module_args': {u'warn': True, u'executable': None, u'chdir': '/srv/www/example.com/cu
rrent', u'_raw_params': u' wp site list --field=url | xargs -I {} bash -c \'export url="{}"; echo -
n "$url " && wp option get stylesheet_root --skip-plugins --skip-themes --url=$url || echo\'\n ', u
'removes': None, u'creates': None, u'_uses_shell': True}}, 'failed_when_result': False, u'start': u
'2017-07-30 23:18:17.713060', 'failed': False}, u'http://example.test/wp/ '))

changed: [test] => (item=({'_ansible_parsed': True, 'stderr_lines': [], '_ansible_item_result': Tru
e, u'end': u'2017-07-30 23:18:19.421725', '_ansible_no_log': False, u'stdout': u'http://example.tes
t/wp/ \nhttp://test2.example.test/ /srv/www/example.com/releases/20170730190452/web/wp/wp-content/t
hemes', u'cmd': u' wp site list --field=url | xargs -I {} bash -c \'export url="{}"; echo -n "$url 
" && wp option get stylesheet_root --skip-plugins --skip-themes --url=$url || echo\'\n ', u'rc': 0,
 'item': u'stylesheet_root', u'delta': u'0:00:01.708665', u'stderr': u'', u'changed': False, u'invo
cation': {u'module_args': {u'warn': True, u'executable': None, u'chdir': u'/srv/www/example.com/cur
rent', u'_raw_params': u' wp site list --field=url | xargs -I {} bash -c \'export url="{}"; echo -n
 "$url " && wp option get stylesheet_root --skip-plugins --skip-themes --url=$url || echo\'\n ', u
'removes': None, u'creates': None, u'_uses_shell': True}}, 'failed_when_result': False, u'start': u
'2017-07-30 23:18:17.713060', 'failed': False}, u'http://test2.example.test/ /srv/www/example.com/re
leases/20170730190452/web/wp/wp-content/themes'))

The above is for two sites only. Imagine output above for a multisite installation with 50+ subsites.

Enables Trellis deploys to update template_root and stylesheet_root
WP options also for multisite subsites, not just the primary site.
Multisite operators who wish to avoid the processing time may define
`update_wp_theme_paths: false`

Limits targets via `select` statement in `with_subelements` instead of
via the `when` condition. This prevents `skipped` output, which could
otherwise be very lengthy if an installation has many subsites.
After new release path is symlinked, sites that need WP theme paths
updated won't load until updated. This commit shuffles tasks to
make the update take place immediately after the symlink change.
WP options template_root and stylesheet_root will not exist for
a site when no theme has been activated explicitly, when a site
defaults to a theme like twentyseventeen. In this case, WP consults
the _site_transient_theme_roots transient for the path to the theme.
This transient contains release paths that do not update on deploy,
leading to WSOD due to various instances of "No such file or directory."
This commit avoids the problem by removing the transient immediately
after the new release path is symlinked. WP auto-regenerates the
transient with correct paths.
@fullyint
Copy link
Contributor Author

I added two commits:

Deploys: Minimize delay in updating WP theme paths

After a new release path is symlinked, sites that need WP theme paths updated won't load until updated, a window of 1-10+ seconds. Thanks @karex for pointing this out.

This commit shuffles tasks so the update task runs as quickly as possible after symlink change.

Remove WP transient _site_transient_theme_roots during deploys

WP options template_root and stylesheet_root will not exist for a site when no theme has been activated explicitly, when a site defaults to a theme like twentyseventeen. In this case, WP consults the _site_transient_theme_roots transient for the path to the theme. This transient contains release paths that do not update on deploy, leading to WSOD due to various instances of "No such file or directory." Original examination in #275 (comment).

This commit avoids the problem by removing the _site_transient_theme_roots transient immediately after the new release path is symlinked. WP regenerates the transient with correct paths as needed.

Copy link
Member

@swalkinshaw swalkinshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@fullyint fullyint merged commit 56defd3 into master Sep 20, 2017
@fullyint fullyint deleted the wp-theme-paths-multisite branch September 20, 2017 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants