502 Bad Gateway

During deployment, the hook build is well executed.
but hook deploy has some errors.

Executing deploy hook for application app
    W: `/app` is not writable.
    W: Bundler will use `/tmp/bundler20210218-152-12m1dwy152' as your home directory temporarily.
    W: rake aborted!
    W: Errno::EROFS: Read-only file system @ dir_s_mkdir - /app/tmp/cache
    W: /app/.global/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/store.rb:79:in `dump_data'
    W: /app/.global/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/store.rb:59:in `commit_transaction'
    W: /app/.global/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/store.rb:50:in `block in transaction'
    W: /app/.global/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/store.rb:46:in `synchronize'
    W: /app/.global/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/store.rb:46:in `transaction'
    W: /app/.global/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/cache.rb:139:in `push_paths_locked'
    W: /app/.global/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/cache.rb:122:in `block in reinitialize'
    W: /app/.global/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/cache.rb:116:in `synchronize'
    W: /app/.global/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/cache.rb:116:in `reinitialize'
    W: /app/.global/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/cache.rb:16:in `initialize'
    W: /app/.global/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache.rb:45:in `new'
    W: /app/.global/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache.rb:45:in `setup'
    W: /app/.global/gems/bootsnap-1.5.1/lib/bootsnap.rb:26:in `setup'
    W: /app/.global/gems/bootsnap-1.5.1/lib/bootsnap/setup.rb:31:in `<top (required)>'
    W: /app/config/boot.rb:4:in `require'
    W: /app/config/boot.rb:4:in `<top (required)>'
    W: /app/config/application.rb:1:in `require_relative'
    W: /app/config/application.rb:1:in `<top (required)>'
    W: /app/Rakefile:4:in `require_relative'
    W: /app/Rakefile:4:in `<top (required)>'
    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: (See full trace by running task with --trace)

This prevents the database from starting.
how to solve this problem.

Your application is trying to write on a read-only filesystem.
The filesystem is writable only during the build hook. Everything happening after that point will be limited to read-only.
If you need to be able to perform post build hook write operations, you will have to use mounts.
You can find more information about this in the storage section of our documentation.

1 Like

To tell the truth, I’m a beginner, so I only have the default configuration proposed.
my .platform.app.yaml

name: app

# The runtime the application uses. The 'type' key defines the base container
# image that will be used to run the application. There is a separate base
# container image for each primary language for the application,
# in multiple versions. Check the Ruby documentation
# (https://docs.platform.sh/languages/ruby.html#supported-versions)
# to find the supported versions for the 'ruby' type.
type: 'ruby:2.7'

# The relationships of the application with services or other applications.
#
# The left-hand side is the name of the relationship as it will be exposed
# to the application in the PLATFORM_RELATIONSHIPS variable. The right-hand
# side is in the form <service name>:<endpoint name>.
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

# The following block defines a single writable directory, 'web/uploads'
# The 'source' specifies where the writable mount is. The 'local' source
# indicates that the mount point will point to a local directory on the
# application container. The 'source_path' specifies the subdirectory
# from within the source that the mount should point at. 
mounts:
  'web/uploads':
    source: local
    source_path: uploads

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

You are missing /tmp in your mounts:

    tmp:
        source: local
        source_path: tmp

This makes the /tmp directory writable.
To get a better understanding of how to configure your application, you can take a look at our ruby documentation page
Especially step 5, where mounts are setup.

thank you for your interest…
but after incorporating your recommendation,
I have always errors with APP, but I see Something interest on the connection to the database.

look at the build log:

    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: 
    W: Caused by:
    W: PG::ConnectionBad: could not connect to server: Connection refused
    W: 	Is the server running on host "localhost" (127.0.0.1) and accepting
    W: 	TCP/IP connections on port 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)

  Opening environment
  Environment configuration
    app (type: ruby:2.7, size: M, disk: 1024)
    dbpostgres (type: postgresql:13, size: M, disk: 9216)

my configuration of DATABASE.YML parameters in config:
config/database.yml


production:
  adapter: postgresql
  encoding: unicode
  host: localhost
  port: 5432
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  url: <%= ENV['DATABASE_URL'] %>
  database: <%= ENV['DATABASE_NAME'] %>
  username: <%= ENV['DATABASE_USERNAME'] %>
  password: <%= ENV['DATABASE_PASSWORD'] %>

the variables defined in credentials.yml.enc


production:
  database_url: postgresdatabase.internal
  database_name: production
  database_username: main
  database_password: main

my .platform/services.yaml

# The name given to the PostgreSQL service (lowercase alphanumeric only).
dbpostgres:
    # The type of your service (postgresql), which uses the format
    # 'type:version'. Be sure to consult the PostgreSQL documentation
    # (https://docs.platform.sh/configuration/services/postgresql.html#supported-versions)
    # when choosing a version. If you specify a version number which is not available,
    # the CLI will return an error.
    type: postgresql:13
     # The disk attribute is the size of the persistent disk (in MB) allocated to the service.
    disk: 9216
    configuration:
      extensions:
        - plpgsql
        - pgcrypto
        - uuid-ossp

if can you help to understand it.