Skip to content

Commit

Permalink
Simplify handling of project_shared_children
Browse files Browse the repository at this point in the history
  • Loading branch information
fullyint committed Dec 14, 2016
1 parent ecdf286 commit 720e2f2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
### HEAD
* Create `project_shared_children` files if they do not exist ([#706](https://github.com/roots/trellis/pull/706))
* Diffie-Hellman params now conditional on SSL status ([#709](https://github.com/roots/trellis/pull/709))
* Update PHP to 7.1 ([#695](https://github.com/roots/trellis/pull/695))
* Update WP-CLI to 1.0.0 ([#708](https://github.com/roots/trellis/pull/708))
Expand Down
11 changes: 4 additions & 7 deletions roles/deploy/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ project_templates:

# The shared_children is a list of all files/folders in your project that need to be linked to a path in `/shared`.
# For example a sessions directory or an uploads folder. They are created if they don't exist, with the type
# specified in the `type` key (file or directory). Use `type: absent` to remove an item from `/shared`.
# specified in the `type` key (file or directory).
# Example:
# project_shared_children:
# - path: app/sessions // <- required for type `directory` and `file`, optional for type `absent`
# src: sessions // <- required
# - path: app/sessions
# src: sessions
# mode: '0755' // <- optional, must be quoted, defaults to `'0755'` if `directory` or `'0644'` if `file`
# type: directory // <- optional, defaults to `directory`, options: `directory`, `file`, `absent`
# type: directory // <- optional, defaults to `directory`, options: `directory` or `file`
project_shared_children:
- path: web/app/uploads
src: uploads
Expand All @@ -44,6 +44,3 @@ project_environment:
# The project_current_path is the symlink used for the latest or active deployment
# - default is 'current'
project_current_path: "{{ project.current_path | default('current') }}"

# Helpers
project_shared_file: "{{ item.type | default('directory') | lower in ['file', 'touch'] }}"
25 changes: 16 additions & 9 deletions roles/deploy/tasks/share.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,46 @@

- name: Ensure shared sources are present -- directories
file:
path: "{{ deploy_helper.shared_path }}/{{ project_shared_file | ternary(item.src | dirname, item.src) }}"
state: "{{ project_shared_file | ternary('directory', item.type | default('directory')) | lower }}"
mode: "{{ project_shared_file | ternary('0755', item.mode | default('0755')) }}"
path: "{{ deploy_helper.shared_path }}/{{ item.src }}"
state: directory
mode: "{{ item.mode | default('0755') }}"
with_items: "{{ project_shared_children }}"
when: item.type | default('directory') | lower == 'directory'

- name: Ensure shared sources are present -- files' parent directories
file:
path: "{{ deploy_helper.shared_path }}/{{ item.src | dirname }}"
state: directory
mode: '0755'
with_items: "{{ project_shared_children }}"
when: item.type | default('directory') | lower == 'file'

- name: Ensure shared sources are present -- files
file:
path: "{{ deploy_helper.shared_path }}/{{ item.src }}"
state: touch
mode: "{{ item.mode | default('0644') }}"
with_items: "{{ project_shared_children }}"
when: project_shared_file
when: item.type | default('directory') | lower == 'file'

- name: Ensure parent directories for shared paths are present
file:
path: "{{ deploy_helper.new_release_path }}/{{ item.path | default('') | dirname }}"
path: "{{ deploy_helper.new_release_path }}/{{ item.path | dirname }}"
state: directory
with_items: "{{ project_shared_children }}"

- name: Ensure shared paths are absent
file:
path: "{{ deploy_helper.new_release_path }}/{{ item.path | default('') }}"
path: "{{ deploy_helper.new_release_path }}/{{ item.path }}"
state: absent
with_items: "{{ project_shared_children }}"
when: item.type | default('directory') | lower != 'absent'

- name: Create shared symlinks
file:
path: "{{ deploy_helper.new_release_path }}/{{ item.path | default('') }}"
path: "{{ deploy_helper.new_release_path }}/{{ item.path }}"
src: "{{ deploy_helper.shared_path }}/{{ item.src }}"
state: link
with_items: "{{ project_shared_children }}"
when: item.type | default('directory') | lower != 'absent'

- include: "{{ deploy_share_after | default('../hooks/example.yml') }}"
tags: deploy-share-after

0 comments on commit 720e2f2

Please sign in to comment.