Skip to content

Instantly share code, notes, and snippets.

@cfaria
Last active May 2, 2019 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfaria/83b06391f5ea1a632fdaf656f0a3634a to your computer and use it in GitHub Desktop.
Save cfaria/83b06391f5ea1a632fdaf656f0a3634a to your computer and use it in GitHub Desktop.
#roles/deploy/hooks/build-after.yml
---
- name: Check for composer.json in project root or project_subtree_path
stat:
path: "{{ deploy_helper.new_release_path }}/composer.json"
register: composer_json
- name: Fail if composer.json not found
fail:
msg: "Unable to find a `composer.json` file in the root of '{{ deploy_helper.new_release_path }}'. Make sure your repo has a `composer.json` file in its root or edit `repo_subtree_path` for '{{ site }}' in `wordpress_sites.yml` so it points to the directory with a `composer.json` file."
when: not composer_json.stat.exists
- name: Setup packagist.com authentication
composer:
command: config
arguments: --auth http-basic.repo.packagist.com token {{ project.packagist_token }}
working_dir: "{{ deploy_helper.new_release_path }}"
no_log: true
when: project.packagist_token is defined
- name: Install Composer dependencies with scripts
composer:
no_scripts: yes #SM! - Need to execute scripts (koodimonni/composer-dropin-installer needs it to move language files)
working_dir: "{{ deploy_helper.new_release_path }}"
#roles/deploy/hooks/finalize-after.yml
---
- block:
- name: Remove WordPress transient containing old release path
shell: "{{ project.multisite.enabled | default(false) | ternary('wp network meta delete 1', 'wp option delete') }} _site_transient_theme_roots ||:"
args:
chdir: "{{ deploy_helper.current_path }}"
register: site_transient_theme_roots
changed_when: site_transient_theme_roots.stdout != ''
when: project.update_wp_theme_paths | default(update_wp_theme_paths | default(true)) | bool
- name: Update WP theme paths
command: >
wp option set {{ item[0].option }}
{{ item[1] | regex_replace('.*' + deploy_helper.releases_path + '/[^/]*(.*)', deploy_helper.new_release_path + '\1') }}
{% if project.multisite.enabled | default(false) %} --url={{ item[1].split(' ')[0] }}{% endif %}
args:
chdir: "{{ deploy_helper.current_path }}"
when: project.update_wp_theme_paths | default(update_wp_theme_paths | default(true)) | bool
with_subelements:
- "[{% for result in wp_template_root.results %}{'option': '{{ result.item }}', 'stdout_lines': {{ result.stdout_lines | default ([]) | select('search', deploy_helper.releases_path) | list }}},{% endfor %}]"
- stdout_lines
- name: Warn about updating network database.
debug:
msg: "Updating the network database could take a long time with a large number of sites."
when: project.update_db_on_deploy | default(update_db_on_deploy) and project.multisite.enabled | default(false)
- name: Update WP database
command: wp core update-db {{ project.multisite.enabled | default(false) | ternary('--network', '') }}
args:
chdir: "{{ deploy_helper.current_path }}"
when: project.update_db_on_deploy | default(update_db_on_deploy)
when: wp_installed.rc == 0
# SM! - Commented out to deploy to Kinsta
# - name: Reload php-fpm
# shell: sudo service php7.2-fpm reload
# args:
# warn: false
#roles/deploy/defaults/main.yml
# If you use the "git" strategy:
# - you must set a repository (no default)
project_git_repo: "{{ project.repo }}"
# - you can set the git ref to deploy (can be a branch, tag or commit hash)
project_version: "{{ project.branch | default('master') }}"
# The source_path is used to fetch the tags from git, or synchronise via rsync. This way
# you do not have to download/sync the entire project on every deploy
project_source_path: "{{ project_root }}/shared/source"
# There are certain folders you'll want to copy from release to release to speed up deploys.
# Examples: Composer's `vendor` folder, npm's `node_modules`.
# These should not be part of project_shared_children since dependencies need to be atomic and tied to a deploy.
project_copy_folders:
# - vendor # SM! - Need to generate vendor everytime I deploy. Koodimonni composer-dropin-installer
# All the templates to process on the remote system on deploy. These could contain config files.
# `src` and `dest` paths work the same as project_local_files.
project_templates:
- name: .env config
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`.
# 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).
# Example:
# project_shared_children:
# - 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` or `file`
project_shared_children:
- path: web/app/uploads
src: uploads
# The project_environment is a list of environment variables that can be used in hooks
# Example:
# project_environment:
# 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') }}"
# Whether to run `wp core update-db` at end of each deploy
update_db_on_deploy: true
# Helpers
project: "{{ wordpress_sites[site] }}"
project_root: "{{ www_root }}/{{ site }}"
project_local_path: "{{ (lookup('env', 'USER') == 'vagrant') | ternary(project_root + '/' + project_current_path, project.local_path) }}"
# Deploy hooks
# For list of hooks and explanation, see https://roots.io/trellis/docs/deploys/#hooks
deploy_build_before:
- "{{ playbook_dir }}/deploy-hooks/build-before.yml"
deploy_build_after:
- "{{ playbook_dir }}/roles/deploy/hooks/build-after.yml"
# - "{{ playbook_dir }}/deploy-hooks/sites/{{ site }}-build-after.yml"
deploy_finalize_before:
- "{{ playbook_dir }}/roles/deploy/hooks/finalize-before.yml"
deploy_finalize_after:
- "{{ playbook_dir }}/roles/deploy/hooks/finalize-after.yml"
deploy_after:
- "{{ playbook_dir }}/vendor/roles/trellis-purge-kinsta-cache-during-deploy/tasks/main.yml"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment