繁体   English   中英

无法将 Rails API 应用程序部署到 Ruby 3.0 平台版本 3.6.2 上的 AWS Elastic Beanstalk

[英]Unable to deploy Rails API app to AWS Elastic Beanstalk on Ruby 3.0 platform version 3.6.2

尝试在“ Ruby 3.0 running on 64bit Amazon Linux 2/3.6.2 ”平台上部署时,无论是使用eb deploy命令还是手动上传我的项目的压缩版本,似乎 Postgresql 服务都没有在我的实例中运行,因为我在eb-engile.log中得到下一个:

2023/01/17 17:31:04.238133 [ERROR] An error occurred during execution of command [app-deploy] - [rake tasks]. Stop running the command. Error: running rake task db:migrate failed with error command bundle exec rake db:migrate failed with error Command /bin/su webapp -c bundle exec rake db:migrate failed with error exit status 1. Stderr:rake aborted!
ActiveRecord::ConnectionNotEstablished: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:83:in `rescue in new_client'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:77:in `new_client'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_handling.rb:327:in `retrieve_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_handling.rb:283:in `connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <main>'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:90:in `each'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <main>'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/opt/elasticbeanstalk/.rbenv/versions/3.0.5/bin/bundle:25:in `load'
/opt/elasticbeanstalk/.rbenv/versions/3.0.5/bin/bundle:25:in `<main>'

Caused by:
PG::ConnectionBad: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/pg-1.2.3/lib/pg.rb:58:in `initialize'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/pg-1.2.3/lib/pg.rb:58:in `new'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/pg-1.2.3/lib/pg.rb:58:in `connect'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:78:in `new_client'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_handling.rb:327:in `retrieve_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_handling.rb:283:in `connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <main>'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:90:in `each'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <main>'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/opt/elasticbeanstalk/.rbenv/versions/3.0.5/bin/bundle:25:in `load'
/opt/elasticbeanstalk/.rbenv/versions/3.0.5/bin/bundle:25:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

虽然,当尝试以 root 身份运行/bin/su webapp -c bundle exec rake db:migrate命令时(请注意,我正在调用 bundler 然后作为 webapp 用户),我得到了不同类型的错误(试图安装一个缺少宝石?):

Bundler::PermissionError: There was an error while trying to write to
`/var/app/staging/vendor/bundle/ruby/3.0.0/cache/public_suffix-5.0.1.gem`. It is likely that you
need to grant write permissions for that path.
  /opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/shared_helpers.rb:105:in `rescue in
filesystem_access'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/shared_helpers.rb:102:in
`filesystem_access'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/rubygems_integration.rb:479:in `block in
download_gem'
  /opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/retry.rb:40:in `run'
  /opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/retry.rb:30:in `attempt'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/rubygems_integration.rb:470:in
`download_gem'
  /opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/source/rubygems.rb:485:in `download_gem'
  /opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/source/rubygems.rb:447:in `fetch_gem'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/source/rubygems.rb:431:in
`fetch_gem_if_possible'
  /opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/source/rubygems.rb:158:in `install'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer/gem_installer.rb:54:in
`install'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer/gem_installer.rb:16:in
`install_from_spec'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer/parallel_installer.rb:155:in
`do_install'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer/parallel_installer.rb:140:in
`install_serially'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer/parallel_installer.rb:91:in
`call'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer/parallel_installer.rb:67:in
`call'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer.rb:244:in
`install_in_parallel'
  /opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer.rb:201:in `install'
  /opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer.rb:89:in `block in run'
  /opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/process_lock.rb:19:in `rescue in lock'
  /opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/process_lock.rb:15:in `lock'
  /opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer.rb:71:in `run'
  /opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer.rb:23:in `install'
  /opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/cli/install.rb:62:in `run'
  /opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/cli.rb:260:in `block in install'
  /opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/settings.rb:131:in `temporary'
  /opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/cli.rb:259:in `install'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/vendor/thor/lib/thor/command.rb:27:in
`run'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in
`invoke_command'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/vendor/thor/lib/thor.rb:392:in
`dispatch'
  /opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/cli.rb:34:in `dispatch'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/vendor/thor/lib/thor/base.rb:485:in
`start'
  /opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/cli.rb:28:in `start'
/opt/rubies/ruby-3.0.5/lib/ruby/gems/3.0.0/gems/bundler-2.4.1/exe/bundle:45:in `block in <top
(required)>'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/friendly_errors.rb:117:in
`with_friendly_errors'
/opt/rubies/ruby-3.0.5/lib/ruby/gems/3.0.0/gems/bundler-2.4.1/exe/bundle:33:in `<top
(required)>'
  /opt/elasticbeanstalk/.rbenv/versions/3.0.5/bin/bundle:25:in `load'
  /opt/elasticbeanstalk/.rbenv/versions/3.0.5/bin/bundle:25:in `<main>'

An error occurred while installing public_suffix (5.0.1), and Bundler cannot
continue.

In Gemfile:
  capybara was resolved to 3.38.0, which depends on
    addressable was resolved to 2.8.1, which depends on
      public_suffix

似乎还没有安装 postgresql 服务(已检查以“post”字符串开头的已安装服务):

[root@ip************ staging]# systemctl list-unit-files | grep post
postfix.service                               enabled 

那么,问题是,如何使eb deploy命令运行而不会失败? 鉴于:

  • 我看到一个使用eb deploy的错误突出显示了一个失败的rake db:migrate命令,但是,在通过 SSH 连接后尝试手动运行它时,它会抛出一个不同的错误; 提到public_suffix的那个。 这似乎出乎意料。
  • postgresql服务应该安装在AWS的托管平台,和之前的版本一样

一般来说,当云供应商做出“一切正常”之类的承诺时,他们的意思是,“当您更改代码以能够利用我们服务的配置约定时,它就会正常工作”。

在这种情况下,您的应用程序似乎正在尝试连接到本地数据库服务器。 在与 Rails 应用程序相同的实例上运行数据库是非常不寻常的。 相反,您希望它连接到远程托管数据库服务,如 AWS RDS。

  • 您是否设置了 RDS postgres 实例?
  • 您是否在 EB 中设置了环境变量,例如需要传递给您的应用程序的DATABASE_URL ......使用正确的 RDS 实例值?
  • 您的 Rails 应用程序的配置文件是否设置为从环境中读取值而不是仅使用默认值(或配置文件中的硬编码值)?

这是 一个教程,可以让您了解其中的大部分内容。

最后,您的问题提到了 Rails 3.0,但是您粘贴的 output 清楚地表明您使用的是 Ruby 3.0。 您不太可能在 Ruby 3 (2020) 上运行 Rails 3.0(2010 年发布)。 我不相信他们甚至可以在您的本地机器上一起工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM