Skip to content

Commit f5991d8

Browse files
committed
Added hook exaples, added hooks to tests
1 parent 0a2ae4e commit f5991d8

File tree

5 files changed

+58
-6
lines changed

5 files changed

+58
-6
lines changed

README.md

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ These are the possible role variables - you only need to have a small set define
9090
symfony_project_php_path: php
9191
symfony_project_keep_releases: 5
9292
symfony_project_git_clone_depth: 1 # uses git shallow copy
93+
symfony_project_github_oauth_token: Auth token for github rate limits
9394
symfony_project_console_opts: ''
9495
symfony_project_parameters_file: parameters.yml # optional fixed parameters file in shared
9596
symfony_project_cache_command: cache:warmup
@@ -127,7 +128,8 @@ If you need any more tasks and stuff in your deployment, you now have the option
127128
In my projects there's often e.g. a gulp task that has to be started before finishing the release. You're also free to create more folders yourself or do whatever you need.
128129
As an additional goodie, you can use the internal dynamically created facts from main role:
129130

130-
```
131+
```yaml
132+
---
131133
symfony_project_release # release timestamp
132134
symfony_current_release # release name
133135
symfony_current_release_dir # fully qualified path to release
@@ -136,7 +138,8 @@ As an additional goodie, you can use the internal dynamically created facts from
136138
```
137139
possible hooks:
138140

139-
```
141+
```yaml
142+
---
140143
symfony_project_post_folder_creation_tasks: task hook after folder creation
141144
symfony_project_pre_cache_warmup_tasks: after cache warmup
142145
symfony_project_pre_live_switch_tasks: before live symlink is switched
@@ -145,18 +148,54 @@ possible hooks:
145148

146149
These hooks trigger an include when defined.
147150
Define hooks:
148-
```
149-
symfony_project_post_folder_creation_tasks: "{{ playbook_dir }}/hooks/post_folder_creation.yml"
151+
```yaml
152+
symfony_project_post_folder_creation_tasks: "{{playbook_dir}}/hooks/post_folder_creation.yml"
150153
```
151154
The "hooks" dir should be in your deployment project as a subfolder. I'd recommend to use this name as a convention. Also it's convinient to use the name of the hook task as a yml name.
152155

156+
## hook examples
157+
These examples can be found in the package's hooks dir.
158+
159+
### php-fpm process restart
160+
E.g. restart php-fpm after successfully finishing deployment.
161+
This is much easier to maintain for different environments.
162+
163+
Create ```<your deployment>/hooks/post_live_switch.yml```:
164+
165+
```yaml
166+
---
167+
- name: hook | Restart php-fpm
168+
service: name=php5-fpm state=restarted
169+
when: symfony_project_env == "prod"
170+
```
171+
172+
### create and maintain web/downloads folder
173+
Example for managing additional directories
174+
175+
Create ```<your deployment>/hooks/post_folder_creation.yml```:
176+
177+
```yaml
178+
---
179+
- name: hook | Create web/uploads folder.
180+
file: state=directory path={{symfony_shared_dir}}/web/uploads
181+
182+
- name: hook | Symlink to release.
183+
file: state=link src="{{symfony_shared_dir}}/web/uploads" path="{{symfony_current_release_dir}}/web/uploads"
184+
```
185+
153186
## Dependencies
154187

155188
None
156189

157190
## Testing
158191

159-
The deployment contains a basic test, executed by travis. If you want to locally test the role, have a look into ```.travis.yml``` for the exceution statements and (maybe) remove the ```geerlingguy.php ``` from ```tests/test.yml``` if you have a local php executable (needed for composer install and symfony console scripts).
192+
The deployment contains a basic test, executed by travis. If you want to locally test the role, have a look into ```.travis.yml``` for the exceution statements. Make sure you have a local php executable (needed for composer install and symfony console scripts).
193+
Add a file ```ansible.cfg```to your deployment project folder with contents:
194+
195+
```
196+
[defaults]
197+
roles_path = ../
198+
```
160199

161200
The test setup looks like this:
162201

hooks/post_folder_creation.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
- name: hook | Create web/uploads folder.
3+
file: state=directory path={{symfony_shared_dir}}/web/uploads
4+
5+
- name: hook | Symlink to release.
6+
file: state=link src="{{symfony_shared_dir}}/web/uploads" path="{{symfony_current_release_dir}}/web/uploads"

hooks/post_live_switch.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
- name: hook | Restart php-fpm
3+
service: name=php5-fpm state=restarted
4+
when: symfony_project_env == "prod"

tasks/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
git: repo={{symfony_project_repo}} dest={{symfony_current_release_dir}} version={{symfony_project_branch}} accept_hostkey=yes depth={{symfony_project_git_clone_depth}}
1515

1616
# read project's composer.json and store output
17-
- shell: cat {{symfony_current_release_dir}}/composer.json
17+
- name: Read composer.json
18+
shell: cat {{symfony_current_release_dir}}/composer.json
1819
register: composer_content
1920

2021
- include: "{{ symfony_project_post_folder_creation_tasks | default('empty.yml') }}"

tests/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
symfony_project_repo: https://github.com/symfony/symfony-standard.git
1212
symfony_project_env: prod
1313

14+
symfony_project_post_folder_creation_tasks: "{{playbook_dir}}/../hooks/post_folder_creation.yml"
15+
1416
# optional parameters, covered by defaults
1517
symfony_project_console_opts: '--no-debug'
1618
symfony_project_composer_opts: '--no-dev --optimize-autoloader'

0 commit comments

Comments
 (0)