Deploy_build_before for multiple site boxes


#1

So, for boxes with multiple sites…
I have some sites using grunt and also with some other slight requirements for deployment, and they all have different theme names at least.

Here’s what I ended up doing…

In deploy.yml, simply add a -{{ site }} to the deploy_build_before path and create your different build_before files accordingly.

May be obvious but hopefully will help someone.


#2

Good idea! Never thought about this.


#3

Reminder:

  • Edit deploy.yml
    deploy_build_before: "{{ playbook_dir }}/deploy-hooks/{{ site }}-build-before.yml"
  • $ cp deploy-hooks/build-before.yml deploy-hooks/[domain.com]-build-before.yml

(r)sync of theme dist
#4

With latest changes to Trellis hook system,
this would be now added to the hooks list in ‘roles/deploy/defaults.yml’:

[...]
deploy_build_before:
  - "{{ playbook_dir }}/deploy-hooks/build-before.yml"
  - "{{ playbook_dir }}/deploy-hooks/sites/{{ site }}-build-before.yml" # <- this
[...]

Trying to install a plugin only for remote server
#5

I use Trellis with multi sites but I have the following structure which I personally prefer.

Instead of prefixing the hook with site I use sub-folders in deploy-hooks depending on what hook it is.

deploy_build_before:
  - "{{ playbook_dir }}/deploy-hooks/build-before/{{ site }}.yml"

deploy_build_after:
  - "{{ playbook_dir }}/deploy-hooks/build-after/{{ site }}.yml"
  # - "{{ playbook_dir }}/deploy-hooks/sites/{{ site }}-build-after.yml"

deploy_finalize_before:
  - "{{ playbook_dir }}/deploy-hooks/finalize-before/{{ site }}.yml"

deploy_finalize_after:
  - "{{ playbook_dir }}/deploy-hooks/finalize-after/{{ site }}.yml"

so when adding a new site I simply create staging.example.com or example.com depending on environment.


#6

I just noticed in


that the hooks are defined in group_vars/all/deploy-hooks.yml.
Is this a better place because it interferes less with existing trellis files?


#7

@strarsis yes, Trellis has changed since my original post here, that is the best way to go about it now.
in group_vars/all/deploy-hooks.yml

deploy_build_before:
  - "{{ playbook_dir }}/deploy-hooks/{{ site }}-build-before.yml"

…or however you prefer to structure the filenames. You could put them in site directories like:

deploy_build_before:
  - "{{ playbook_dir }}/deploy-hooks/{{ site }}/build-before.yml"

I realize another year has gone by, just posting this for anyone that might find it. There’s now instructions in the trellis docs for this: https://roots.io/trellis/docs/deploys/#custom-tasks