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

Deploy command hooks #305

Closed
swalkinshaw opened this issue Aug 16, 2015 · 3 comments
Closed

Deploy command hooks #305

swalkinshaw opened this issue Aug 16, 2015 · 3 comments
Milestone

Comments

@swalkinshaw
Copy link
Member

Right now our deploy command "hooks" are limited to strings that get passed into the command or shell module. This means we can't really take advantage of Ansible modules at all.

This leads to issues like #282 with non-ideal solutions.

Instead we could include task files for each hook:

# roles/deploy/tasks/main.yml
- name: Run post_finalize_tasks
  include: hooks/post-deploy.yml
# roles/deploy/tasks/hooks/post-deploy.yml
- name: Restart php-fpm
  shell: sudo php5-fpm reload
  when: not hhvm

- name: Restart hhvm
  shell: sudo hhvm restart
  when: hhvm

/cc @cfxd @louim @fullyint

@louim
Copy link
Contributor

louim commented Aug 16, 2015

That is an excellent Idea. Moreover, project_deploy_module got a refactor and it got renamed to project_deploy: https://github.com/f500/ansible-project_deploy. They now include hook like you propose. With a little refactor we could use theses.

Quick example from the docs: project_deploy_hook_on_perform_build: "{{ playbook_dir }}/deploy_hooks/perform-build.yml"

@swalkinshaw
Copy link
Member Author

Wow that's hilarious. They even named the dir hooks. I was just thinking earlier I should see if that project had been updated since I hadn't looked in a long time.

@swalkinshaw swalkinshaw added this to the 1.0.0 milestone Aug 16, 2015
swalkinshaw added a commit that referenced this issue Oct 9, 2015
This implements proper hook files with Ansible tasks as discussed in #305.

This feature is heavily borrowed/stolen from https://github.com/f500/ansible-project_deploy with a few differences.

This PR separates outs the `main.yml` tasks file into multiple files. Each file represents a "step" in the deploy flow. And for each step we have `before` and `after` hooks available.

The steps are:

1. `initialize`
2. `update`
3. `prepare`
4. `build`
5. `share`
6. `finalize`

Also note that technically the `after` hook of one step and the `before` hook of the following step are the same. However I wanted to include the `before`/`after` nomenclature for semantic reasons mostly. Also so it's more obvious *when* the hook is run. The f500 project uses hooks like `project_deploy_hook_on_initialize` which, in my opinion, could be a little confusing as to where/when exactly it's happening.

Hooks available:

* `deploy_initialize_before`
* `deploy_initialize_after`
* `deploy_update_before`
* `deploy_update_after`
* `deploy_prepare_before`
* `deploy_prepare_after`
* `deploy_build_before`
* `deploy_build_after`
* `deploy_share_before`
* `deploy_share_after`
* `deploy_finalize_before`
* `deploy_finalize_after`

Those are all variables which can be defined to override the default. Right now only `deploy_build_after` and `deploy_finalize_after` have corresponding hook files to replicate functionality we previously had in the commands.
@swalkinshaw
Copy link
Member Author

Fixed by #378

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

3 participants