【问题标题】:Using Ruby in an Elixir umbrella appp在 Elixir 伞形应用程序中使用 Ruby
【发布时间】:2022-01-15 07:40:26
【问题描述】:

我正在 Heroku 上运行 Elixir 伞式应用程序。一切都很好,但只有一件事。我正在使用 :erlport, github: "hdima/erlport" 运行一些 Ruby 代码 (asciidoctor-latex)。这在本地有效,但在 Heroku 上无效。 (Heroku 无法帮助我,因为他们不支持 Elixir。)

我已将问题缩小到一行。有问题的应用程序是http://notefile.herokuapp.com (https://github.com/jxxcarlson/ns_umbrella),代码行在app/apps/ruby_bridge/priv/ruby/asciidoc.rb

# require 'asciidoctor-latex'
require "/app/vendor/bundle/ruby/2.3.0/bundler/gems/asciidoctor-latex-
b5c9de1363de/bin/asciidoctor-latex"

注释掉的行在本地有效,但在 Heroku 上无效。另一行是我的(失败的)实验之一,用asciidoctor-latex 的绝对路径提供require

我知道这条线是有罪的一方,原因如下。首先,注释掉所有require 行;然后,在asciidoc.rb 中,使用result = "Text length = #{text.length}" 而不是result = Asciidoctor.convert text, { 'dialect' => 'latex' }

在这里,我用通用 Ruby 代码替换了对 asciidoctor-latex 中方法的调用。进行这些更改后,应用不会崩溃并提供预期的输出。

结论:require 找不到它的目标。下面我列出了使用的构建包(按顺序):

heroku/ruby
https://github.com/HashNuke/heroku-buildpack-elixir.git
https://github.com/gjaldon/heroku-buildpack-phoenix-static

日志:

Rendering ... 
2017-05-02T18:52:00.071102+00:00 app[web.1]: ========================
2017-05-02T18:52:00.071023+00:00 app[web.1]: MU.RenderText in APPLICATION MU_SERVER
2017-05-02T18:52:00.071326+00:00 app[web.1]: %{mode: "show", note_id: 1065, process: :adoc_latex, public: false, user_id: 9,
2017-05-02T18:52:00.071181+00:00 app[web.1]: OPTIONS
2017-05-02T18:52:00.071327+00:00 app[web.1]:   username: "jxxcarlson"}
2017-05-02T18:52:00.071392+00:00 app[web.1]: --
2017-05-02T18:52:00.071513+00:00 app[web.1]: Rendering asciidoc-latex
2017-05-02T18:52:00.150754+00:00 app[web.1]: Hello! This is render_asciidoc
2017-05-02T18:52:00.458499+00:00 heroku[router]: at=info method=GET path="/notes/1065" host=notefile.herokuapp.com request_id=f1ce45ba-6800-4d84-9b93-47851c0502e9 fwd="65.24.227.211" dyno=web.1 connect=0ms service=417ms status=500 bytes=243 protocol=https
2017-05-02T18:52:00.371673+00:00 app[web.1]: (1) Hello, I am here, in asciidoc.rb, top of file
2017-05-02T18:52:00.378538+00:00 app[web.1]: Starting MU.Server ...
2017-05-02T18:52:00.459594+00:00 app[web.1]: 18:52:00.459 [error] GenServer MUServer terminating
2017-05-02T18:52:00.459607+00:00 app[web.1]: ** (stop) {:ruby, :LoadError, "cannot load such file -- /app/vendor/bundle/ruby/2.3.0/bundler/gems/asciidoctor-latex-b5c9de1363de/bin/asciidoctor-latex", ["-e:1:in `<main>'", "/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'", "/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'", "/app/_build/prod/lib/erlport/priv/ruby1.9/erlport/cli.rb:94:in `<top (required)>'", "/app/_build/prod/lib/erlport/priv/ruby1.9/erlport/cli.rb:41:in `main'", "/app/_build/prod/lib/erlport/priv/ruby1.9/erlport/erlang.rb:138:in `start'", "/app/_build/prod/lib/erlport/priv/ruby1.9/erlport/erlang.rb:194:in `_receive'", "/app/_build/prod/lib/erlport/priv/ruby1.9/erlport/erlang.rb:234:in `call_with_error_handler'", "/app/_build/prod/lib/erlport/priv/ruby1.9/erlport/erlang.rb:195:in `block in _receive'", "/app/_build/prod/lib/erlport/priv/ruby1.9/erlport/erlang.rb:218:in `incoming_call'", "/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'", "/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'", "/app/apps/ruby_bridge/priv/ruby/asciidoc.rb:4:in `<top (required)>'", "/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'", "/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'"]}

【问题讨论】:

  • 你能发布 Heroku 的错误日志吗? (我认为命令是heroku logs)您可能还需要添加一个Ruby buildpack,以便同时安装Ruby 依赖项。
  • 这里是日志的摘录:
  • 请注意上面格式更好的版本中存在 ruby​​ buildpack
  • 使用require 'asciidoctor-latex' + Ruby buildpack 也会出现同样的错误?
  • 是的,我遇到了同样的错误

标签: ruby heroku elixir


【解决方案1】:

我刚刚在尝试修复 GitHub 操作中的类似错误时遇到了这个问题

对我来说,解决方法是将require "bundler/setup" 添加到我的 ruby​​ 文件的顶部。例如:

require "bundler/setup"
require "prawn"
...

关于require "bundler/setup" 所做的精彩文章:https://www.brianstorti.com/understanding-bundler-setup-process/

我的具体错误如下供参考

** (ErlangError) Erlang error: {:ruby, :LoadError, "cannot load such file -- prawn", [
"-e:1:in `<main>'", "/opt/hostedtoolcache/Ruby/2.7.5/x64/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'",
"/opt/hostedtoolcache/Ruby/2.7.5/x64/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'",
"/home/runner/work/clarus_ex/clarus_ex/deps/erlport/priv/ruby1.9/erlport/cli.rb:94:in `<top (required)>'",
"/home/runner/work/clarus_ex/clarus_ex/deps/erlport/priv/ruby1.9/erlport/cli.rb:41:in `main'",
"/home/runner/work/clarus_ex/clarus_ex/deps/erlport/priv/ruby1.9/erlport/erlang.rb:138:in `start'",
"/home/runner/work/clarus_ex/clarus_ex/deps/erlport/priv/ruby1.9/erlport/erlang.rb:194:in `_receive'",
"/home/runner/work/clarus_ex/clarus_ex/deps/erlport/priv/ruby1.9/erlport/erlang.rb:234:in `call_with_error_handler'",
"/home/runner/work/clarus_ex/clarus_ex/deps/erlport/priv/ruby1.9/erlport/erlang.rb:195:in `block in _receive'",
"/home/runner/work/clarus_ex/clarus_ex/deps/erlport/priv/ruby1.9/erlport/erlang.rb:218:in `incoming_call'",
"/opt/hostedtoolcache/Ruby/2.7.5/x64/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'",
"/opt/hostedtoolcache/Ruby/2.7.5/x64/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'",
"/home/runner/work/clarus_ex/clarus_ex/apps/clarus/priv/ruby/final_report.rb:1:in `<top (required)>'",
"/opt/hostedtoolcache/Ruby/2.7.5/x64/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'",
"/opt/hostedtoolcache/Ruby/2.7.5/x64/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'"]}

【讨论】:

    猜你喜欢
    • 2017-09-23
    • 1970-01-01
    • 1970-01-01
    • 2015-12-25
    • 1970-01-01
    • 1970-01-01
    • 2018-03-04
    • 1970-01-01
    • 2023-04-11
    相关资源
    最近更新 更多