简体   繁体   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

While trying to deploy in the " Ruby 3.0 running on 64bit Amazon Linux 2/3.6.2 " platform, both using the eb deploy command or manually uploading a zipped version of my project, it seems the Postgresql service is not running in my instance since I get the next in eb-engile.log :尝试在“ 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)

Although, when trying to run the /bin/su webapp -c bundle exec rake db:migrate command as root (please notice that, I am invoking bundler then as the webapp user), I get different kind of error (trying to install a missing gem?):虽然,当尝试以 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

It also seems the postgresql service is not installed (checked installed services starting with the "post" string):似乎还没有安装 postgresql 服务(已检查以“post”字符串开头的已安装服务):

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

So, the question is, how do I make the eb deploy command run without failing?那么,问题是,如何使eb deploy命令运行而不会失败? given that:鉴于:

  • I see one error using eb deploy that highlights a failing rake db:migrate command but, when trying to running it manually after connecting through SSH it throws a different error;我看到一个使用eb deploy的错误突出显示了一个失败的rake db:migrate命令,但是,在通过 SSH 连接后尝试手动运行它时,它会抛出一个不同的错误; the one that mentions public_suffix .提到public_suffix的那个。 This seems unexpected.这似乎出乎意料。
  • The postgresql service should be installed in AWS's managed platform, as with previous versions postgresql服务应该安装在AWS的托管平台,和之前的版本一样

In general when cloud providers make promises like, "it just works", what they mean is, "it works when you've changed your code to able to take advantage of our service's conventions for configuration".一般来说,当云供应商做出“一切正常”之类的承诺时,他们的意思是,“当您更改代码以能够利用我们服务的配置约定时,它就会正常工作”。

In this case it looks like your app is trying to connect to a local database server.在这种情况下,您的应用程序似乎正在尝试连接到本地数据库服务器。 It's very unusual to run the database on the same instance as the Rails app.在与 Rails 应用程序相同的实例上运行数据库是非常不寻常的。 Instead, you want it to connect to a remote, hosted DB service like AWS RDS.相反,您希望它连接到远程托管数据库服务,如 AWS RDS。

  • have you set up an RDS postgres instance?您是否设置了 RDS postgres 实例?
  • have you set up the environment variables in EB such as DATABASE_URL that need to be passed to your app... with the correct values for your RDS instance?您是否在 EB 中设置了环境变量,例如需要传递给您的应用程序的DATABASE_URL ......使用正确的 RDS 实例值?
  • are your Rails app's config files set up to read the values from the environment rather than just using defaults (or hardcoded values from config files)?您的 Rails 应用程序的配置文件是否设置为从环境中读取值而不是仅使用默认值(或配置文件中的硬编码值)?

Here's a tutorial that talks you through most of this.这是 一个教程,可以让您了解其中的大部分内容。

Finally, your question mentions Rails 3.0, but the output you paste makes it clear that you're using Ruby 3.0.最后,您的问题提到了 Rails 3.0,但是您粘贴的 output 清楚地表明您使用的是 Ruby 3.0。 It's very unlikely that you're running Rails 3.0 (released in 2010) with Ruby 3 (2020).您不太可能在 Ruby 3 (2020) 上运行 Rails 3.0(2010 年发布)。 I'm not confident that they would even work together on your local machine.我不相信他们甚至可以在您的本地机器上一起工作。

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

相关问题 无法自动将 do.net 应用程序部署到 Elastic Beanstalk - Unable to automatically deploy a dotnet app to Elastic Beanstalk 将 django 部署到 AWS Elastic Beanstalk - deploy django to AWS Elastic Beanstalk 无法安装弹性 beantalk AWS - Unable to install elastic beanstalk AWS 如何使用 github 操作部署到 aws elastic beanstalk? - How to deploy to aws elastic beanstalk with github actions? 如何使用 Travis CI 在 docker 平台的 Elastic beanstalk 中部署 React 应用程序? - How to deploy react app in Elastic beanstalk in a docker platform using Travis CI? 使用 api-platform 动态路由的 symfony 6.2 在@localhost 上工作,但在使用 elastic beanstalk 部署在 AWS 上时不起作用 - symfony 6.2 using api-platform dynamic routes work @localhost but not when deployed on AWS using elastic beanstalk 发布将 Rails 6.1 部署到 AWS Elastic Beanstalk - Issue Deploying Rails 6.1 to AWS Elastic Beanstalk 无法增加 AWS Elastic Beanstalk 上的超时 - Unable to increase the timeout on AWS Elastic Beanstalk 无法使用已安装的弹性文件系统部署 Elastic Beanstalk 应用程序 - Unable to deploy Elastic Beanstalk Application with mounted Elastic File System 在 AWS Elastic Beanstalk 中找不到 Laravel API 路由 - Laravel API routes not found in AWS Elastic Beanstalk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM