From 13d6841df57360a3e50e11cd4e7b9dc56d2aa501 Mon Sep 17 00:00:00 2001 From: Michael Silber Date: Thu, 30 Jun 2016 03:22:08 -0400 Subject: [PATCH] Allow custom current_path Remove Vagrantfile assignment Define project_current_path in roles/deploy/defaults/main.yml instead of deploy.yml (also change var name to match convention Ensure rollback role gets project_current_path var Neater var order Even better, shorter vars Change path after merge of #616 Add changelog entry --- CHANGELOG.md | 1 + Vagrantfile | 8 ++++---- roles/deploy/defaults/main.yml | 4 ++++ roles/deploy/tasks/finalize.yml | 1 + roles/deploy/tasks/initialize.yml | 1 + roles/rollback/tasks/main.yml | 2 +- roles/rollback/tasks/prior-release.yml | 2 +- roles/rollback/tasks/user-release.yml | 2 +- roles/wordpress-install/tasks/directories.yml | 2 +- roles/wordpress-install/tasks/main.yml | 12 ++++++------ .../wordpress-setup/templates/wordpress-site.conf.j2 | 2 +- rollback.yml | 1 + 12 files changed, 23 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9761fe0441..f60808aefa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### HEAD * Fix `wp_home` option in Multisite after install in development ([#616](https://github.com/roots/trellis/pull/616)) +* Add `current_path` var and default to enable custom current release path ([#607](https://github.com/roots/trellis/pull/607)) * Add Vagrant post up message ([#602](https://github.com/roots/trellis/pull/602)) * Fix #468 - Use curl to install wp-cli tab completions ([#593](https://github.com/roots/trellis/pull/593)) * Require Ansible 2.0.2 and remove deploy_helper ([#579](https://github.com/roots/trellis/pull/579)) diff --git a/Vagrantfile b/Vagrantfile index 9e2fa6d4e5..d16be5cf3b 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -63,7 +63,7 @@ Vagrant.configure('2') do |config| if Vagrant::Util::Platform.windows? and !Vagrant.has_plugin? 'vagrant-winnfsd' wordpress_sites.each_pair do |name, site| - config.vm.synced_folder local_site_path(site), remote_site_path(name), owner: 'vagrant', group: 'www-data', mount_options: ['dmode=776', 'fmode=775'] + config.vm.synced_folder local_site_path(site), remote_site_path(name, site), owner: 'vagrant', group: 'www-data', mount_options: ['dmode=776', 'fmode=775'] end config.vm.synced_folder File.join(ANSIBLE_PATH, 'hosts'), File.join(ANSIBLE_PATH.sub(__dir__, '/vagrant'), 'hosts'), mount_options: ['dmode=755', 'fmode=644'] else @@ -72,7 +72,7 @@ Vagrant.configure('2') do |config| else wordpress_sites.each_pair do |name, site| config.vm.synced_folder local_site_path(site), nfs_path(name), type: 'nfs' - config.bindfs.bind_folder nfs_path(name), remote_site_path(name), u: 'vagrant', g: 'www-data', o: 'nonempty' + config.bindfs.bind_folder nfs_path(name), remote_site_path(name, site), u: 'vagrant', g: 'www-data', o: 'nonempty' end end end @@ -147,6 +147,6 @@ def post_up_message msg end -def remote_site_path(site_name) - "/srv/www/#{site_name}/current" +def remote_site_path(site_name, site) + "/srv/www/#{site_name}/#{site['current_path'] || 'current'}" end diff --git a/roles/deploy/defaults/main.yml b/roles/deploy/defaults/main.yml index 3974dedaf4..a592b98c11 100644 --- a/roles/deploy/defaults/main.yml +++ b/roles/deploy/defaults/main.yml @@ -40,3 +40,7 @@ project_shared_children: # WP_ENV: "production" project_environment: WP_ENV: "{{ env }}" + +# 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') }}" diff --git a/roles/deploy/tasks/finalize.yml b/roles/deploy/tasks/finalize.yml index 3699ffb7d5..e21bccaf0e 100644 --- a/roles/deploy/tasks/finalize.yml +++ b/roles/deploy/tasks/finalize.yml @@ -4,6 +4,7 @@ - name: Finalize the deploy deploy_helper: + current_path: "{{ project_current_path }}" path: "{{ project_root }}" release: "{{ deploy_helper.new_release }}" state: finalize diff --git a/roles/deploy/tasks/initialize.yml b/roles/deploy/tasks/initialize.yml index 1d5b833f03..ed175524aa 100644 --- a/roles/deploy/tasks/initialize.yml +++ b/roles/deploy/tasks/initialize.yml @@ -4,6 +4,7 @@ - name: Initialize deploy_helper: + current_path: "{{ project_current_path }}" path: "{{ project_root }}" state: present diff --git a/roles/rollback/tasks/main.yml b/roles/rollback/tasks/main.yml index 59255cc6bf..aa78e0db1d 100644 --- a/roles/rollback/tasks/main.yml +++ b/roles/rollback/tasks/main.yml @@ -17,6 +17,6 @@ - name: Link 'current' directory to target release file: - path: "{{ project_root }}/current" + path: "{{ project_root }}/{{ project_current_path }}" src: "{{ new_release_path }}" state: link diff --git a/roles/rollback/tasks/prior-release.yml b/roles/rollback/tasks/prior-release.yml index fb5bba9851..1788aeebe8 100644 --- a/roles/rollback/tasks/prior-release.yml +++ b/roles/rollback/tasks/prior-release.yml @@ -1,6 +1,6 @@ --- - name: Get list position of current symlinked release - shell: "ls releases | grep -n $(basename $(readlink current)) | cut -f1 -d:" + shell: "ls releases | grep -n $(basename $(readlink {{ project_current_path }})) | cut -f1 -d:" args: chdir: "{{ project_root }}" register: current_release_position diff --git a/roles/rollback/tasks/user-release.yml b/roles/rollback/tasks/user-release.yml index 965405720c..6e356e1bc0 100644 --- a/roles/rollback/tasks/user-release.yml +++ b/roles/rollback/tasks/user-release.yml @@ -5,7 +5,7 @@ register: specified - name: Get name of current symlinked release - shell: "basename $(readlink current)" + shell: "basename $(readlink {{ project_current_path }})" args: chdir: "{{ project_root }}" register: current_release diff --git a/roles/wordpress-install/tasks/directories.yml b/roles/wordpress-install/tasks/directories.yml index 31802eed3f..093d3212a6 100644 --- a/roles/wordpress-install/tasks/directories.yml +++ b/roles/wordpress-install/tasks/directories.yml @@ -1,7 +1,7 @@ --- - name: Create web root of sites file: - path: "{{ www_root }}/{{ item.key }}/current/web" + path: "{{ www_root }}/{{ item.key }}/{{ item.value.current_path | default('current') }}/web" owner: "{{ web_user }}" group: "{{ web_group }}" mode: 0755 diff --git a/roles/wordpress-install/tasks/main.yml b/roles/wordpress-install/tasks/main.yml index 6cbc36ff72..bc4f7398fe 100644 --- a/roles/wordpress-install/tasks/main.yml +++ b/roles/wordpress-install/tasks/main.yml @@ -11,7 +11,7 @@ with_dict: "{{ wordpress_sites }}" - name: Copy .env file into web root - command: rsync -ac --info=NAME /tmp/{{ item.key }}.env {{ www_root }}/{{ item.key }}/current/.env + command: rsync -ac --info=NAME /tmp/{{ item.key }}.env {{ www_root }}/{{ item.key }}/{{ item.value.current_path | default('current') }}/.env with_dict: "{{ wordpress_sites }}" register: env_file changed_when: env_file.stdout == "{{ item.key }}.env" @@ -19,7 +19,7 @@ - name: Install Dependencies with Composer command: composer install args: - chdir: "{{ www_root }}/{{ item.key }}/current/" + chdir: "{{ www_root }}/{{ item.key }}/{{ item.value.current_path | default('current') }}/" register: composer_results with_dict: "{{ wordpress_sites }}" changed_when: "'Nothing to install or update' not in composer_results.stderr" @@ -33,7 +33,7 @@ --admin_password="{{ vault_wordpress_sites[item.key].admin_password }}" --admin_email="{{ item.value.admin_email }}" args: - chdir: "{{ www_root }}/{{ item.key }}/current/" + chdir: "{{ www_root }}/{{ item.key }}/{{ item.value.current_path | default('current') }}/" register: wp_install_results with_dict: "{{ wordpress_sites }}" when: item.value.site_install | default(true) and not item.value.multisite.enabled | default(false) @@ -42,7 +42,7 @@ - name: Setup Permalink Structure command: wp rewrite structure {{ item.value.initial_permalink_structure | default("/%postname%/") }} --allow-root args: - chdir: "{{ www_root }}/{{ item.key }}/current/" + chdir: "{{ www_root }}/{{ item.key }}/{{ item.value.current_path | default('current') }}/" with_dict: "{{ wordpress_sites }}" when: wp_install_results | changed and not item.value.multisite.enabled | default(false) @@ -57,7 +57,7 @@ --admin_password="{{ vault_wordpress_sites[item.key].admin_password }}" --admin_email="{{ item.value.admin_email }}" args: - chdir: "{{ www_root }}/{{ item.key }}/current/" + chdir: "{{ www_root }}/{{ item.key }}/{{ item.value.current_path | default('current') }}/" register: wp_install_results with_dict: "{{ wordpress_sites }}" when: item.value.site_install | default(true) and item.value.multisite.enabled | default(false) @@ -66,6 +66,6 @@ - name: Update WP Multisite Home URL command: wp option update home {{ site_env.wp_home }} --allow-root args: - chdir: "{{ www_root }}/{{ item.key }}/current/" + chdir: "{{ www_root }}/{{ item.key }}/{{ item.value.current_path | default('current') }}/" with_dict: "{{ wordpress_sites }}" when: item.value.site_install | default(true) and item.value.multisite.enabled | default(false) diff --git a/roles/wordpress-setup/templates/wordpress-site.conf.j2 b/roles/wordpress-setup/templates/wordpress-site.conf.j2 index c94d05cd7c..cf68c6b4b3 100644 --- a/roles/wordpress-setup/templates/wordpress-site.conf.j2 +++ b/roles/wordpress-setup/templates/wordpress-site.conf.j2 @@ -11,7 +11,7 @@ server { access_log {{ www_root }}/{{ item.key }}/logs/access.log; error_log {{ www_root }}/{{ item.key }}/logs/error.log; - root {{ www_root }}/{{ item.key }}/current/web; + root {{ www_root }}/{{ item.key }}/{{ item.value.current_path | default('current') }}/web; index index.php index.htm index.html; charset utf-8; diff --git a/rollback.yml b/rollback.yml index b3b69904d3..2ce5ff5212 100644 --- a/rollback.yml +++ b/rollback.yml @@ -9,6 +9,7 @@ vars: project_root: "{{ www_root }}/{{ site }}" + project_current_path: "{{ wordpress_sites[site].current_path | default('current') }}" roles: - rollback