我正在研究Ruby on Rails Tutorial的Rails 3.2版本,并且接近第5章的末尾。虽然几天前它接受了我的代码,但Heroku不再想在我推动时接受它。它抱怨它需要一个Gemfile.lock,我可以理解 - 但我已经提供了一个。
几天前,我确实从存储库中删除了Gemfile.lock,因为我在Windows上启动了这个项目并因此而遇到了Bundler地狱。那时,我将Gemfile.lock的名字添加到了.gitignore,但是现在我已经从.gitignore中删除了它的名字并再次添加了它。然而Heroku仍然认为它没有承诺。
我该怎么办?除了在当前阶段重新添加Gemfile.lock之外,我还尝试使用rebasing来删除首先删除它的提交。我还完全从Heroku中删除了应用程序并重新添加(使用相同的名称和不同的名称)。另外,虽然我没有在shell会话中捕获它,但我确实在所有这些之前运行bundle update
以确保Gemfile.lock与Gemfile匹配。
这是我的bash会话:
$ 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
$
答案 0 :(得分:1)
我终于追溯到这个问题,我根据平台(Mac,Linux和Windows)为Guard通知指定了不同的gems;但是当我想要在我的Mac上运行bundle install
它不会锁定Gemfile.lock中的Linux或Windows宝石。我确实在case
语句中检测到主机平台的那些宝石,但显然Bundler无法完全说出我的意图。
我把整个条件拿出去,只是指定了Mac宝石,而不是其他平台。一段时间后,我将进一步调查;由于这些宝石仅用于测试,我认为Heroku的Bundler根本不需要了解它们。