Marchan4
@Marchan4 (Marchan4)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

SECRET_KEY_BASEの環境変数を設定したのに、HerokuアプリケーションがHeroku URLで動作しないのはなぜなのでしょうか?

Rubyのバージョンは2.6.6、mysqlのバージョンは8.0.23、mysql2のバージョンは0.5.3、bundlerのバージョンは2.2.21、railsのバージョンは5.0.7.2、Xcodeのバージョンは12.5です。

macOS Big Sur(バージョン11.4)とテキストエディタ「Atom」を使用しています。

次のエラーがURLに表示されたため、HerokuアプリケーションがHerokuURLで機能しません。

An unhandled lowlevel error occurred. The application logs may have details.

下記のように3つの環境変数を設定しました。

$ heroku config:set DATABASE_USERNAME=****
$ heroku config:set DATABASE_PASSWORD=****
$ heroku config:set SECRET_KEY_BASE="$(bundle exec rake secret)"

以下をGemfileに追加しました。

gem 'heroku_secrets', github: 'alexpeattie/heroku_secrets'

次のコマンドを実行しました。

$ bundle install --without production

Your /Users/****/.bundle/config config includes `BUNDLE_--LOCAK`, which contains the dash character (`-`).
This is deprecated, because configuration through `ENV` should be possible, but `ENV`keys cannot include dashes.
Please edit /Users/****/.bundle/config and replace any dashes in configuration keys with a triple underscore (`___`).
[DEPRECATED] The `--without` flag is deprecated because it relies on being remembered across bundler invocations, which bundler will no longer do in future versions. Instead please use `bundle config set --local without 'production'`, and stop using this flag
・・・
Bundle complete! 19 Gemfile dependencies, 69 gems now installed.
Gems in the group 'production' were not installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

そして、次のコマンドを実行しました。

$ bundle exec rake heroku:secrets[APP_NAME] RAILS_ENV=production

Your /Users/****/.bundle/config config includes `BUNDLE_--LOCAK`, which contains the dash character (`-`).
This is deprecated, because configuration through `ENV` should be possible, but `ENV`keys cannot include dashes.
Please edit /Users/****/.bundle/config and replace any dashes in configuration keys with a triple underscore (`___`).
[DEPRECATED] `Bundler.with_clean_env` has been deprecated in favor of `Bundler.with_unbundled_env`. If you instead want the environment before bundler was originally loaded, use `Bundler.with_original_env` (called at /Users/****/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/bundler/gems/heroku_secrets-****/lib/heroku_secrets/tasks
.rb:28)

rake aborted!

Don't know how to build task '[APP_NAME]' (See the list of available tasks with `rake --tasks`)
/Users/****/.rbenv/versions/2.6.6/bin/bundle:23:in `load'
/Users/****/.rbenv/versions/2.6.6/bin/bundle:23:in `<main>'
(See full trace by running task with --trace)

以下のようにHerokuにコードをデプロイしました。

$ git push heroku main

・・・
remote: ###### WARNING:
remote:
remote:        You have not declared a Ruby version in your Gemfile.
remote:
remote:        To declare a Ruby version add this line to your Gemfile:
remote:
remote:        ```  
remote:        ruby "2.6.6"  
remote:        ```
remote:
remote:        For more information see:
remote:          https://devcenter.heroku.com/articles/ruby-versions
remote:
remote: ###### WARNING:
remote:
remote:        There is a more recent Ruby version available for you to us

remote:
remote:
remote:        2.6.8
remote:
remote:        The latest version will include security and bug fixes. We
always recommend
remote:        running the latest version of your minor release.
remote:
remote:        Please upgrade your Ruby version.
remote:
remote:        For all available Ruby versions see:
remote:          https://devcenter.heroku.com/articles/ruby-support#supported-runtimes
remote:
remote: ###### WARNING:
remote:
remote:        No Procfile detected, using the default web server.
remote:        We recommend explicitly declaring how to boot your server process via a Procfile.
remote:        https://devcenter.heroku.com/articles/ruby-default-web-server
remote:
remote:
remote: -----> Discovering process types
remote:        Procfile declares types     -> (none)
remote:        Default types for buildpack -> console, rake, web
remote:
remote: -----> Compressing...

remote:        Done: 44.2M
remote: -----> Launching...
remote:        Released v10
remote:        https://[APP_NAME].herokuapp.com/ deployed
to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/[APP_NAME].git
   5963057..b503389  main -> main

次のコマンドを実行しました。

$ git push heroku main

Everything up-to-date

次のコマンドを実行しました。

$ heroku config

===[APP_NAME] Config Vars
DATABASE_PASSWORD: ****
DATABASE_URL: postgres://****
DATABASE_USERNAME: ****
LANG: en_US.UTF-8
RACK_ENV: production
RAILS_ENV: production
RAILS_LOG_TO_STDOUT: enabled
RAILS_SERVE_STATIC_FILES: enabled
SECRET_KEY_BASE: ****
_SECRET_SECRET_KEY_BASE:
_SECRET_SECRET_TOKEN:

次のコマンドを実行しました。

$ heroku config:unset _SECRET_SECRET_KEY_BASE _SECRET_SECRET_TOKEN

Unsetting _SECRET_SECRET_KEY_BASE, _SECRET_SECRET_TOKEN and restarting ⬢ [APP_NAME]... done, v11

次のコマンドを実行しました。

$ heroku config

=== [APP_NAME] Config Vars
DATABASE_PASSWORD: ****
DATABASE_URL: postgres://****
DATABASE_USERNAME: ****
LANG: en_US.UTF-8
RACK_ENV: production
RAILS_ENV: production
RAILS_LOG_TO_STDOUT: enabled
RAILS_SERVE_STATIC_FILES: enabled
SECRET_KEY_BASE: ****

次のコマンドを実行しました。

$ heroku open

しかし、次のエラーがHerokuURLに表示されたため、私のHerokuアプリケーションはそのURLでは機能しません。

An unhandled lowlevel error occurred. The application logs may have details.

$ heroku logsというコマンドで以下のエラーが出てきました。

#<RuntimeError: Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`>

しかし、下記のURL通りにエラーを解決しようと思っても、どのサーバーにログインしたらいいのかや、

$ vi /etc/profileというファイルが何なのかがわかりませんでした。

SECRET_KEY_BASEの環境変数を設定したのに、HerokuアプリケーションがHeroku URLで動作しないのはなぜなのでしょうか?

0

No Answers yet.

Your answer might help someone💌