Last Updated: February 25, 2016
· dangaytan

Use envdir with Capistrano v3

I was trying to use envdir in a Capistrano deploy so I needed to prefix all rake commands with envdir secret. After an hour of looking at capistrano codes, I saw that behind its magic was sshkit.

What I did was set an after rvm:hook to prefix the rake as follows:

after 'rvm:hook', 'deploy:prefix_rake'

desc 'Overwrites the default rake command and adds a prefix'
task :prefix_rake do
  SSHKit.config.command_map[:rake] = "envdir secret #{ SSHKit.config.command_map[:rake] }"

What command_map does is set the command to run when you do execute :command. It should be a symbol to get it to work.

Now it works nicely with capistrano-rvm and sets the env vars before any :rake is executed.