1
votes

I have been using Capistrano 3 to deploy a PHP app for several months and it works great. Recently, we decided to start using Sass for stylesheets and I am now trying to deploy these changes.

I am trying to write a task that runs after the rest of the deploy stuff is finished that converts a scss file to css using the Sass gem.

namespace :deploy do

  after :finished, :assets do
    on roles(:app), in: :sequence, wait: 5 do
      within release_path do
        # process sass files to css
        execute "sass #{release_path}/styles/test.scss #{release_path}/styles/test.css"
      end
    end
  end

end

I am using RVM on the server and have the sass gem installed in a specific gemset. There is also an .rvmrc file in the project root that loads the correct gemset when you cd into the 'current' directory that capistrano creates.

When I deploy, it fails on my new task saying that it cannot find sass.

stderr: bash: sass: command not found

I can log into the server as the same user that is used to deploy with Capistrano and cd into the 'current' directory and run the same command in the task (substituting the #{release_path} with actual path) and it works fine.

Things I have tried:

  1. rewriting the execute command with the following:

rvm use 2.1.5@deployer && sass #{release_path}/styles/test.scss #{release_path}/styles/test.css

  1. writing a bash script accessible by the deployer user that loads the gemset then runs the sass command (works when I run the new script while logged into the sever in any directory, does not work when called from the capistrano task)

  2. using the capistrano-rvm plugin (adding to Gemfile, requiring in Capfile) to set the RVM gemset - hoping that it would load the gemset before running any commands.

I have used Capistrano many times for deploying Rails apps and always use the asset plugin that handles precompiling and whatnot... This is the first project that I have used for deploying a PHP app and maybe the first time I have tried to manually run a capistrano task that uses a rubygem installed on the server with RVM.

Is it possible to run a task that depends on a specific gem/gemset... without using the default rails plugins?

Any help is appreciated.

Thanks, JD

1

1 Answers

0
votes

figured this one out by requiring the capistrano/bundler command, just to see how capistrano runs bundle by default... copied the bundler command that was logged during a deploy, then modified it to work for what I was trying to do and finally removed the bundler plugin as I do not actually need the deploy to bundle anything.

without using any capistrano plugins, you can preface the capistrano task execute command with the location of the gemset like so:

after :finished, :assets do
  on roles(:app), in: :sequence, wait: 5 do
    within release_path do
      execute "~/.rvm/bin/rvm ruby-2.1.5@deployer do sass #{release_path}/styles/sass/screen.scss #{release_path}/styles/screen.css"
    end
  end
end

The key difference is the following snippet prefaces the actual command I was trying initially:

~/.rvm/bin/rvm ruby-2.1.5@deployer do ....

Obviously, you could use whatever command requiring the gemset specified that you want (instead of the sass command I am using).