在先前从存储库中取出Gemfile.lock之后,将Rails应用程序部署到Heroku [英] Deploying Rails app to Heroku after previously taking Gemfile.lock out of repository

查看:69
本文介绍了在先前从存储库中取出Gemfile.lock之后,将Rails应用程序部署到Heroku的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 Ruby on Rails教程的Rails 3.2版,并且在本章结尾处5.尽管几天前它接受了我的代码,但是在我推送时Heroku不再希望接受它。它抱怨它需要一个Gemfile.lock,据我了解-但我已经提供了一个。

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.

几天前,我确实从Gemfile.lock中删除了存储库,因为我在Windows上启动了该项目,因此遇到了Bundler地狱。那时,我在.gitignore中添加了Gemfile.lock的名称,但是现在我从.gitignore中删除了它的名称,然后又重新添加了它。

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.

我该怎么办?除了在当前阶段重新添加Gemfile.lock之外,我还尝试过使用rebasing删除最初将其删除的提交。我还从Heroku中完全删除了该应用,然后重新添加了它(使用相同的名称和不同的名称)。另外,尽管我没有在shell会话中捕获它,但在确保所有Gemfile.lock与Gemfile匹配之前,我还是先运行了 bundle update

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.

这是我的bash会话:

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
$


推荐答案

我最终将问题追溯到以下事实:我根据平台(Mac,Linux和Windows)为Guard通知指定了不同的gem;但是当我会在Mac上运行捆绑安装不会锁定Gemfile.lock中的Linux或Windows gem。我确实在 case 语句中检测到了这些主机平台,但是显然Bundler不能从中看出我的意图。

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.

我将整个条件排除在外,仅指定了Mac gem,而不是其他平台。一段时间以后,我将进一步调查;因为这些宝石仅用于测试,所以我认为Heroku的Bundler根本不需要了解它们。

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.

这篇关于在先前从存储库中取出Gemfile.lock之后,将Rails应用程序部署到Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆