Ruby version error on deployment with capistrano - ruby-on-rails

I am getting ' Your Ruby version is 2.3.3, but your Gemfile specified 2.0.0' when I am trying to deploy with Capistrano.
my gemfile specifying 2.3.3
ruby "2.3.3"
00:27 bundler:install
01 /usr/local/rvm/bin/rvm 2.3.3 do bundle install --path /var/www/mypath/shared/bundle --without development test --deployment --quiet
01 Warning, new version of rvm available '1.29.1', you are using older version '1.29.0'.
01 You can disable this warning with: echo rvm_autoupdate_flag=0 >> ~/.rvmrc
01 You can enable auto-update with: echo rvm_autoupdate_flag=2 >> ~/.rvmrc
01 Your Ruby version is 2.3.3, but your Gemfile specified 2.0.0

Don't know what the problem is from looking at this, but here is how I would debug it.
Check your Gemfile and Gemfile.lock and verify it is showing 2.3.3. Also Capistrano pulls directly from the repository rather than uploading your local files so verify your Gemfile and Gemfile.lock on the remote machine have the right versions. If they don't, verify you have committed the latest Gemfile and Gemfile.lock and pushed them up to your repository. You can also try just running bundle on the remote machine to take Capistrano out of the equation.

Related

Rails deployment on ec2

I am using Capistrano to deploy my rails app to ec2 VM. I am following along with this tutorial https://gist.github.com/ThomasBush/584dc1e999b34177dd4436c5edb1b24d
I am using ruby version 2.6.5
Capistrano Log:
DEBUG [3b5b580d] Command: cd /home/deploy/editorial_board/releases/20210607071516 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.6.5" ; $HOME/.rbenv/bin/rbenv exec bundle install --jobs 4 --quiet )
DEBUG [3b5b580d] Your Ruby version is 2.6.5, but your Gemfile specified 2.7.1
I have checked ruby -v in my local machine and on ec2 VM and i am getting my ruby version 2.6.5
Also in my gemfile specified version is 2.6.5
In .ruby-version file version is 2.6.5
In Capfile set :rbenv_ruby, '2.6.5'
I am not getting where 2.7.1 is specified, and how to get it deployed
delete Gemfile.lock and run bundle install again.
And check if you installed rbenv on your ec2 instance.

Capistrano bundle install trying to install development gems on server

I have a development gem that is trying to be installed on the server via capistrano and is failing b/c i'm pointing to github at the moment.
Why is this gem trying to be installed on my server anyways?
Gemfile snippet:
gem 'capistrano-local-precompile', '~> 1.0', :git => 'git#github.com:stve/capistrano-local-precompile.git', :branch => 'cap3', :group => :development, require: false
Capistrano snippet output:
00:08 bundler:install
01 ~/.rvm/bin/rvm 2.3.3 do bundle install --path /var/www/csmschedule/shared/bundle --without development test --quiet --no-cache
01 The authenticity of host 'github.com (192.30.253.112)' can't be established.
01
01 RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Is the GIT section for capistrano-local-precompile present in your Gemfile.lock, and is that lock file committed to your repo? In other words, have you run bundle install locally, committed both Gemfile and Gemfile.lock, and pushed those changes before running cap deploy?
Bundler needs to know the dependencies of the capistrano-local-precompile gem in order to do version resolution. Even if you specify --without development, it still needs this information (because version requirements of development gems can affect version resolution for production ones).
If your lock file is not present or if it is out of date (i.e. capistrano-local-precompile is not in the lock file), then Bundler needs to download the gem from GitHub in order to update the lock file.
On a related note: I notice you are not using --deployment in the bundle command on the server. That is probably not a good idea. You should use --deployment so that Bundler checks that your Gemfile.lock is up to date, as described here:
http://bundler.io/v1.15/man/bundle-install.1.html#DEPLOYMENT-MODE

How to manually update a gem in the capstrino environment

We have a codebase, which is used as a gem in the older codebase. After deployment we see that, the older code in the gem is getting executed. Now we want to manually update the gem in the server
here is what capistrino is doing
bundler:install
01 ~/.rvm/bin/rvm 2.3.0 do bundle install --path /home/deployer/bla/shared/bundle --without development test --deployment --quiet
01 Warning, new version of rvm available '1.28.0', you are using older version '1.27.0'.
01 You can disable this warning with: echo rvm_autoupdate_flag=0 >> ~/.rvmrc
01 You can enable auto-update with: echo rvm_autoupdate_flag=2 >> ~/.rvmrc
So I went into the bundle folder and I did
bundle update gem_name.
It said it could not find the gemfile. And the contents of the bundle folder is just ruby. Is there a way that I can manually update the gem? Any help would be greatly appreciated.
Bundler doesn't work that way. Even if you updated the gem, if your Gemfile/Gemfile.lock still reference the old version, that's the one that will be loaded. If it's not available, then your app won't boot.
If you want to update the gem in your production environment, you need to run bundle update gem_name inside your app directory, where the Gemfile is located. Assuming you haven't picked a too-specific version in your Gemfile, this will modify your Gemfile.lock and install the new gem.

bundler and rvm are using different rubies

I have the gist of the difference between rvm and bundler. On my local machine, I use rvm to manage different rubies and different gemsets for those rubies. For example I have a ruby 2.1.2 with a gemset called core:
$ rvm-prompt
ruby-2.1.2#core
$ rvm gemdir
/Users/donato/.rvm/gems/ruby-2.1.2#core
$ cd /Users/donato/.rvm/gems/ruby-2.1.2#core/gems
$ ls
actionmailer-4.1.10
...
As you can see, I have a ruby 2.1.2 and a gemset core for that ruby. When I run my project, rails looks for the gems located in /Users/donato/.rvm/gems/ruby-2.1.2#core/gems. It DOES NOT look for the gems at shared/bundle. In fact, I don't even have a shared directory at my Rails root in my local machine.
So on my local machine, while bundler manages gem dependencies and adds gems if new ones found in Gemfile, it does not manage the LOCATION of the gems' installation. It installs the gems in rvm gemdir. In fact, when you run bundle install and a new gem exists in Gemfile, then bundler actually installs the gem in rvm's gem directory.
What's confusing is that this is not how it works in staging or production deploy. It appears bundler looks for gems in the location shared/bundle. So apparently in production, bundler not only wants to install the gems, but it wants to manage the location of the gems as well, and let rvm just worry about rubies, but not gem locations.
This has caused an issue for me. I am using capistrano for deployment. When I run cap staging deploy, It is installing gems in the wrong ruby.
The capistrano script runs this line:
Running /usr/local/rvm/bin/rvm ruby-2.1.2#core do bundle install
--path /var/www/mysite_staging/shared/bundle --without development test --deployment --quiet
You can see that it installs the gems in shared/bundle.
When I go to shared/bundle/ruby after a successful deployment, I see the following directory:
/shared/bundle/ruby/2.1.0
Wait a second! In my capistrano 3 script, which is using capistrano-rvm, I specified the following:
set :rvm_type, :system
set :rvm_ruby_version, 'ruby-2.1.2#core'
If it is recommended to use bundler to manage gem locations in staging and production, at shared/bundle directory, then how should I resolve this issue? Why is bundler installing gems in the wrong ruby version for this project?
so, what would you say the major the difference between your machine and the server you are deploying on?
Look at: http://bundler.io/v1.9/deploying.html
See different behaviour beween dev and deployment and also read note on capistrano.
hope this helps

Deploying rails app on heroku

I'm learning RoR and trying to deploy my test app to heroku receiving next error:
Unresolved dependencies detected; Installing...
Using --without developmen
You have modified your Gemfile in development but did not check
the resulting snapshot (Gemfile.lock) into version control
You have added to the Gemfile:
* therubyracer (~> 0.9.3.beta1)
* pg
FAILED: http://devcenter.heroku.com/articles/bundler
! Heroku push rejected, failed to install gems via Bundler
Please! Help!
Have you committed your Gemfile.lock?
bundle install
git add Gemfile.lock
git commit -am "Add lock file"
git push heroku master
This error might be because you did not completely do bundle install.
First do
bundle install
Add gem 'pg' to the gem file and install the postgres gems and postgres on your local machine. If you dont want to install postgres on your local machine then add gem 'pg to production environment and run bundle install without test environment. Though heroku discourages this way of running your application. It is always better to use same database for running locally and in production. Installing postgres is pain but it is worth it.
Your ruby should be 1.9.2.
After installing all the dependencies and post gres on your machine do bundle install and add your gem file to heroku.
git add Gemfile
git add Gemfile.lock
git commit
git push heroku master

Resources