0

我已经在 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

配置/数据库.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 变量设置

我认为这是导致问题的部分。(日志额外)

 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)

 

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

4

1 回答 1

0

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

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 官方文档

于 2021-07-12T13:19:51.860 回答