heroku run rake db:migrate fails to deploy - ruby-on-rails

I'm trying to deploy my Rails6 app to Heroku
I'm able to successfully build after pushing my app to Heroku but the app immediately crashes.
I just added
group :production do
gem 'pg', '~> 1.2', '>= 1.2.3'
end
to my Gemfile after developing in sqlite so I figured I'd need to migrate which brings me to my error
peter.walker#MACSB-RJ2CLKF45C friends % heroku run rake db:migrate
Running rake db:migrate on ⬢ ptw-friends... up, run.5761 (Free)
Your Ruby version is 2.7.0, but your Gemfile specified 2.6.10
I'm not sure why I'm being told my Ruby version is 2.7.0.
My Gemfile has ruby '2.6.10',
my Gemfile.lock has RUBY VERSION ruby 2.6.10p210,
and my $ ruby -v returns ruby 2.6.10p210 (2022-04-12 revision 67958) [arm64-darwin21]
Could it be from adding
"scripts": {
"start": "rails s"
},
to my package.json?
Could I not be specifying the Ruby version in Procfile?
The full error is here along with my repo
https://github.com/petertimwalker/friends/issues/1

Heroku doesn't support all Ruby versions. When a Ruby version reaches end-of-life and is not maintained anymore then Heroku stops supporting it.
Ruby 2.6 reached end-of-life December last year.
Therefore you need to update your application and your local environment to at least 2.7 when you still want to be able to deploy on Heroku.
Please see the list of Ruby versions supported by Heroku.

install ruby version 2.6.10 and use that version in local
if you using rvm check your current version with rvm list and
install ruby 2.6.10 with rvm install 2.6.10
then use command rvm use 2.6.10

Related

Ruby-on-Rails: Cannot set correct Ruby Version

Dearest Community.
Here's an odd one, and I cannot figure this one out myself.
I am about to deploy a Ruby-on-Rails app to a production server. I like to keep all versions consistent between development and production as you do.
In my Gemfile I set the Ruby version to 2.7.1 (correctly), and on development I installed 2.7.1 and use that version locally for this specific project. All works just fine! - here's the entry:
Gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.2'
...
The Problem:
On production I installed and use (via rbenv) ruby 2.7.1. And I verified that the version is installed & in use! However, when it try to migrate my database or do any other task for that matter it outputs the following
Your Ruby version is 2.7.0, but your Gemfile specified 2.7.1
I do not even have 2.7.0 installed. So for the sake of it I edited the Gemfile on production to run the test. For the purpose of the test I set the ruby verions to 2.7.0 and run another command that fires up the rack. Now the message is:
Your Ruby version is 2.7.1, but your Gemfile specified 2.7.0
What is happening?! I have never ever had or saw a similar issue before. Any help is much appreciated! Thank you!
Here are the environment details:
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.1 LTS (Focal Fossa)"
ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]
$ rails -v
Rails 6.0.3.2
$ bundle -v
Bundler version 2.1.4
I find the best solution is to uninstall all versions of ruby from your ruby version manager (not familiar with rbenv, but you should be able to listed all installed versions then one by one uninstall the ones you don't need until only the one you need remains. If you need multiple versions, best setup a script that will let you quickly switch or setup isolated development environments (basically virtual machines), such that you can be sure it only has the version it needs.
After that, it will either work fine or you'll have an error message that might help pin down the root cause of the issue.

How to Create Rails 6 application from within a Rails 5 environment

I'm playing around with a microservice automation pipeline that builds out a bunch of templated code.
Currently, the pipeline code is automatically running via guard and generates a shell script to create databases, create new rails application and other types of assets.
I run ruby & rails within RbEnv and the script that I am executing works fine from the command line, it creates a brand new Rails 6 application.
But, when I run it from guard which has an existing Rails 5.2 environment Application, the new application is built as a Rails 5.2 app.
I have tried overriding certain settings, but it still picks up the environment that my code is running in.
When I run the script from the command line:
echo 'SHOULD CREATE A RAILS APP using VERSION 6.0.0 on RUBY 2.6.3'
gem install rails -v 6.0.0
echo 'rails -v'
rails -v
echo 'rbenv local'
rbenv local
echo 'rbenv version'
rbenv version
echo 'rbenv versions'
rbenv versions
rails _6.0.0_ new . -d postgresql --force --skip-action-mailer --skip-action-mailbox --skip-action-text --skip-spring --skip-test --skip-bundle --skip-webpack-install
I get the following output log
Successfully installed rails-6.0.0
1 gem installed
SHOULD CREATE A RAILS APP using VERSION 6.0.0 on RUBY 2.6.3
rails -v
Rails 6.0.0
rbenv local
2.6.3
rbenv version
2.6.3 (set by /Users/myname/dev/myapp/.ruby-version)
rbenv versions
system
2.4.1
2.4.6
2.5.3
* 2.6.3 (set by /Users/myname/dev/myapp/.ruby-version)
With following GEM file
ruby '2.6.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.0'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
And confirmation via the last line that the application is Rails 6
remove config/initializers/new_framework_defaults_6_0.rb
When I run the same script from ruby using variations on system and fork { exec { } }
Dir.chdir File.dirname(output_file) do
# fork { exec("bash #{output_file}") }
system "bash #{output_file}"
# system "/usr/local/bin/zsh #{output_file}"
end
I get Rails 5.2
rails -v
Rails 5.2.3
rbenv local
rbenv: no local version configured for this directory
rbenv version
2.5.3 (set by RBENV_VERSION environment variable)
rbenv versions
system
2.4.1
2.4.6
* 2.5.3 (set by RBENV_VERSION environment variable)
2.6.3
I don't really understand why you'd want to do this in ruby, it seems like you're trying to reinvent something like what docker or kubernetes already has solved pretty well.
But I suspect the problem with your script is the bash session doesn't have the rbenv stubs you want. I would find where they are on your computer or server's filesystem and then specify exact paths to them when running commands like gem, rails, or bundler.

rails -v keeps saying Rails 3.2.13 after installing 4.2.2

What gives?
I typed this in gem install rails -v 4.2.2
After that, I tried rails -v, and it keeps coming out Rails 3.2.13
Why is this?
My ruby version after ruby -v
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14]
You can manage gems with bundler (http://bundler.io/)
Put this on your Gemfile
source 'https://rubygems.org'
gem 'rails', '4.2.2'
gem install bundler
and then
bundle install
bundle exec rails -v
If you still working without bundler, you can make
gem list
look at your rails version and then uninstall older versions
gem uninstall rails --version 3.2.13
and then
rails -v
I've encountered this before. And this is what I did.
Change version of rails
Just change the versions.
If you have multiple versions of Rails installed, you'll get conflicting information like this.
If you need to run a command with a specific version of Rails, you can specify the version as part of the command, eg.
rails _4.2.2_ -v
That will tell you you are using Rails 4.2.
Once you've created a new app by doing something like rails _4.2.2_ new app_name, then the Gemfile for that app will specify Rails 4.2.2 and you can drop the special prefix.

Openshift ssh incorrect ruby version on bundle install?

I have a Ruby 2.0 rails 4 app on openshift.
When I ssh into my application and run bundle install I get a message saying: 'Your Ruby version is 1.8.7, but your Gemfile specified 2.0.0'.
When running ruby -v, I get : "ruby 2.0.0p353..."
Running gem environment it also says Ruby 2.0.
Also on my local machine everything is working fine.
Why does my bundle install think I'm using ruby 1.8.7 on the openshift server?
I think your bundler was installed before Ruby upgrade to 2. Try to install your bundler again using gem install bundler and then run bundle install
Let me know if it works

Bundle is switchng my rails version but I have no gem file. How to stop this?

I create a gemset with
$ rvm gemset create r3
$ rvm gemset use r3
$ gem install rails -v3.2.13
At this point
$ rails -v
now shows
$ Rails 3.2.13
but every time I do bundle with a project I've forked, I find that
rails -v
shows Rails 4.0.1 - which then gives issue with the project in question when running tests
(4.0.1 conflicts with 3.2.13).
My question is - if my Gemfile only has:
$ cat Gemfile
source 'https://rubygems.org'
gemspec
how is this happening? How can I make my command line ruby version stay at 3.2.13 and not switch to 4.0.1 Once it switches to 4.0.1 I seem to be stuck with that for that gemset and to create a 3.2.13 gemset I have to start over again.
Bundle works by finding the most up-to-date version of the gems that are compatible with the restrictions from the Gemfile. In this case, those restrictions are coming from the gemspec file, which presumably allows versions of Rails greater than 3.2.13. So it's picking the most up-to-date version of Rails allowed - which is 4.0.1. Your RVM configuration is not relevant here.
To lock your particular fork to Rails 3.2.13, just add the following:
gem 'rails', '3.2.13'
to the Gemfile in your fork. This will lock the local version to 3.2.13 when you run bundle.
if you wish to explicitly use different version of rails then the one that would be calculated from Gemfile then you need to use:
NOEXEC_DISABLE=1 rails ...
you can make it permanent for single shell session with:
export NOEXEC_DISABLE=1
rails ...
and to disable loading gems in versions calculated via Gemfile put it in you shell initialization file (like ~/.bash_profile or ~/.zlogin):
export NOEXEC_DISABLE=1
this happens because RVM installs gem rubygems-bundler which automatically analyzes your Gemfile when you run gem binaries and if a version specified via this file is available then it is loaded (even if it is specified only as dependency of your gems).

Resources