Background
I have one Vagrant box to manage multiple sites (around ~25). I have refrained from using deploy hooks (mainly build_before) since I have customized build workflows between different sites and at the moment, deploy hooks are applied to all sites within one Trellis instance.
I would like to have the possibility to have customized deploy hooks per site. It would ideally look something along the lines of build-before-site1.com.yml and allow me to create new deploy files if necessary that are customized to each site.
Example
Problem
If a site does not have a deploy hook file (e.g. build-before-site3.com.yml), deploying via Ansible will fail saying that the file is missing. I could probably create an empty file to bypass the error but I have another suggestion.
What I have that is working
I have changed roles/deploy/tasks/build.yml and added a check to make sure that the deploy_build_before file (referenced in deploy.yml) exists and added a when statement to only run the deploy-hook if it exists.
- name: Build before?
local_action: stat path="{{ deploy_build_before }}"
register: build_before
- include: "{{ deploy_build_before | default('../hooks/example.yml') }}"
tags: deploy-build-before
when: build_before.stat.exists
I can then do something like this in deploy.yml
vars:
deploy_build_before: "{{ playbook_dir }}/deploy-hooks/build-before-{{ site }}.yml"
deploy_build_after: "{{ playbook_dir }}/roles/deploy/hooks/build-after.yml"
And it will give me the opportunity to have a file in the deploy-hooks folder named build-before-site1.com.yml
Other relevant information
As far as I can tell this will not affect already existing Trellis instances but only extend the flexibility that the project already has. This could/should possibly be extended to all deploy hooks (if implemented) to be consistent throughout. So this is more of a request to see if it is interesting at all to the community or if I should keep using this as a custom modification for myself.
Final note
Thank you for your amazing efforts on this project. It has helped me immensely in my work and also in my personal development!
This seems like a useful addition but I'm wary of adding this for every hook. There is a cost in terms of performance for all these tasks and it matters more for deploys which should be fast as possible.
I understand the concerns for performance. If I can help in any way, just let me know.
This will be covered by https://github.com/roots/trellis/pull/815 as a nice bonus
Most helpful comment
This seems like a useful addition but I'm wary of adding this for every hook. There is a cost in terms of performance for all these tasks and it matters more for deploys which should be fast as possible.