Trellis, Bedrock Sage on Windows - Issue with build-before.yml

I have an almost fully working setup of Trellis, Bedrock, Sage on my Windows 10 host.

However I’m having trouble getting the themes dist folder to copy to staging / production servers.

I’ve uncommented the following task in build-before.yml to copy my local dist folder to staging/production

- name: Copy project local files
  synchronize:
    src: "{{ project.local_path }}/web/app/themes/rl/dist"
    dest: "{{ deploy_helper.new_release_path }}/web/app/themes/rl"
    group: no
    owner: no
    rsync_opts: --chmod=Du=rwx,--chmod=Dg=rx,--chmod=Do=rx,--chmod=Fu=rw,--chmod=Fg=r,--chmod=Fo=r

On deploy I get the following error:

rsync: change_dir "/site/web/app/themes/rl" failed: No such file or directory
(2)
rsync error: some files/attrs were not transferred (see previous errors)
(code 23) at main.c(1183) [sender=3.1.1]

What’s the best way to set this up so that the dist folder for my Sage based theme is copied to staging/prodution when using Windows. What am i missing?

Looking at your error, it looks like your theme directory is set incorrectly, can you confirm the directory of your theme? Also, can you confirm that your repo actually contains the theme- it’s possible it’s being excluded depending on how you installed it (if you cloned the sage repo instead of using composer, the .git directory would prevent the theme being included in your site’s repo).

P.S. A formatting request, please format your code, it’s much easier to read that way. The shortcut is right there between quotes and upload a file.

1 Like

Thanks for your reply @thisolivier. I’ve editied my post so the code is formatted. I’m using a standard Trellis, Bedrock, Sage setup.

The theme directory is correct, it was installed using composer with the following command:

composer create-project roots/sage rl 8.5.0

The theme files have been commited and pushed to my remote repo.

On deploy the git clone is successful. The only part that I can’t get to work is copying the locally compiled dist files from local to staging / production. I noticed I missed the final portion of the error message when I added it previously

bash: warning: setlocale: LC_ALL: cannot change locale (en_US)
rsync: change_dir "/site/web/app/themes/rl" failed: No such file or directory
(2)
rsync error: some files/attrs were not transferred (see previous errors)
(code 23) at main.c(1183) [sender=3.1.1]

fatal: [139.162.240.174]: FAILED! => {"changed": false, "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --no-owner --no-group --rsh '/usr/bin/ssh  -S none -o StrictHostKeyChecking=no' --chmod=Du=rwx --chmod=Dg=rx --chmod=Do=rx --chmod=Fu=rw --chmod=Fg=r --chmod=Fo=r --out-format='<<CHANGED>>%i %n%L' \"/site/web/app/themes/rl/dist\" \"web@139.162.240.174:/srv/www/ryanlowry.uk/releases/20161006090232/web/app/themes/rl\"", "failed": true, "rc": 23}

I’ve modified the “Copy project local files” task as follows and the deploy completes successfully.

- name: Copy project local files
  synchronize:
    #src: "{{ project.local_path }}/web/app/themes/rl/dist"
    src: "/srv/www/ryanlowry.uk/current/web/app/themes/rl/dist"
    dest: "{{ deploy_helper.new_release_path }}/web/app/themes/rl"
    group: no
    owner: no
    rsync_opts: --chmod=Du=rwx,--chmod=Dg=rx,--chmod=Do=rx,--chmod=Fu=rw,--chmod=Fg=r,--chmod=Fo=r

{{ project.local_path }} appears to be pointing to the wrong location?

That’s a bizarre solution- the src variable should point to the local path on your machine- which (unless you have a very odd setup) won’t be /srv/www/ryanlowry.uk/current/... - can you give some info about how your local directories are setup, and how your site variables are configured?

Are you using Sage 9? There might have been a change in behaviour, if so, worth submitting a bug report on the repo, because this behaviour looks like ansible is building the local files on your remote.

When using windows as a host the ansible commands have to be run on the guest OS. https://roots.io/trellis/docs/windows/. That’s why my current solution works.

My folder layout matches the roots example project exactly https://github.com/roots/roots-example-project.com/

I’m using Sage v8.50

The correct way to resolve this is to set your local_path in your wordpress_sites.yml file.

I’m guessing that it’s currently ../site, which is resolving to /vagrant/../site, which is /site, which doesn’t exist. You should change that to something like /srv/www/example.com/current.

Alternatively, you can move your Vagrantfile one level up so that it sits alongside your trellis and site folders. This is how we used to do it in roots-example-project. Just make sure to change your ANSIBLE_PATH in Vagrantfile to something like File.join(__dir__, 'trellis') [ref]. This will put your site files in /vagrant/site and your trellis stuff in /vagrant/trellis. Now local_path: ../site will resolve to /vagrant/trellis/../site, which is /vagrant/site, which exists.

6 Likes

Thanks. I knew there would be a simple solution. Will give it a go later tonight.

Thanks @QWp6t. Everything now working as expected :slight_smile:

This is an old issue. As I was helping a colleague to get Trellis (especially the deployment) working on his Windows machine (I’m on macOS) it happened to me. Your post pointed me in the right direction.

Make sure your site’s keys for staging/production site are matching the site key in group_vars/development/wordpress_sites.yml.

If you are on Windows/run Ansible as vagrant user, the local_path variable will not be used. Instead the project_root is used, which contains the site key. So they have to be the same.

Another thing I noticed is that the example for Sage in the build-before.yml deploy hook is not working on Windows machines because yarn is not installed. Might be worth adding an Ansible task for that or am I missing something?