Skip to content

Commit

Permalink
build-before: Checkout project source code to local temporary directo…
Browse files Browse the repository at this point in the history
…ry and compile multiple sage themes
  • Loading branch information
tangrufus committed Nov 18, 2018
1 parent 186c99f commit b425baa
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,4 +1,5 @@
### HEAD
* build-before: Checkout project source code to local temporary directory and compile multiple sage themes ([#1030](https://github.com/roots/trellis/pull/1030))
* Allow customizing Nginx `worker_connections` ([#1021](https://github.com/roots/trellis/pull/1021))
* Update wp-cli to 2.0.1 ([#1019](https://github.com/roots/trellis/pull/1019))
* [BREAKING] Update wp-cli to 2.0.0 and verify its PGP signature ([#1014](https://github.com/roots/trellis/pull/1014))
Expand Down
75 changes: 49 additions & 26 deletions deploy-hooks/build-before.yml
@@ -1,33 +1,56 @@
# Placeholder `deploy_build_before` hook for building theme assets on the
# `deploy_build_before` hook for building theme assets on the
# host machine and then copying the files to the remote server
#
# ⚠️ This example assumes your theme is using Sage 9
# ⚠️ This assumes your theme is using Sage 9
# An example for themes built with Sage 8 can be found at: https://git.io/vdgUt
#
# Uncomment the lines below and replace `sage` with your theme folder
#
# ---
# - name: Install npm dependencies
# command: yarn
# connection: local
# args:
# chdir: "{{ project_local_path }}/web/app/themes/sage"
#
# - name: Install Composer dependencies
# command: composer install --no-ansi --no-dev --no-interaction --no-progress --optimize-autoloader --no-scripts
# args:
# chdir: "{{ deploy_helper.new_release_path }}/web/app/themes/sage"
# Define an array of `sage_themes` in `group_vars/<env>/wordpress_sites.yml`, e,g:
# wordpress_sites:
# example.com:
# sage_themes:
# - my-first-sage-theme-name
# - my-second-sage-theme-name
#
# - name: Compile assets for production
# command: yarn build:production
# connection: local
# args:
# chdir: "{{ project_local_path }}/web/app/themes/sage"
#
# - name: Copy production assets
# synchronize:
# src: "{{ project_local_path }}/web/app/themes/sage/dist"
# dest: "{{ deploy_helper.new_release_path }}/web/app/themes/sage"
# group: no
# owner: no
# rsync_opts: --chmod=Du=rwx,--chmod=Dg=rx,--chmod=Do=rx,--chmod=Fu=rw,--chmod=Fg=r,--chmod=Fo=r
# ---
- block:
- name: Clone project files
git:
repo: "{{ project_git_repo }}"
version: "{{ project_version }}"
dest: "{{ project_build_path }}"
force: yes
no_log: true
connection: local

- name: Install npm dependencies
command: yarn
connection: local
args:
chdir: "{{ project_build_site_path }}/web/app/themes/{{ item }}"
with_items: "{{ project.sage_themes }}"

- name: Install Composer dependencies
command: composer install --no-ansi --no-dev --no-interaction --no-progress --optimize-autoloader --no-scripts
args:
chdir: "{{ deploy_helper.new_release_path }}/web/app/themes/{{ item }}"
with_items: "{{ project.sage_themes }}"

- name: Compile assets for production
command: yarn build:production
connection: local
args:
chdir: "{{ project_build_site_path }}/web/app/themes/{{ item }}"
with_items: "{{ project.sage_themes }}"

- name: Copy production assets
synchronize:
src: "{{ project_build_site_path }}/web/app/themes/{{ item }}/dist"
dest: "{{ deploy_helper.new_release_path }}/web/app/themes/{{ item }}"
group: no
owner: no
rsync_opts: --chmod=Du=rwx,--chmod=Dg=rx,--chmod=Do=rx,--chmod=Fu=rw,--chmod=Fg=r,--chmod=Fo=r
with_items: "{{ project.sage_themes }}"

when: project.sage_themes is defined
3 changes: 3 additions & 0 deletions group_vars/production/wordpress_sites.yml
Expand Up @@ -19,3 +19,6 @@ wordpress_sites:
provider: letsencrypt
cache:
enabled: false
# sage_themes:
# - my-first-sage-theme-name
# - my-second-sage-theme-name
3 changes: 3 additions & 0 deletions group_vars/staging/wordpress_sites.yml
Expand Up @@ -19,3 +19,6 @@ wordpress_sites:
provider: letsencrypt
cache:
enabled: false
# sage_themes:
# - my-first-sage-theme-name
# - my-second-sage-theme-name
4 changes: 2 additions & 2 deletions roles/deploy/defaults/main.yml
Expand Up @@ -51,8 +51,8 @@ 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) }}"

project_build_path: "{{ lookup('env', 'TMPDIR') | default('/tmp/', true) }}trellis/{{ (project_git_repo + project_version) | hash('md5') }}"
project_build_site_path: "{{ project_build_path }}/{{ '/' + project.repo_subtree_path if 'repo_subtree_path' in project else '' }}"

# Deploy hooks
# For list of hooks and explanation, see https://roots.io/trellis/docs/deploys/#hooks
Expand Down

0 comments on commit b425baa

Please sign in to comment.