【问题标题】:Deploying Publify blog to Heroku causes Application Error将发布博客部署到 Heroku 会导致应用程序错误
【发布时间】:2013-07-20 11:48:21
【问题描述】:

我正在尝试将全新安装的 Publify 博客部署到 Heroku。在我的本地计算机上一切正常。

git push heroku master 没有说任何问题:

Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 786 bytes, done.
Total 6 (delta 1), reused 0 (delta 0)

-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.2.2
       Running: bundle install --without development:test --path 
         vendor/bundle --binstubs bin/ --deployment

       Using rake (10.0.2)

       ... (edited out list of gems being used)

       Your bundle is complete! It was installed into ./vendor/bundle
       Cleaning up the bundler cache.
-----> Writing config/database.yml to read from DATABASE_URL
-----> Rails plugin injection
       Injecting rails_log_stdout
       Injecting rails3_serve_static_assets
-----> Discovering process types
       Procfile declares types      -> (none)
       Default types for Ruby/Rails -> console, rake, web, worker
-----> Compiled slug size: 10.7MB
-----> Launching... done, v7
       http://desolate-harbor-2909.herokuapp.com deployed to Heroku

To git@heroku.com:desolate-harbor-2909.git
   cea2c5c..efb4eb2  master -> master

但之后我在应用页面上看到了这个:

应用程序错误
应用程序发生错误,无法提供您的页面。请稍后再试。

如果您是应用程序所有者,请查看您的日志以了解详细信息。

Heroku 日志显示:

heroku[slugc]: Slug compilation started
heroku[api]: Release v7 created by runsfor@gmail.com
heroku[api]: Deploy efb4eb2 by runsfor@gmail.com
heroku[web.1]: State changed from crashed to starting
heroku[slugc]: Slug compilation finished
heroku[web.1]: Starting process with command `bundle exec rails server -p 50812`
app[web.1]:        /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler/dsl.rb:7:in `evaluate'
app[web.1]:        /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/bin/bundle:14:in `<top (required)>'
app[web.1]:        /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler/dsl.rb:32:in `instance_eval'
app[web.1]:        /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler/friendly_errors.rb:4:in `with_friendly_errors'
app[web.1]: There was an error in your Gemfile, and Bundler cannot continue.
app[web.1]:        /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler/cli.rb:423:in `exec'
app[web.1]:        /app/Gemfile:7:in `eval_gemfile'
app[web.1]:        /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler/dsl.rb:32:in `eval_gemfile'
app[web.1]:        /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler/definition.rb:18:in `build'
app[web.1]:        /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler.rb:144:in `definition'
app[web.1]:        /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler/vendor/thor/task.rb:27:in `run'
app[web.1]:        /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler/vendor/thor/invocation.rb:120:in `invoke_task'
app[web.1]:        /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler/vendor/thor.rb:275:in `dispatch'
app[web.1]:        /usr/local/lib/ruby/1.9.1/syck.rb:135:in `load'
app[web.1]:        /app/vendor/bundle/ruby/1.9.1/bin/bundle:23:in `load'
app[web.1]:        /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler/vendor/thor/base.rb:408:in `start'
app[web.1]:        /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/bin/bundle:14:in `block in <top (required)>'
app[web.1]: /usr/local/lib/ruby/1.9.1/syck.rb:135:in `load': syntax error on line 27, col 0: `adapter = uri.scheme' (ArgumentError)
app[web.1]:        /app/vendor/bundle/ruby/1.9.1/bin/bundle:23:in `<main>'
heroku[web.1]: Process exited with status 4
heroku[web.1]: State changed from starting to crashed
heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=desolate-harbor-2909.herokuapp.com fwd=171.5.16.142 dyno= queue= wait= connect= service= status=503 bytes=
heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=desolate-harbor-[2909.herokuapp.com][1] fwd=171.5.16.142 dyno= queue= wait= connect= service= status=503 bytes=

我做错了什么?我想我需要在部署到 Heroku 之前以某种方式设置它。

Database.yml 文件为:

login: &login
  adapter: postgresql
  host: localhost
  username: *****
  password: *****

development:
  database: typo_dev
  <<: *login

test:
  database: typo_tests
  <<: *login

production:
  database: typo
  <<: *login

Heroku 运行 rake db:migrate 输出为:

Running `rake db:migrate` attached to terminal... up, run.7604
/usr/local/lib/ruby/1.9.1/syck.rb:135:in `load': syntax error on line 27, col 0: `adapter = uri.scheme' (ArgumentError)
       /usr/local/lib/ruby/1.9.1/syck.rb:135:in `load'
       /app/Gemfile:7:in `eval_gemfile'
       /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler/dsl.rb:32:in `instance_eval'
       /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler/dsl.rb:32:in `eval_gemfile'
       /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler/dsl.rb:7:in `evaluate'
       /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler/definition.rb:18:in `build'
       /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler.rb:144:in `definition'
       /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler/cli.rb:423:in `exec'
       /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler/vendor/thor/task.rb:27:in `run'
       /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler/vendor/thor/invocation.rb:120:in `invoke_task'
       /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler/vendor/thor.rb:275:in `dispatch'
       /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler/vendor/thor/base.rb:408:in `start'
       /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/bin/bundle:14:in `block in <top (required)>'
       /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/lib/bundler/friendly_errors.rb:4:in `with_friendly_errors'
       /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.2/bin/bundle:14:in `<top (required)>'
       /app/vendor/bundle/ruby/1.9.1/bin/bundle:23:in `load'
       /app/vendor/bundle/ruby/1.9.1/bin/bundle:23:in `<main>'
There was an error in your Gemfile, and Bundler cannot continue.

【问题讨论】:

  • 你配置好你的数据库了吗?如果是这样,您可以发布您的配置吗?
  • 你跑了吗:heroku rake db:migrate ?
  • 请注意,在 Heroku 上,您的 database.url 被替换 - Writing config/database.yml to read from DATABASE_URL。请参阅Ruby buildpack
  • rake db:migrate 说:您的 Gemfile 中有错误,Bundler 无法继续。

标签: deployment heroku publify


【解决方案1】:

当 Rails 加载 database.yml 文件时,它实际上是 filters it through ERB before loading it as a Yaml file。这样您就可以使用 Ruby 动态创建配置,例如将密码保存在您的存储库之外。

当您将 Rails 应用程序推送到 Heroku 时,a new database.yml file is created, replacing the original。这个新的database.yml 使用ERB 从DATABASE_URL 环境变量构造配置,所以实际上它不是一个“纯”的Yaml 文件——你可以认为它类似于database.yml.erb

Typo loads the database.yml fileparses it as Yaml 的 Gemfile,但没有先通过 ERB 输入。您看到的错误是由于 Yaml 解析器读取文件但由于它是 ERB 而失败,而不是有效的 Yaml。

要修复它,您需要确保 database.yml 文件在被读取为 Yaml 之前通过 ERB。在您的Gemfile 中更改行

conf = YAML.load(File.read(dbfile))

require 'erb'
conf = YAML.load(ERB.new(File.read(dbfile)).result)

您可能想要打开 Typo 的错误报告,甚至发送拉取请求。

【讨论】:

  • 有一个错字:不是 Rakefile,而是 Gemfile。除此之外,这对我有用。谢谢。
猜你喜欢
  • 2015-11-08
  • 2017-08-22
  • 1970-01-01
  • 2019-05-16
  • 1970-01-01
  • 2017-11-04
  • 1970-01-01
  • 1970-01-01
  • 2013-12-25
相关资源
最近更新 更多