From f5148569c09eab9ee6e533dfef27c5e4bcf66f87 Mon Sep 17 00:00:00 2001 From: Phil Nelson Date: Fri, 9 Dec 2016 17:43:30 -0700 Subject: [PATCH 1/3] Create project_shared_children files if they do not exist --- roles/deploy/defaults/main.yml | 3 +++ roles/deploy/tasks/share.yml | 14 +++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/roles/deploy/defaults/main.yml b/roles/deploy/defaults/main.yml index a592b98c11..ac2e63d78e 100644 --- a/roles/deploy/defaults/main.yml +++ b/roles/deploy/defaults/main.yml @@ -44,3 +44,6 @@ 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'] }}" diff --git a/roles/deploy/tasks/share.yml b/roles/deploy/tasks/share.yml index aa855834eb..4d14b59814 100644 --- a/roles/deploy/tasks/share.yml +++ b/roles/deploy/tasks/share.yml @@ -2,12 +2,20 @@ - include: "{{ deploy_share_before | default('../hooks/example.yml') }}" tags: deploy-share-before -- name: Ensure shared sources are present +- 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')) }}" + mode: "{{ project_shared_file | ternary('0755', item.mode | default('0755')) }}" + with_items: "{{ project_shared_children }}" + +- name: Ensure shared sources are present -- files file: path: "{{ deploy_helper.shared_path }}/{{ item.src }}" - state: "{{ item.type | default('directory') }}" - mode: "{{ item.mode | default('0755') }}" + state: touch + mode: "{{ item.mode | default('0644') }}" with_items: "{{ project_shared_children }}" + when: project_shared_file - name: Ensure shared paths are absent file: From ecdf2867c6905d893249027c28ebf2ed6157ff6b Mon Sep 17 00:00:00 2001 From: Phil Nelson Date: Sun, 11 Dec 2016 15:24:30 -0700 Subject: [PATCH 2/3] Ensure parent directories for project shared paths are present --- roles/deploy/defaults/main.yml | 12 ++++++------ roles/deploy/tasks/share.yml | 14 +++++++++++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/roles/deploy/defaults/main.yml b/roles/deploy/defaults/main.yml index ac2e63d78e..cbcb6a6268 100644 --- a/roles/deploy/defaults/main.yml +++ b/roles/deploy/defaults/main.yml @@ -21,15 +21,15 @@ project_templates: src: roles/deploy/templates/env.j2 dest: .env -# The shared_children is a list of all files/folders in your project that need to be linked to a path in "/shared". +# 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). +# specified in the `type` key (file or directory). Use `type: absent` to remove an item from `/shared`. # Example: # project_shared_children: -# - path: "app/sessions" -# src: "sessions" -# mode: "0755" -# type: "file" / "directory" // <- optional, defaults to "directory" +# - path: app/sessions // <- required for type `directory` and `file`, optional for type `absent` +# src: sessions // <- required +# 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` project_shared_children: - path: web/app/uploads src: uploads diff --git a/roles/deploy/tasks/share.yml b/roles/deploy/tasks/share.yml index 4d14b59814..876e2c2ac0 100644 --- a/roles/deploy/tasks/share.yml +++ b/roles/deploy/tasks/share.yml @@ -5,7 +5,7 @@ - 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')) }}" + state: "{{ project_shared_file | ternary('directory', item.type | default('directory')) | lower }}" mode: "{{ project_shared_file | ternary('0755', item.mode | default('0755')) }}" with_items: "{{ project_shared_children }}" @@ -17,18 +17,26 @@ with_items: "{{ project_shared_children }}" when: project_shared_file +- name: Ensure parent directories for shared paths are present + file: + path: "{{ deploy_helper.new_release_path }}/{{ item.path | default('') | dirname }}" + state: directory + with_items: "{{ project_shared_children }}" + - name: Ensure shared paths are absent file: - path: "{{ deploy_helper.new_release_path }}/{{ item.path }}" + path: "{{ deploy_helper.new_release_path }}/{{ item.path | default('') }}" 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 }}" + path: "{{ deploy_helper.new_release_path }}/{{ item.path | default('') }}" 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 From 720e2f2f43fd469fef7e41b63432efe7c2f3ffff Mon Sep 17 00:00:00 2001 From: Phil Nelson Date: Wed, 14 Dec 2016 14:25:47 -0700 Subject: [PATCH 3/3] Simplify handling of project_shared_children --- CHANGELOG.md | 1 + roles/deploy/defaults/main.yml | 11 ++++------- roles/deploy/tasks/share.yml | 25 ++++++++++++++++--------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f66f74a892..4ff38a388a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/roles/deploy/defaults/main.yml b/roles/deploy/defaults/main.yml index cbcb6a6268..0e230fb7b2 100644 --- a/roles/deploy/defaults/main.yml +++ b/roles/deploy/defaults/main.yml @@ -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 @@ -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'] }}" diff --git a/roles/deploy/tasks/share.yml b/roles/deploy/tasks/share.yml index 876e2c2ac0..62ded1a0f3 100644 --- a/roles/deploy/tasks/share.yml +++ b/roles/deploy/tasks/share.yml @@ -4,10 +4,19 @@ - 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: @@ -15,28 +24,26 @@ 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