Sage9 + Trellis Build-Before Fails

Using the hook found in the docs, here.

I get the below error when attempting to deploy:

TASK [deploy : Install npm dependencies] *******************************************************************************
System info:
  Ansible 2.4.2.0; Linux
  Trellis at "Update `vagrant_box_version` to `>= 201801.02.0`"
---------------------------------------------------
[Errno 2] No such file or directory
fatal: [example.com]: FAILED! => {"changed": false, "cmd": "yarn", "rc": 2}

Does anyone know how to fix this from happening? As best I can tell it does this when trying to run the yarn command on my VM. I tried navigating to where the files are on the VM and running the command manually works fine, just not in this hook.

Notes:

  • I changed the url in the error above on purpose.
  • I’m running the deploy commands from the VirtualBox as I’m on a Windows host.

As usual, posting helped my brain. I’ll post my solution in case this happens to anyone else. Since the build commands are being run from the VM, yarn must exist on the VM. The problem with this is that yarn requires a higher version of node that is already provisioned. So the easiest solution is to run yarn && yarn run build:production locally in Windows, and modify the build-before hook to the below (change example to your theme name):

- 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/example"

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