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

rvm:use without environment parameter #297

Closed
ralfebert opened this issue Apr 2, 2015 · 4 comments
Closed

rvm:use without environment parameter #297

ralfebert opened this issue Apr 2, 2015 · 4 comments

Comments

@ralfebert
Copy link
Contributor

rvm:use[] requires an environment which is unnecessary when the project has a .ruby-version file.

Workaround:

task :environment do
  queue %{
      source /usr/local/rvm/scripts/rvm
      rvm use || exit 1
    }
end
@d4be4st
Copy link
Member

d4be4st commented Jul 5, 2015

Would love a PR with this.
Thx

@ralfebert
Copy link
Contributor Author

Looking a bit more into this, I found out that the workaround doesn't work - it does not take the ruby version according to the .ruby-version file but the default ruby on the system.

I found no way to set the environment according to the .ruby-version file in the current deploy commit - in the environment task the git commit is not cloned yet; and later after cloning; environment variables cannot be set (after queuing a command, the changed environment seems to be thrown away).

I worked around this issue by reading the .ruby-version according to the local file:

task :environment do
  ruby_version = File.read('.ruby-version').strip
  raise "Couldn't determine Ruby version: Do you have a file .ruby-version in your project root?" if ruby_version.empty?
  queue %{
    source /etc/profile.d/rvm.sh
    rvm use #{ruby_version} || exit 1
  }
end

Do you see a way to do this in a more clean way using the file in the deploy commit on the server? If we find a clean solution, I would take the time to create a PR to add this to the rvm task.

@ralfebert
Copy link
Contributor Author

btw, here is a full guide to the setup for which I cooked up this workaround: http://www.ralfebert.de/tutorials/rails-deployment/

@hernandesbsousa
Copy link

👍 for finding a solution to this problem, I had the exact same issue and the workaround @ralfebert provided worked as a charm, thanks!

@d4be4st d4be4st closed this as completed Jul 8, 2016
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

No branches or pull requests

3 participants