platform.sh 上的 502 Bad Gateway,带有 rails 6 应用程序 + 独角兽

问题描述

我已经在 platform.sh 上部署了我的 rails 6 应用程序 部署成功,但我在主页上出现 502 错误

502 Bad Gateway

我认为迁移或数据库创建失败。 我联系了支持人员,目前答案没有任何改变。

.aplatform.app.yaml的完整配置

    # The name of this app. Must be unique within a project.
name: app

type: 'ruby:2.7'


relationships:
    postgresdatabase: 'dbpostgres:postgresql'

# The size of the persistent disk of the application (in MB).
disk: 1024


hooks:
    build: |
      gem install bundler:2.2.8
      bundle install --without development test
    deploy: |
      RACK_ENV=production bundle exec rake db:migrate

mounts:
  'web/uploads':
    source: local
    source_path: uploads
  'tmp':
    source: local
    source_path: tmp

web:
  upstream: 
    socket_family: "unix"
  commands: 
    start: "unicorn -l $SOCKET -E production config.ru"
  locations: 
    '/': 
      root: "public"
      passthru: true
      expires: "1h"
      allow: true

config/database.yml

default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling,see Rails configuration guide
  # https://guides.rubyonrails.org/configuring.html#database-pooling
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>


###### PRODUCTION ############
   production:
     url: <%= ENV['DATABASE_URL'] %>
#
production:
  <<: *default
  database: LNCLASSAPPS_production
  username: LNCLASSAPPS
  password: <%= ENV['LNCLASSAPPS_DATABASE_PASSWORD'] %>

我用

设置了这个ENV:LNCLASSAPPS_DATABASE_PASSWORD
 platform variable:create

截图

ENV variables set up

我认为是导致问题的部分。(log extrait)

 Redeploying environment master
      Preparing deployment
      Closing services router and app
      opening application app and its relationships
      Executing deploy hook for application app
        W: `/app` is not writable.
        W: Bundler will use `/tmp/bundler20210210-161-unk7cf161' as your home directory temporarily.
        W: Rails Error: Unable to access log file. Please ensure that /app/log/production.log exists and is writable (ie,make it writable for user and group: chmod 0664 /app/log/production.log). The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
        W: rake aborted!
        W: PG::ConnectionBad: Could not connect to server: No such file or directory
 

现在是完整的部署日志

 Found 1 new commit
 
 Building application 'app' (runtime type: ruby:2.7,tree: a57066f)
   Generating runtime configuration.
   
   Executing build hook...
     Successfully installed bundler-2.2.8
     Parsing documentation for bundler-2.2.8
     I
   .......... GEMS INSTALLING

    
  
 
 Redeploying environment master
  Preparing deployment
  Closing services router and app
  opening application app and its relationships
  Executing deploy hook for application app
    W: `/app` is not writable.
    W: Bundler will use `/tmp/bundler20210210-161-unk7cf161' as your home directory temporarily.
    W: Rails Error: Unable to access log file. Please ensure that /app/log/production.log exists and is writable (ie,make it writable for user and group: chmod 0664 /app/log/production.log). The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
    W: rake aborted!
    W: PG::ConnectionBad: Could not connect to server: No such file or directory
    W:      Is the server running locally and accepting
    W:      connections on Unix domain socket "/var/run/postgresql/.s.PGsql.5432"?
    W: /app/.global/gems/pg-1.2.3/lib/pg.rb:58:in `initialize'
    W: /app/.global/gems/pg-1.2.3/lib/pg.rb:58:in `new'
    W: /app/.global/gems/pg-1.2.3/lib/pg.rb:58:in `connect'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/postgresql_adapter.rb:46:in `postgresql_connection'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:887:in `new_connection'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `checkout_new_connection'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:910:in `try_to_checkout_new_connection'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:871:in `acquire_connection'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:593:in `checkout'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:437:in `connection'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:1119:in `retrieve_connection'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/connection_handling.rb:221:in `retrieve_connection'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/connection_handling.rb:189:in `connection'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/tasks/database_tasks.rb:238:in `migrate'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/railties/databases.rake:86:in `block (3 levels) in <main>'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/railties/databases.rake:84:in `each'
    W: /app/.global/gems/activerecord-6.0.3.4/lib/active_record/railties/databases.rake:84:in `block (2 levels) in <main>'
    W: /app/.global/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/cli/exec.rb:63:in `load'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/cli/exec.rb:63:in `kernel_load'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/cli/exec.rb:28:in `run'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/cli.rb:494:in `exec'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/cli.rb:30:in `dispatch'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/cli.rb:24:in `start'
    W: /app/.global/gems/bundler-2.2.8/exe/bundle:49:in `block in <top (required)>'
    W: /app/.global/gems/bundler-2.2.8/lib/bundler/friendly_errors.rb:130:in `with_friendly_errors'
    W: /app/.global/gems/bundler-2.2.8/exe/bundle:37:in `<top (required)>'
    W: /app/.global/bin/bundle:23:in `load'
    W: /app/.global/bin/bundle:23:in `<main>'
    W: Tasks: TOP => db:migrate
    W: (See full trace by running task with --trace)

 

我认为问题来自重新部署环境主部分。

解决方法

我不知道您是否已设法解决您的问题,但似乎是安装问题:

W: `/app` is not writable.
W: Bundler will use `/tmp/bundler20210210-161-unk7cf161' as your home directory temporarily.
W: Rails Error: Unable to access log file. Please ensure that /app/log/production.log exists and is writable (ie,make it writable for user and group: chmod 0664 /app/log/production.log). The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
W: rake aborted!

我建议将此值添加到您的 mounts 文件中的 .platform.app.yaml 属性:

mounts:
    'web/uploads':
        source: local
        source_path: uploads
    'tmp':
        source: local
        source_path: tmp
    # The new lines
    logs:
        source: local
        source_path: logs

有关 Ruby,请参阅 Platform.sh official documentation

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...