将带有 Sinatra 2.0.0beta2 的 Rails 5 应用程序部署到 Amazon Linux AMI 时出错

Posted

技术标签:

【中文标题】将带有 Sinatra 2.0.0beta2 的 Rails 5 应用程序部署到 Amazon Linux AMI 时出错【英文标题】:Error deploying Rails 5 app with Sinatra 2.0.0beta2 to Amazon Linux AMI 【发布时间】:2017-01-26 13:49:09 【问题描述】:

我遇到了 Sinatra 2.0.0 beta 2 和 Rails 5 部署到 Amazon Linux AMI v 2.1.6 的异常。我已经在 Sinatra Github repro 中发布了the issue,但有人建议我在这里发布。

编辑:我在使用 Elastic Beanstalk 时遇到了这个问题,但正如 @neal 报告的那样,Capistrano 部署到 EC2 时也会发生这种情况。

重现问题的步骤如下:

    在干净的目录中创建一个新的 Rails 5 应用程序

    $ gem install rails
    $ rails --version
    (confirm Rails 5.0.0.1)
    $ rails new test-app
    

将此行添加到 gemfile:

gem 'sinatra', '2.0.0.beta2'

    创建一个类型为“64bit Amazon Linux 2016.03 v2.1.6 running Ruby 2.3 (Puma)”的新 Elastic Beanstalk Web 环境,Web 服务器。使用所有默认值,除了将实例大小更改为 t2.small(任何更小的都没有足够的内存来部署)

    使用 Web 控制台将两个新环境变量添加到 Elastic Beanstalk 环境 SECRET_KEY_BASE =(为此设置一个值) RAILS_ENV = 生产

    将应用程序部署到这个新环境,例如使用 eb 命令行工具。

    再次部署 通过 Elastic Beanstalk 控制台跟踪日志

结果:

-------------------------------------
/var/log/puma/puma.log
-------------------------------------
=== puma startup: 2016-08-26 02:39:12 +0000 ===
=== puma startup: 2016-08-26 02:39:12 +0000 ===
[15926] - Worker 0 (pid: 15929) booted, phase: 0
[15926] - Gracefully shutting down workers...
/opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-2.0.0.beta2/lib/sinatra/main.rb:11:in `expand_path': No such file or directory - getcwd (Errno::ENOENT)
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-2.0.0.beta2/lib/sinatra/main.rb:11:in `block in <class:Application>'
    from (eval):1:in `run?'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-2.0.0.beta2/lib/sinatra/main.rb:26:in `block in <module:Sinatra>'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/cluster.rb:120:in `fork'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/cluster.rb:120:in `block in spawn_workers'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/cluster.rb:116:in `times'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/cluster.rb:116:in `spawn_workers'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/cluster.rb:426:in `run'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/launcher.rb:172:in `run'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/cli.rb:74:in `run'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/bin/puma:10:in `<top (required)>'
    from /opt/rubies/ruby-2.3.1/bin/puma:23:in `load'
    from /opt/rubies/ruby-2.3.1/bin/puma:23:in `<top (required)>'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/cli/exec.rb:63:in `load'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/cli/exec.rb:63:in `kernel_load'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/cli/exec.rb:24:in `run'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/cli.rb:304:in `exec'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/cli.rb:11:in `start'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/exe/bundle:27:in `block in <top (required)>'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/friendly_errors.rb:98:in `with_friendly_errors'
    from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/exe/bundle:19:in `<top (required)>'
    from /opt/rubies/ruby-2.3.1/bin/bundle:23:in `load'
    from /opt/rubies/ruby-2.3.1/bin/bundle:23:in `<main>'
[15926] === puma shutdown: 2016-08-26 02:41:17 +0000 ===
[15926] - Goodbye!
=== puma startup: 2016-08-26 02:41:20 +0000 ===
=== puma startup: 2016-08-26 02:41:20 +0000 ===
[16296] - Worker 0 (pid: 16299) booted, phase: 0

【问题讨论】:

仍然存在于最新的 Amazon Linux AMI 2016.09 v2.2.0 【参考方案1】:

这不仅仅是弹性 bean stalk 问题,我可以确认在使用 capistrano / EC2 Ubuntu / nginx 部署 rails 5 应用程序时也会发生这种情况

【讨论】:

感谢@neal,我编辑了帖子以反映这不是 Elastic Beanstalk 特有的。你介意提出这个问题吗?

以上是关于将带有 Sinatra 2.0.0beta2 的 Rails 5 应用程序部署到 Amazon Linux AMI 时出错的主要内容,如果未能解决你的问题,请参考以下文章

带有 sinatra 的 Mandrill API 电子邮件队列

如何将模块化 Sinatra 应用程序迁移到 AWS Lambda

带有角膜宝石和 sqlite 的 Sinatra 项目。耙分贝:迁移不工作。已创建架构但无法生成测试数据

Sinatra 应用程序作为机架中间件 TimeOut Rails 3

将 Sinatra 与acts_as_audited 一起使用的任何示例?

将 Ruby Sinatra 的 ADAL 示例映射到 Active Directory