Bedrock Capistrano, Sage 9, Running Composer and NPM on deploy

With Sage 9, after Capistrano deploys the following commands need to run in the theme directory:

  • composer install
  • npm install
  • npm run build:production

How can I automate that with Capistrano?’

Much thanks for any help,

I put this together last week for someone:

It should serve as a good starting point/guide.

Thanks very much for the help!

I managed to get npm installing properly after removing the image optimization stuff which I feel isn’t worth the hassle of trying to get working on shared hosting.

I’m still a little lost on how to actually run the npm “build” task and run “composer install” on Sage-9 directory.

Here’s what I have thus far

Much thanks,

I’m still having issues with this.

Turns out npm-capistrano is actually installing to the previous release. I’m not sure why.

I’ve updated by deploy.rb to run “composer install” and “npm run build:production” within the theme directory. They both work, but unfortunately also on the previous release.

Any ideas?

Nothing sticks out after looking at it unfortunately. I haven’t really used Capistrano in almost 2 years so I can’t help debug it like I used to.

Thanks for taking a look,

All my research leads to the server caching symlinks. When npm is installing to the “current” release directory I can check the symlink through a separate terminal and it still points to the previous release.

I’m going to contact my host provider and see if they have any ideas.

That actually should be the case. Capistrano’s entire flow is designed around only updating the symlink after everything is done. That way if there’s an error you’ve left the current release intact and working.

Deploy flow is here:

I believe deploy:publishing is where the symlink is updated. It should look like this:

  • /path/to/releases/20160101 (old release)
  • /path/to/releases/20160701 (current symlink currently here)
  • /path/to/releases/20160826 (new release not yet finish)

release_path in Capistrano should point to the last one (/path/to/releases/20160826) during the deploy. current_release_path would point to the /current symlink.


As you mentioned symlinks ended up not being the issue.

I finally tracked it down to trying to use the release_path in the settings area, where it is not defined.

I realized this because hardcoding the path addition in my tasks worked.

It was suggested to me to retrieve the theme path via a function which is the approach I took.

1 Like