Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rbenv #39

Closed
wants to merge 2 commits into from
Closed

Rbenv #39

wants to merge 2 commits into from

Conversation

Arcath
Copy link
Contributor

@Arcath Arcath commented Aug 6, 2012

tl;dr Makes life much easier for those of us using rbenv.

The problem was that ~/.bash_profile wasn't being pulled in which required the use of bundle_bin to get bundler to work and in some cases even resulted in the ruby command not being found, which was the case on a new production server I've had to setup up.

This change causes source ~/.bash_profile to be added as the first command run in the ssh session which results in:

$ mina deploy --verbose

-----> Loading rbenv
       $ source ~/.bash_profile

-----> Creating a temporary build path
       $ touch "deploy.lock"

It also adds a task for checking the ruby version (for debugging only):

invoke :'rbenv:ruby_version'

which appears like this in the output:

-----> Checking Ruby version
       $ ruby -v
       ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]

For rbenv users this render the need for bundle_bin and any other patches redundant and only needs tem to add

require 'mina/rbenv'

to the top of their config/deploy.rb

@rstacruz
Copy link
Member

rstacruz commented Aug 7, 2012

Hm, I'm not sure about the idea of sourcing ~/.bash_profile. Profile files are usually made for interactive shells, and will cause problems in some setups. For instance, I have my profile set up on some servers to automatically show some system info when I log in. These will be executed every time I run a Mina task, which I don't want to happen.

A better solution may be:

  1. Use export PATH="${HOME}/.rbenv/shims:${PATH}" instead, which is the line injected to ~/.bash_profile that makes RVM work, or
  2. Use a prefix rbenv exec for all Ruby commands.

I kind of like #1, but I don't want it to be built-in assumption that can't be changed.

cc @mikong

@rstacruz
Copy link
Member

rstacruz commented Aug 7, 2012

I think a better solution would be to implement a special task that is executed for every Mina task that's meant to set up the environment:

task :environment do
  queue echo_cmd %[export PATH="${HOME}/.rbenv/shims:${PATH}"]
end

Or much nicer this way:

require 'mina/rbenv'
task :environment => [ 'rbenv:load' ]

# In mina/rbenv.rb:
task :'rbenv:load' do
  queue echo_cmd %[export PATH="${HOME}/.rbenv/shims:${PATH}"]
end

Also, Rake supports defining tasks multiple times and they all get executed in serial, which lends very well to this standard.

We may even be able to add explicit support for RVM by making an rvm:load task which loads ~/.rvm/scripts/rvm.

require 'mina/rvm'
task :environment => [ "rvm:load[1.9.3-p142@project]" ]

# In mina/rvm.rb:
task :'rvm:load[gemset]' do |t, args|
  queue echo_cmd %[source "$HOME/.rvm/scripts/rvm"]
  queue echo_cmd %[rvm use "#{gemset}"]
end

Related #5. cc @mikong.

@rstacruz rstacruz closed this Aug 7, 2012
rstacruz added a commit that referenced this pull request Aug 7, 2012
rstacruz added a commit to mina-deploy/mina-docs that referenced this pull request Aug 7, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants