Changing Ruby and Rails version with capistrano and rvm - ruby-on-rails-5

What are the correct steps for changing the configuration of my project when change the ruby and rails version, using rmv.
For example, I have to change in deploy.rb set :rvm_ruby_version, '2.4.0#5.1', but what else?
I can't get Capistrano use the correct rvm gemset, and allways tries to bundle install with the old rvm gemset
Do I have to change something in the production server? I think so, but in some order, before deploy and then after deploy some other changes...¿?
I have tried capistrano-rvm , rvm-capistrano, and finally rvm1-capistrano3
When I run cap production depoly, I get these errors, all arround "Could not determine which Ruby to use"
DEBUG [e2eccae9] Running /home/rails/www/digitalshelving/rvm1scripts/rvm-auto.sh . bundle check --path /home/rails/www/digitalshelving/shared/bundle as rails#46.101.100.14
DEBUG [e2eccae9] Command: cd /home/rails/www/digitalshelving/releases/20180303130204 && /home/rails/www/digitalshelving/rvm1scripts/rvm-auto.sh . bundle check --path /home/rails/www/digitalshelving/shared/bundle
DEBUG [e2eccae9] Could not determine which Ruby to use; . should contain .rvmrc or .versions.conf or .ruby-version or .rbfu-version or .rbenv-version, or an appropriate line in Gemfile.
DEBUG [e2eccae9] Can not find ruby for '.'.
DEBUG [e2eccae9] Finished in 0.684 seconds with exit status 103 (failed).
INFO [c22dc933] Running /home/rails/www/digitalshelving/rvm1scripts/rvm-auto.sh . bundle install --path /home/rails/www/digitalshelving/shared/bundle --without development test --deployment --quiet as rails#46.101.100.14
DEBUG [c22dc933] Command: cd /home/rails/www/digitalshelving/releases/20180303130204 && /home/rails/www/digitalshelving/rvm1scripts/rvm-auto.sh . bundle install --path /home/rails/www/digitalshelving/shared/bundle --without development test --deployment --quiet
DEBUG [c22dc933] Could not determine which Ruby to use; . should contain .rvmrc or .versions.conf or .ruby-version or .rbfu-version or .rbenv-version, or an appropriate line in Gemfile.
DEBUG [c22dc933] Can not find ruby for '.'.
Thanks

In Rails.root create file with name .ruby-version and following content:
2.3.3
or whatever version you want. When you or capistrano cd to root folder rvm will change ruby version according to file's content

Related

How do I `bundle install` with Chef?

I am using Chef to provision a CentOS 6.5 box and install my Rails 4.0.4 app.
I installed RVM and Ruby 2.1.1
When I cd my_website, RVM will set the correct ruby version (gemset).
How do I tell Chef to bundle with the correct ruby version
currently I am using this:
execute "bundle-install" do
user "my_user"
cwd "/home/my_user/website/"
command "bundle install"
action :run
end
But that is not enougth, it's still trying to use ruby 1.9.3
RVM is a shell-based Ruby version manager. Since the Chef Client runs as root, it probably isn't executing the login shell. So things like .rvmrc and the actual loading of RVM are ignored. Handling this with Chef is a bit complicated. I would recommend looking at Fletcher's chef-rvm cookbook.

An error occurred while installing pg (0.12.2), and Bundler cannot continue

I'm following the Michael Hartl Ruby on Rails Tutorial & there is a part where he is he he instructs you to update your Gemfile to include:
group :production do
gem 'pg', '0.12.2'
end
And then enter the below commands in your terminal:
bundle update
bundle install --without production
When you run the bundle update command it throws back the below errors.
sample_app:$ bundle update
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Using rake (10.0.3)
Using i18n (0.6.4)
etc
[omitted lines for brevity]
etc
Using railties (3.2.12)
Using coffee-rails (3.2.2)
Installing diff-lcs (1.1.3)
Using jquery-rails (2.0.2)
Installing pg (0.12.2)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/ross/.rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
etc
[omitted lines for brevity]
etc
Gem files will remain installed in /home/ross/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.12.2 for inspection.
Results logged to /home/ross/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.12.2/ext/gem_make.out
An error occurred while installing pg (0.12.2), and Bundler cannot
continue.
Make sure that `gem install pg -v '0.12.2'` succeeds before bundling.
sample_app:$
I was able to overcome this error easily be removing the 'pg', '0.12.2' gem from the Gemfile & replacing it after running the bundle update command. This seems to work fine as the 'pg', '0.12.2' gem is aslo omitted in the without production flag in the latter bundle install --without production.
The 'pg', '0.12.2' gem is only needed for deploying to heroku with the correct database & everything works fine even when I deployed it to heroku but I'm just wondering if this is an error in the Tutorial or am I missing something bigger here?
It's also annoying to have to remove this Gem everytime I run bundle update, is bundle update really that necessary?
Thanks in Advance
I'm following the same tutorial and I think it's redundant to run update without modifying existing dependency, but in this case it's even causing problems because update command has not --without argument.
I stumbled upon Rails 3 cheatsheet which mentions bundler workflow this way:
After adding or removing dependencies from Gemfile
$ bundle
Commit Gemfile and Gemfile.lock
After modifying existing dependency versions
$ bundle update
Commit Gemfile and Gemfile.lock
I read man pages for bundle update and tried RECOMMENDED WORKFLOW which consists of running bundle update after bundle install.
In my case (some output omitted):
$ bundle install --without production
Resolving dependencies...
Using rake (10.0.3)
...
Installing rspec-core (2.11.1)
Your bundle is complete!
Gems in the group production were not installed. <-- check
$ bundle update
Resolving dependencies...
Using rake (10.0.3)
...
Using uglifier (1.2.3)
Your bundle is updated!
Gems in the group production were not installed. <-- check
I tried it with new RVM gem set and everything was installed correctly.
After that Gemfile.lock contains pg (0.12.2) and deploying to Heroku works.
RECOMMENDED WORKFLOW
In general, when working with an application managed with bundler, you
should use the following workflow:
After you create your Gemfile for the first time, run
$ bundle install
Check the resulting Gemfile.lock into version control
$ git add Gemfile.lock
When checking out this repository on another development machine, run
$ bundle install
When checking out this repository on a deployment machine, run
$ bundle install --deployment
After changing the Gemfile to reflect a new or update dependency,
run
$ bundle install
Make sure to check the updated Gemfile.lock into version control
$ git add Gemfile.lock
If bundle install reports a conflict, manually update the specific
gems that you changed in the Gemfile
$ bundle update rails thin
If you want to update all the gems to the latest possible versions
that still match the gems listed in the Gemfile, run
$ bundle update
Installation of postgres fails with this error : "Can't find the 'libpq-fe.h header"
Looks like a lot of people faced this problem, good news is : stackoverflow has the answer ;)
Can't find the 'libpq-fe.h header when trying to install pg gem
(or at least it should help you to look in the right direction)

cap deploy:migrations fails with Could not locate Gemfile

I'm working on my first rails deployment and having a problem I can't figure out.
mac osx 10.8.2
ruby 1.8.7
Rails 3.2.6
rvm 1.17.2
I've been following this tutorial http://brandnewrails.wordpress.com/ and got stuck on 7c.
I set it all up in RVM, got git running on the server, ran bundle install in the app, and wrote the Capistrano recipe in my_app/config/deploy.rb
Then I ran:
$ capify . no problem
$ cap deploy:setup no errors
$ cap deploy:check returned You appear to have all necessary dependencies installed
$ cap deploy:migrations is where the problem happens. After successfully running a bunch of the commands, capistrano fails. See below:
2012-12-10 00:43:56 executing `bundle_install'
* executing "cd /home/{servername}/party/releases/20121209134354 && bundle install --path vendor/bundle"
servers: ["{servername}"]
[{servername}] executing command
** [out :: {servername}] Could not locate Gemfile
command finished in 694ms
failed: "sh -c 'cd /home/alexchee/party/releases/20121209134354 && bundle install --path vendor/bundle'" on {servername}
Does anyone know what to do? When I check the app directory, the Gemfile is there. Any ideas or further questions?
The inability of capistrano to locate a Gemfile in this case seems to be a symptom of not having initiated git in the app locally, that is on my own computer.
My hunch is that since Gemfile is the first file in the list above, that is why it created an error first. If the program had continued, it would have probably had other errors as well.
Even if git is running on the server and the app is bundled up correctly, you must also initiate git locally and direct it to the appropriate files on your server in order for the deploy to work.
Great instructions are listed here: http://brandnewrails.wordpress.com/2012/10/14/lesson-7b/

Capistrano & jruby & rvm - Bundler::GemNotFound: Could not find rake-0.9.2.2 in any of the sources

I encountered Bundler::GemNotFound: Could not find rake-0.9.2.2 in any of the sources during deploying my application using capistrano, and when processing deploy:assets:precompile.
The command is:
cd /opt/app/deploy/entercamp/releases/20120627132117 && /usr/local/rvm/rubies/jruby-1.6.7/bin/jruby --1.9 -S bundle exec rake RAILS_ENV=staging RAILS_GROUPS=assets assets:precompile
I tried the command manually on the server and it works quite ok. And I could see that rake-0.9.2.2 is installed in the result output of bundle:install in the deploy process.
Where could be the problem?
Detailed information is in: https://gist.github.com/3005237
This just got fixed with help of Michal from rvm-capistrano project.
It raises this error is because jruby is install with version 1.8 by default and it tries to switch to 1.9 when deploying and that causes the problem.
The solution is to install jruby with version 1.9 by default: rvm install jruby-1.6.7.2 --1.9 and then it works.

RVM 1.0.2 fails to build ruby 1.9.2

This fails every time. I ran rvm remove 1.9.2 and then rvm install 1.9.2.
The error looks like this:
info: Applying patch '' (located at /)
error: Error running 'patch -F25 -p1 -f <"/"',
please check /Users/peter/.rvm/log/ruby-1.9.2-p0/patch.apply.*.log
fail: There has been an error applying the specified patches.
Aborting the installation.
And the log shows this:
[2010-09-05 19:38:14] patch -F25 -p1 -f <"/"
patch: **** read error : Is a directory
This worked fine with rvm 1.0.1.
Any idea what's up and how I can roll back rvm to 1.0.1?
For me, simply running rvm update (without --head) let Ruby 1.9.2 install right.