Deploying Rails app to Heroku after previously taking Gemfile.lock out of repository

百般思念 提交于 2019-12-24 11:32:33

问题


I'm working through the Rails 3.2 edition of Ruby on Rails Tutorial, and am right near the end of Chapter 5. Although it accepted my code a few days ago, Heroku no longer wants to take it when I push. It complains that it needs a Gemfile.lock, which I can understand -- but I am supplying one already.

A few days ago I did remove Gemfile.lock from the repository, since I started this project on Windows and ran into Bundler hell due to that. At that time, I added Gemfile.lock's name to .gitignore, but now I've removed its name from .gitignore and added it back again; yet Heroku still thinks it's not committed.

What can I do? Besides re-adding Gemfile.lock at the current stage, I've tried using rebasing to delete the commit that removed it in the first place. I've also removed the app completely from Heroku and re-added it (using the same name and a different name). Also, although I didn't capture it in the shell session, I did run bundle update before all this to make sure Gemfile.lock matched Gemfile.

Here is my bash session:

$ type ssha-heroku
ssha-heroku is aliased to `eval `ssh-agent`; ssh-add -t 5m ~/.ssh/heroku.id_rsa'

ruby-1.9.3-p392@railstutorial3 ~/Scripts/Rails/railstutorial/sample_app
$ ssha-heroku
Agent pid 19642
Enter passphrase for /Users/eric/.ssh/heroku.id_rsa:
Identity added: /Users/eric/.ssh/heroku.id_rsa (/Users/eric/.ssh/heroku.id_rsa)
Lifetime set to 300 seconds

ruby-1.9.3-p392@railstutorial3 ~/Scripts/Rails/railstutorial/sample_app
$ git push heroku master
Counting objects: 384, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (260/260), done.
Writing objects: 100% (384/384), 60.58 KiB, done.
Total 384 (delta 172), reused 215 (delta 86)

-----> Ruby/NoLockfile app detected
 !
 !     Gemfile.lock required. Please check it in.
 !
 !     Heroku push rejected, failed to compile Ruby/nolockfile app

To git@heroku.com:stormy-coast-5058.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:stormy-coast-5058.git'

ruby-1.9.3-p392@railstutorial3 ~/Scripts/Rails/railstutorial/sample_app
$ git ls-files |grep Gemfile
Gemfile

ruby-1.9.3-p392@railstutorial3 ~/Scripts/Rails/railstutorial/sample_app
$ vim .gitignore # here I remove the line ignoring Gemfile.lock

ruby-1.9.3-p392@railstutorial3 ~/Scripts/Rails/railstutorial/sample_app
$ git add .gitignore Gemfile.lock

ruby-1.9.3-p392@railstutorial3 ~/Scripts/Rails/railstutorial/sample_app
$ git commit -m 'Stop ignoring Gemfile.lock so we can deploy to Heroku'
[master 1b691f1] Stop ignoring Gemfile.lock so we can deploy to Heroku
 2 files changed, 182 insertions(+), 6 deletions(-)
 create mode 100644 Gemfile.lock

ruby-1.9.3-p392@railstutorial3 ~/Scripts/Rails/railstutorial/sample_app
$ git ls-files |grep Gemfile
Gemfile
Gemfile.lock

ruby-1.9.3-p392@railstutorial3 ~/Scripts/Rails/railstutorial/sample_app
$ git push heroku master
Counting objects: 387, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (263/263), done.
Writing objects: 100% (387/387), 60.90 KiB, done.
Total 387 (delta 174), reused 215 (delta 86)

-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.3.2
       Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment
       You are trying to install in deployment mode after changing
       your Gemfile. Run `bundle install` elsewhere and add the
       updated Gemfile.lock to version control.
       You have added to the Gemfile:
       * rb-inotify (~> 0.9)
       * libnotify (= 0.5.9)
       You have deleted from the Gemfile:
       * rb-fsevent (= 0.9.1)
       * terminal-notifier-guard (= 1.5.3)
 !
 !     Failed to install gems via Bundler.
 !
 !     Heroku push rejected, failed to compile Ruby/rails app

To git@heroku.com:stormy-coast-5058.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:stormy-coast-5058.git'

ruby-1.9.3-p392@railstutorial3 ~/Scripts/Rails/railstutorial/sample_app
$

回答1:


I finally traced the issue back to the fact that I specified different gems for Guard notification depending on platform (Mac, Linux, and Windows); but when I would e.g. run bundle install on my Mac it wouldn't lock the Linux or Windows gems in Gemfile.lock. I did have those gems in a case statement detecting host platform, but apparently Bundler couldn't quite tell my intention from that.

I took the whole conditional out and just specified the Mac gems and not the other platforms'. Some time down the road I will investigate further; since those gems are for testing only I don't think Heroku's Bundler needs to know about them at all.



来源:https://stackoverflow.com/questions/15873531/deploying-rails-app-to-heroku-after-previously-taking-gemfile-lock-out-of-reposi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!