Cannot push to Heroku (gemfile.lock issue) - ruby-on-rails

Summary:
When pushing to my staging app, Heroku complains that bundle install failed and that I need to run bundle install elsewhere and version the resulting Gemfile.lock. The problem is that I've already done this and committed it.
How do I fix this?
Issue:
Due to some inherited awfulness at work, I had to debug and fix several things in production. Everything's working now, but this means our master branch is ahead of staging by 10+ commits, including some gem changes. I merged them and attempted to push to my staging app on Heroku.
However, I didn't run bundle install after merging in the changes (shame on me), so Heroku correctly complained.
To fix this, I ran the standard:
bundle install
git add Gemfile.lock
git commit -m "Updated gem bundle"
git push staging
However, Heroku is still complaining about Gemfile.lock:
Counting objects: 228, done.
Delta compression using up to 6 threads.
Compressing objects: 100% (179/179), done.
Writing objects: 100% (192/192), 24.38 KiB | 0 bytes/s, done.
Total 192 (delta 127), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Using set buildpack heroku/ruby
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.2.2
remote: -----> Installing dependencies using bundler 1.11.2
remote: Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote: You are trying to install in deployment mode after changing
remote: your Gemfile. Run `bundle install` elsewhere and add the
remote: updated Gemfile.lock to version control.
remote: You have deleted from the Gemfile:
remote: * ruby-drupal-hash
remote: Bundler Output: You are trying to install in deployment mode after changing
remote: your Gemfile. Run `bundle install` elsewhere and add the
remote: updated Gemfile.lock to version control.
remote:
remote: You have deleted from the Gemfile:
remote: * ruby-drupal-hash
remote: !
remote: ! Failed to install gems via Bundler.
remote: !
remote:
remote: ! Push rejected, failed to compile Ruby app
remote:
remote: Verifying deploy...
remote:
remote: ! Push rejected to redacted-staging.
remote:
To https://git.heroku.com/redacted-staging.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/redacted-staging.git'
Also:
Gemfile.lock is not in .gitignore
bundle install runs fine, and does not update any gems (as I've run it several times now).
To verify my sanity, I checked git status and git log to ensure I actually added and committed the changes; I'm apparently not crazy (though please correct me if i'm wrong).
To reiterate:
I have already run bundle install and added & committed Gemfile.lock
How do I fix this?
What am I missing?
Update:
I've tried
running bundle update which updated 26 gems; committing the new Gemfile.lock and pushing results in the same error.
Deleting and re-bundling produces an identical Gemfile.lock. Adding a newline and pushing results in the same error.
Removing Bundler's version info from Gemfile.lock and pushing results in the same error.
I even re-addded the ruby-drupal-hash gem, ran bundle install, and pushed the new Gemfile and Gemfile.lock files. Interestingly, the error message about me deleting ruby-drupal-hash persisted despite it being present again.

I assume that you are working locally on different OS then your server is, for example windows vs Unix.
In order to fix it you simply have to build it with the following flag:
bundle install --deployment
If this is not working as well, simply delete the .lock file and let it be generated again in the same flow as you did before with install/update

Yeah, trying to run bundle update or if it didn't work, I think this line it's look interesting:
remote: You have deleted from the Gemfile:
remote: * ruby-drupal-hash
remote: Bundler Output: You are trying to install in deployment mode after changing
remote: your Gemfile. Run `bundle install` elsewhere and add the
remote: updated Gemfile.lock to version control.
remote:
remote: You have deleted from the Gemfile:
remote: * ruby-drupal-hash

It seems it is complaining about ruby-drupal-hash being removed from Gemfile but Gemfile.lock not reflecting it.
You have deleted from the Gemfile:
remote: * ruby-drupal-hash
I would check the Gemfile and Gemfile.lock for that particular gem and see if that is the problem.

The answer was deceptively simple (of course):
git push staging staging:master
The issue was that I was on the staging branch and needed to update my Heroku staging server's master branch.
Shame on me for overlooking something so obvious!
... and shame on Heroku's decidedly unhelpful output.

For future internet explorers, I had a similar situation.
I had to change the version of a gem dependency, so I had to manually add "Execjs, '2.7.0'" to my gemfile, since another gem update had pulled it to 2.8.0 and that was causing an issue on Heroku.
Once I got the dependency updated, I removed the gem from the gemfile (while it remained in the gemfile.lock) and never did a bundle install to clean up the gemfile.lock When I tried to push to Heroku, it broke and I got the same error.
To fix, I ran bundle install on the master branch and then committed the new gemfile.lock and then pushed to Heroku and it deployed as expected.
VERY stressful morning for me! :-)

Related

Heroku Rails deployment/build error: Could not find 'bundler' (version) required by your Gemfile.lock

I have a Ruby on Rails and Redux/React app I have already pushed dozens of times to heroku via "git push heroku master" and it builds correctly. I recently tried to create a staging environment. After setting the remote, I run
git push staging master
And the webpack portion builds correctly, but once Heroku tries to build the Rails portion I get this error.
remote: ! Could not detect rake tasks
remote: ! ensure you can run `$ bundle exec rake -P` against your app
remote: ! and using the production group of your Gemfile.
remote: ! Activating bundler (2.0.1) failed:
remote: ! Could not find 'bundler' (2.0.1) required by your /tmp/build_687b8b1cf6d6cbb297288640ccb0d405/Gemfile.lock.
remote: ! To update to the latest version installed on your system, run `bundle update --bundler`.
remote: ! To install the missing version, run `gem install bundler:2.0.1`
remote: ! Checked in 'GEM_PATH=vendor/bundle/ruby/2.5.0', execute `gem env` for more information
remote: !
remote: ! To install the version of bundler this project requires, run `gem install bundler -v '2.0.1'`
To create the staging environment, I ran
heroku create --remote staging
in the root folder of the project.
I also have tried updating the bundler.
bundle update --bundler
&
gem install bundler:2.0.1
I tried precompiling assets as well, but nothing.
RAILS_ENV=production bundle exec rake assets:precompile
I ran
bundle exec rake -P
as suggested, but that did not fix it as well.
Another thing is when I push successfully, in the logs it shows I am using a different ruby version
Using Ruby version: ruby-2.3.4
remote: -----> Installing dependencies using bundler 2.0.2
In the staging logs it shows
Using Ruby version: ruby-2.5.5
remote: -----> Installing dependencies using bundler 2.0.2
Not sure if that helps. But any possible solutions can help!
Thanks!
The solution to issues like these it to ensure all environments (development, staging, production, CI) share the same Ruby version. This will make development and testing much more predictable.
Specify your Ruby version in the Gemfile (this build worked with Ruby 2.3.4, so that's what we'll use):
# Gemfile
ruby '2.3.4'

Pushing Rails to Heroku, can't find Rake taks

UPDATE: now using Ruby 2.5.5 and Bundler 2.0.2, still getting the error:
/app/tmp/buildpacks/<long hash>/lib/language_pack/helpers/rake_runner.rb:106:
in load_rake_tasks!':
Could not detect rake tasks (LanguagePack::Helpers::RakeRunner::CannotLoadRakefileError)`
I'm trying to git push heroku master a Rails app for the first time, and I'm getting this error:
remote: -----> Detecting rake tasks
remote:
remote: !
remote: ! Could not detect rake tasks
remote: ! ensure you can run `$ bundle exec rake -P` against your app
remote: ! and using the production group of your Gemfile.
remote: ! Activating bundler (2.0.1) failed:
remote: ! Could not find 'bundler' (2.0.1) required by your /tmp/build_cf9981ccbdc1fd4f0b82703a5ff40ecc/Gemfile.lock.
remote: ! To update to the latest version installed on your system, run `bundle update --bundler`.
remote: ! To install the missing version, run `gem install bundler:2.0.1`
remote: ! Checked in 'GEM_PATH=vendor/bundle/ruby/2.5.0', execute `gem env` for more information
remote: !
remote: ! To install the version of bundler this project requires, run `gem install bundler -v '2.0.1'`
remote: !
remote: /app/tmp/buildpacks/b7af5642714be4eddaa5f35e2b4c36176b839b4abcd9bfe57ee71c358d71152b4fd2cf925c5b6e6816adee359c4f0f966b663a7f8649b0729509d510091abc07/lib/language_pack/helpers/rake_runner.rb:106:in `load_rake_tasks!': Could not detect rake tasks (LanguagePack::Helpers::RakeRunner::CannotLoadRakefileError)
remote: ensure you can run `$ bundle exec rake -P` against your app
remote: and using the production group of your Gemfile.
remote: Activating bundler (2.0.1) failed:
remote: Could not find 'bundler' (2.0.1) required by your /tmp/build_cf9981ccbdc1fd4f0b82703a5ff40ecc/Gemfile.lock.
remote: To update to the latest version installed on your system, run `bundle update --bundler`.
remote: To install the missing version, run `gem install bundler:2.0.1`
remote: Checked in 'GEM_PATH=vendor/bundle/ruby/2.5.0', execute `gem env` for more information
remote:
remote: To install the version of bundler this project requires, run `gem install bundler -v '2.0.1'`
I have run gem install bundler:2.0.1 successfully in this app's root directory. My $GEM_PATH does not include vendor/bundle/ruby/2, and I don't know if altering it is the solution. If so, does that mean I need to alter it locally or remotely? If locally, is it done the same way as normal environment variables, or is there a special Rails setting I need to change?
I have tried the suggestion in the accepted answer here:
heroku push error: "Could not detect rake tasks"
but that made no difference.
My problem also seems to be similar to the (unanswered) question here:
Can't Push Rails Project to Heroku
Searching the Heroku Help Center didn't seem to yield any results, either.
Any guidance about what I should do?
This is a known issue with Bundler 2 on Heroku:
A Gemfile.lock that specifies bundler 2.0.2 does not work with bundler 2.0.1
If you attempt to deploy an app that uses bundler 2.0.2 onto the Heroku platform with bundler 2.0.1 you may get this error:
`find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
This is due to a bug in the Rubygems bundler version checking code. To avoid this issue, upgrade your Ruby version. It is fixed in 2.5.5+ and 2.6.3+. If you do not update, your Ruby version then every new release of Bundler 2.x will trigger this issue.
Upgrade Ruby to version 2.5.5+ or 2.6.3+ locally, update your Gemfile accordingly, and re-run bundle. Commit the changes to your Gemfile and Gemfile.lock, then deploy again.

Heroku push rejected, the path to rails engine does not exist

When attempting to deploy my rails app on heroku,
git push heroku master
I get the following error:
remote: Fetching gem metadata from https://rubygems.org/........
remote: The path `/tmp/fullcalendar-rails-engine` does not exist.
remote: Bundler Output: Fetching gem metadata from https://rubygems.org/........
remote: The path `/tmp/fullcalendar-rails-engine` does not exist.
remote: !
remote: ! Failed to install gems via Bundler.
remote: !
remote:
remote: ! Push rejected, failed to compile Ruby app
The path is referencing a rails engine (https://github.com/vinsol/fullcalendar-rails-engine) which is included in my Gemfile. However I don't ever reference a tmp folder in '/tmp/fullcalendar-rails-engine'.
I'm not sure how to address this issue. Just to see if I could deploy my app, I tried removing the gem from the Gemfile and commented out the mounting in my app but even when trying to push the deploy after that, I still received the same error.
Might be a bit of a dirty fix, but I added the indicated folder to the tmp folder of the project. Still curious about why this happened and if making that actually solved anything.

Heroku / Bundler / Push issue: Could not find rake-0.8.7 in any of the sources

For the life of me I can not figure out how to fix this issue. I have looked around for the whole day and found simular issues but they all seem to be slightly different.
-----> Heroku receiving push
-----> Rails app detected
-----> Configure Rails to log to stdout
Installing rails_log_stdout... done
-----> Gemfile detected, running Bundler version 1.0.7
Unresolved dependencies detected; Installing...
Using --without development:test
Your Gemfile doesn't have any sources. You can add one with a line like 'source:rubygems'
Could not find rake-0.8.7 in any of the sources
FAILED: http://docs.heroku.com/bundler
! Heroku push rejected, failed to install gems via Bundler
error: hooks/pre-receive exited with error code 1
To git#heroku.com:smooth-wind-620.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git#heroku.com:
Bundle install and bundle list both have rake listed.
Have you tried adding something like source 'http://rubygems.org' to the top of your Gemfile, or source :gemcutter? That's the first error I see heroku giving you and would be the first thing I would try to resolve.

Gemfile.lock not checked in - Heroku

While trying to "git push heroku master", I keep getting the error :
Counting objects: 266, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (239/239), done.
Writing objects: 100% (266/266), 222.68 KiB, done.
Total 266 (delta 55), reused 0 (delta 0)
-----> Heroku receiving push
-----> Rails app detected
-----> Detected Rails is not set to serve static_assets
Installing rails3_serve_static_assets... done
-----> Gemfile detected, running Bundler version 1.0.3
Unresolved dependencies detected; Installing...
Using --without development:test
You have modified your Gemfile in development but did not check
the resulting snapshot (Gemfile.lock) into version control
You have deleted from the Gemfile:
* version: 1.0.6
FAILED: http://docs.heroku.com/bundler
! Heroku push rejected, failed to install gems via Bundler
error: hooks/pre-receive exited with error code 1
To git#heroku.com:freezing-frost-65.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git#heroku.com:freezing-frost-65.git'
I tried adding Gemfile and Gemfile.lock to git but to no avail. I tried removing .bundle directory and Gemfile.lock but the same error.
There is a problem with bundler version 1.0.6
You need to run "gem update bundler" on your development machine to update bundler to 1.0.7. Then you need to run bundle update in your app to generate a new Gemfile.lock file. You will see that the Gemfile.lock is updated. Commit this new Gemfile.lock and push to heroku again.
I fixed mine by opening Gemfile.lock and deleting the following two lines:
PLATFORMS
x86-mingw32
So now i just need to make a script that bundles then removes that from the lock file.
Both the Gemfile and Gemfile.lock files needs to be included in the git repository.
Make sure you are not ignoring them in the .gitignore file.
Also, make sure you are using Bundler >= 1.0.0 on your local machine to generate the Gemfile.lock. I you use an outdated version, such as Bundler 0.9x, it will fail.
Last but not least, update your Gemfile.lock if you have one.
$ cd /path/to/project
$ bundle update
Found the answer at - http://www.unityisplural.com/2010/11/hobo-finally.html
I deleted the "mingw" line under PLATFORMS on my Gemfile.lock file, added and committed to git, pushed it to git, then pushed everything to heroku and apparently it works now.
In your applicaton directory, in the bin subdirectory modify the files
bin/bundle
bin/rails
bin/rake
Instead of
'#!/usr/bin/env ruby.exe
must be
'#!/usr/bin/env ruby
(thanks to previous post)
Make sure there are no references to windows in the gemfile.lock - they can just be deleted.
Then
git push heroku master
If there are still problems use heroku logs (copying text to a text editor makes it easier to cut and paste for solutions).

Resources