1

I've deployed my rails 6 application on platform.sh the deployment was successful, but I have a 502 error on home page.

502 Bad Gateway

I think that the migration or the database creation fails. I contacted the support, and the answer doesn't change anything at the moment.

the complete configuration of .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'] %>

I set up this ENV:LNCLASSAPPS_DATABASE_PASSWORD with

 platform variable:create

screenshot

ENV variables set up

I think it is the section that is the cause of the problem.(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
 

now the complet deploy log

 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)

 

I think the problem is coming from the Redeploying environment master section.

1 Answers1

0

I don't know if you've managed to solve your issue but it seems that it's a mount issue:

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!

I'd suggested to add this value to your mounts property in your .platform.app.yaml file:

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

See Platform.sh official documentation for Ruby.

rootasjey
  • 126
  • 1
  • 6