Roots Discourse

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


#1

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,


#2

I put this together last week for someone: https://gist.github.com/swalkinshaw/7fba3ab806cdba974db4ab0083639e61

It should serve as a good starting point/guide.


#3

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

https://gist.github.com/christianmagill/2378019c8cad18890c607d31f06f8b5f

Much thanks,


#5

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.

https://gist.github.com/christianmagill/b308ae6d5384387dbfc120d76b0901ec

Any ideas?


#6

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.


#7

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.


#8

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: http://capistranorb.com/documentation/getting-started/flow/

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.


#9

Thanks,

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.