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

Check if deploy hook files exist before including them #755

Closed
5 of 6 tasks
arashohadi opened this issue Feb 14, 2017 · 3 comments
Closed
5 of 6 tasks

Check if deploy hook files exist before including them #755

arashohadi opened this issue Feb 14, 2017 · 3 comments

Comments

@arashohadi
Copy link

Submit a feature request or bug report


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

  • site1.com uses gulp to build my assets
  • site2.com uses webpack to build my assets
  • site3.com does not have a need for a build workflow

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.


Feature Request

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!

@swalkinshaw
Copy link
Member

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.

@arashohadi
Copy link
Author

I understand the concerns for performance. If I can help in any way, just let me know.

@swalkinshaw
Copy link
Member

This will be covered by #815 as a nice bonus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants