【问题标题】:Setting up Firefly (ruby link shortener) 2.0 on Heroku?在 Heroku 上设置 Firefly(ruby 链接缩短器)2.0?
【发布时间】:2013-01-02 14:39:34
【问题描述】:

我在本地机器上进行了有效安装,但无法在 heroku 上执行相同操作。

我所做的唯一更改:

  • 将 firefly.yml 中的主机名更改为 rxlcc.herokuapp.com
  • 注释掉 Gemfile 中的其他 dbs,只有 pg 未注释

我的回购地址:https://github.com/hayksaakian/rxlcc

github 更新日志:https://github.com/hayksaakian/rxlcc/commit/d2e2f926b228372a9ff7861e918bdf193a3c3bca

我猜这是因为没有与生产数据库的连接,但我不确定将它们添加到哪里

2012-12-31T05:36:20+00:00 heroku[web.1]: Starting process with command `bundle exec rackup config.ru -p 36424`
2012-12-31T05:36:26+00:00 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)
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236:in `load_dependency'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/config.ru:2:in `block in <main>'
2012-12-31T05:36:26+00:00 app[web.1]:   from /usr/local/lib/ruby/1.9.1/syck.rb:135:in `load'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/lib/firefly/database.rb:8:in `config'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/lib/firefly/database.rb:13:in `<top (required)>'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/lib/firefly/database.rb:4:in `connect!'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `block in require'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:137:in `start'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/bin/rackup:4:in `<top (required)>'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/config.ru:1:in `new'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/bin/rackup:19:in `<main>'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/lib/firefly.rb:30:in `<top (required)>'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/config.ru:1:in `<main>'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/config.ru:2:in `require'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/bin/rackup:19:in `load'
2012-12-31T05:36:26+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
2012-12-31T05:36:28+00:00 heroku[web.1]: Process exited with status 1
2012-12-31T05:36:28+00:00 heroku[web.1]: State changed from starting to crashed
2012-12-31T05:41:04+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=rxlcc.herokuapp.com fwd=71.212.33.130 dyno= queue= wait= connect= service= status=503 bytes=
2012-12-31T05:41:05+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=rxlcc.herokuapp.com fwd=71.212.33.130 dyno= queue= wait= connect= service= status=503 bytes=

我的heroku插件:

heroku-postgresql:dev  HEROKU_POSTGRESQL_NAVY

更新:

我尝试在 lib/firefly/server.rb 中添加一行

  # suggested by iain on stackoverflow
  @config[:database_url] = ENV["DATABASE_URL"]

这似乎没有改变任何东西

https://github.com/hayksaakian/rxlcc/commit/638bb8b215cf09f7edbafc0f21e964dfc05f86f2

    2013-01-02T06:32:19+00:00 heroku[web.1]: State changed from crashed to starting
    2013-01-02T06:32:22+00:00 heroku[web.1]: Starting process with command `bundle exec rackup config.ru -p 18667`
    2013-01-02T06:32:25+00:00 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)
    2013-01-02T06:32:25+00:00 app[web.1]:   from /usr/local/lib/ruby/1.9.1/syck.rb:135:in `load'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/lib/firefly/database.rb:8:in `config'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/lib/firefly/database.rb:4:in `connect!'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/lib/firefly/database.rb:13:in `<top (required)>'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `block in require'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236:in `load_dependency'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/lib/firefly.rb:30:in `<top (required)>'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/config.ru:2:in `require'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/config.ru:2:in `block in <main>'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/config.ru:1:in `new'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/config.ru:1:in `<main>'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:137:in `start'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/bin/rackup:4:in `<top (required)>'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/bin/rackup:19:in `load'
    2013-01-02T06:32:25+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/bin/rackup:19:in `<main>'
    2013-01-02T06:32:26+00:00 heroku[web.1]: Process exited with status 1
    2013-01-02T06:32:27+00:00 heroku[web.1]: State changed from starting to crashed
    2013-01-02T06:37:44+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=rxlcc.herokuapp.com fwd=71.212.33.130 dyno= queue= wait= connect= service= status=503 bytes=
    2013-01-02T06:37:44+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=rxlcc.herokuapp.com fwd=71.212.33.130 dyno= queue= wait= connect= service= status=503 bytes=

【问题讨论】:

    标签: ruby-on-rails heroku sinatra


    【解决方案1】:

    是的,你需要在yml文件的host:下指定数据库url。您可以在 Heroku 站点的设置页面中查看 url,或者您可以运行 heroku config --app rxlcc 并查找 DATABASE_URL。

    注意:如果您要使用 Heroku,说明会告诉您更改 .gitignore 并签入 .yml 文件。如果您要在其中保留密钥,那么我不会这样做,但是如果您这样做,不要将回购公开!如果其他人知道秘密,您需要重新生成它。

    我个人会通过

    添加任何秘密
    heroku config:add SECRET_VARIABLE=blahblahblah --app rxlcc
    

    然后通过

    将其读入需要它的应用程序中
    my_secret_variable = ENV["SECRET_VARIABLE"]
    

    我看到应用程序将配置设置为 https://github.com/hayksaakian/rxlcc/blob/master/lib/firefly/server.rb#L209,并在 https://github.com/hayksaakian/rxlcc/blob/master/lib/firefly/server.rb#L109 的前块中设置。在任何一点你都可以尝试:

    @config[:database_url] = ENV["DATABASE_URL"]
    

    添加任何秘密变量。

    【讨论】:

    • 我还认为 firefly.yml 中的主机名变量应该指向公共域而不是数据库
    • 是的,firefly.yml 中的 hostname 用于公共域 url。 host 是 database.yml 应该指向数据库服务器。在示例中,这被假定为 localhost,但在生产中很少会这样。如果您运行 heroku config 并获取 HEROKU_POSTGRESQL_NAVY_URL 的值并将其添加为 DATABASE_URL(如果它不存在),它也会更容易移植。如果 DATABASE_URL 不存在,我会对我的所有应用程序执行此操作。
    • 感谢您的帮助。在与萤火虫开发人员交谈后,似乎 2.0 还没有准备好投入生产。我现在使用github.com/ariejan/firefly-heroku 很顺利。
    • 啊,是的,他已经按照我在 rackup 文件中的建议做了。很高兴它对你有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-25
    • 2014-07-12
    • 1970-01-01
    • 2017-11-06
    • 2016-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多