taiseifukushi / kbus_timetable

kbus_timetable
https://kbus-timetable-husita-h.onrender.com
1 stars 0 forks source link

masterにマージされたらデプロイしたい #6

Closed taiseifukushi closed 2 years ago

taiseifukushi commented 2 years ago

herokuにデプロイする https://github.com/AkhileshNS/heroku-deploy を使う https://github.com/marketplace/actions/deploy-to-heroku

taiseifukushi commented 2 years ago

何かがうまくいっていないのでreopen

スクリーンショット 2022-08-14 2 22 20

これも気になる スクリーンショット 2022-08-14 2 24 35

https://github.com/husita-h/k-bus-norikae-app/runs/7820717906?check_suite_focus=true

taiseifukushi commented 2 years ago

スクリーンショット 2022-08-14 13 45 35

ActiveRecord::ConnectionNotEstablished could not translate host name "db" to address: Name or service not known

taiseifukushi commented 2 years ago

アドオンを追加 スクリーンショット 2022-08-14 14 13 28

taiseifukushi commented 2 years ago

スクリーンショット 2022-08-14 14 22 40

ActiveRecord::PendingMigrationError Migrations are pending. To resolve this issue, run: bin/rails db:migrate RAILS_ENV=development You have 7 pending migrations:


→ エラー画面に表示されているRun pending migrationsを押したらActiveRecord::PendingMigrationErrorはなくなった。

ただしデータは作成されていないみたい rails db:seedを実行したい

taiseifukushi commented 2 years ago

https://www.heroku.com/deploy-with-docker

taiseifukushi commented 2 years ago

エラー画面に表示されているRun pending migrationsを押したらActiveRecord::PendingMigrationErrorはなくなった。 ただしデータは作成されていないみたい rails db:seedを実行したい

デプロイされるたびにherokuコマンド使って手動でrails db:seedを実行しても良いけどやりたくない。 良いやり方ないだろうか

そもそもherokuでdocker compose upしているのなら、docker-compose.ymlのcommandでrails db:seedを実行するようにしているから、データ作成されていそうだけど


https://github.com/AkhileshNS/heroku-deploy/blob/79ef2ae4ff9b897010907016b268fd0f88561820/index.js#L66

コマンドを追加してみる docker compose run web rails db:drop db:create db:migrate db:seed RAILS_ENV=production

- run: |
          heroku auth:whoami
          echo "Set Jikokuhyo Data"s
          docker compose run web rails db:drop db:create db:migrate db:seed RAILS_ENV=production
taiseifukushi commented 2 years ago

https://dev.to/heroku/deploying-to-heroku-from-github-actions-29ej

taiseifukushi commented 2 years ago

https://github.com/husita-h/k-bus-norikae-app/runs/7837512807?check_suite_focus=true

Run set -e
heroku config:set RAILS_ENV=production
Setting RAILS_ENV and restarting ***... done, v22
RAILS_ENV: production
heroku run bundle exec rails db:drop db:create db:migrate db:seed RAILS_ENV=production
Running bundle exec rails db:drop db:create db:migrate db:seed RAILS_ENV=production on ***... starting, run.5819 (Free)
Running bundle exec rails db:drop db:create db:migrate db:seed RAILS_ENV=production on ***... connecting, run.5819 (Free)Running bundle exec rails db:drop db:create db:migrate db:seed RAILS_ENV=production on ***... up, run.5819 (Free)
rails aborted!
ActiveRecord::EnvironmentMismatchError: You are attempting to modify a database that was last run in `development` environment.
You are running in `production` environment. If you are sure you want to continue, first set the environment using:

        bin/rails db:environment:set RAILS_ENV=production

Tasks: TOP => db:drop => db:check_protected_environments
(See full trace by running task with --trace)
heroku ps
Free dyno hours quota remaining this month: 538h 54m (97%)
Free dyno usage for this app: 11h 5m (2%)
For more information on dyno sleeping and how to upgrade, see:
https://devcenter.heroku.com/articles/dyno-sleeping

=== web (Free): rails server -b 0.0.0.0 (1)
web.1: up 2022/08/15 [12](https://github.com/husita-h/k-bus-norikae-app/runs/7837512807?check_suite_focus=true#step:5:13):04:41 +0000 (~ 6s ago)
taiseifukushi commented 2 years ago

https://github.com/husita-h/k-bus-norikae-app/runs/7837584001?check_suite_focus=true

rails aborted!
ActiveRecord::ProtectedEnvironmentError: You are attempting to run a destructive action against your 'production' database.
If you are sure you want to continue, run the same command with the environment variable:
DISABLE_DATABASE_ENVIRONMENT_CHECK=1

Tasks: TOP => db:drop => db:check_protected_environments
(See full trace by running task with --trace)
taiseifukushi commented 2 years ago
Run set -e
heroku config:set RAILS_ENV=production
Setting RAILS_ENV and restarting ***... done, v24
RAILS_ENV: production
heroku run bin/rails db:environment:set RAILS_ENV=production
Running bin/rails db:environment:set RAILS_ENV=production on ***... starting, run.1979 (Free)
Running bin/rails db:environment:set RAILS_ENV=production on ***... connecting, run.1979 (Free)Running bin/rails db:environment:set RAILS_ENV=production on ***... up, run.1979 (Free)
heroku run bundle exec bin/rails db:drop db:create db:migrate db:seed
Running bundle exec bin/rails db:drop db:create db:migrate db:seed DISABLE_DATABASE_ENVIRONMENT_CHECK=1 RAILS_ENV=production bundle exec bin/rails db:drop db:create db:migrate db:seed on ***... starting, run.8498 (Free)
Running bundle exec bin/rails db:drop db:create db:migrate db:seed DISABLE_DATABASE_ENVIRONMENT_CHECK=1 RAILS_ENV=production bundle exec bin/rails db:drop db:create db:migrate db:seed on ***... connecting, run.8498 (Free)Running bundle exec bin/rails db:drop db:create db:migrate db:seed DISABLE_DATABASE_ENVIRONMENT_CHECK=1 RAILS_ENV=production bundle exec bin/rails db:drop db:create db:migrate db:seed on ***... up, run.8498 (Free)
Database 'ddmu4q27ppai8k' does not exist
We could not find your database: postgres. Which can be found in the database configuration file located at config/database.yml.

To resolve this issue:

- Did you create the database for this app, or delete it? You may need to create your database.
- Has the database name changed? Check your database.yml config has the correct database name.

To create your database, run:

        bin/rails db:create
Couldn't create 'ddmu4q27ppai8k' database. Please check your configuration.
rails aborted!
ActiveRecord::NoDatabaseError: We could not find your database: postgres. Which can be found in the database configuration file located at config/database.yml.

To resolve this issue:

- Did you create the database for this app, or delete it? You may need to create your database.
- Has the database name changed? Check your database.yml config has the correct database name.

To create your database, run:

        bin/rails db:create

Caused by:
PG::ConnectionBad: FATAL:  permission denied for database "postgres"
DETAIL:  User does not have CONNECT privilege.

Tasks: TOP => db:create
(See full trace by running task with --trace)
heroku ps
Free dyno hours quota remaining this month: 538h 54m (97%)
Free dyno usage for this app: 11h 5m (2%)
For more information on dyno sleeping and how to upgrade, see:
https://devcenter.heroku.com/articles/dyno-sleeping

=== web (Free): rails server -b 0.0.0.0 (1)
web.1: up [20](https://github.com/husita-h/k-bus-norikae-app/runs/7837721626?check_suite_focus=true#step:5:21)[22](https://github.com/husita-h/k-bus-norikae-app/runs/7837721626?check_suite_focus=true#step:5:23)/08/15 12:10:11 +0000 (~ 9m ago)

https://github.com/husita-h/k-bus-norikae-app/runs/7837721626?check_suite_focus=true

taiseifukushi commented 2 years ago
EDITOR="vim" bin/rails credentials:edit
# EDITOR="vim" bin/rails credentials:edit
Adding config/master.key to store the encryption key: 

Save this in a password manager your team can access.

If you lose the key, no one, including you, can access anything encrypted with it.

      create  config/master.key

Couldn't decrypt config/credentials.yml.enc. Perhaps you passed the wrong key?

Couldn't decrypt config/credentials.yml.enc. Perhaps you passed the wrong key?

組み合わせが正しくない →作り直し

config/credentials.yml.enc config/master.key 2つ削除


EDITOR="vim" bin/rails credentials:edit

# EDITOR="vim" bin/rails credentials:edit
Adding config/master.key to store the encryption key: 

Save this in a password manager your team can access.

If you lose the key, no one, including you, can access anything encrypted with it.

      create  config/master.key

File encrypted and saved.

master.key をherokuの環境変数としてセット

heroku config:set RAILS_MASTER_KEY=cat config/master.key -a k-bus-norikae-app Setting RAILS_MASTER_KEY and restarting ⬢ k-bus-norikae-app... done, v31 RAILS_MASTER_KEY:

taiseifukushi commented 2 years ago

[fix]ActionView::Template::Error (The asset application.css is not pr…

0b18d17 …esent in the asset pipeline.

変更箇所

環境変数を追加 ENV['RAILS_SERVE_STATIC_FILES'] = true

config/environments/production.rb config.assets.compile = false → config.assets.compile = true

サーバー起動時にbundle exec rails assets:precompile実行

taiseifukushi commented 2 years ago

`heroku config:add RAILS_LOG_TO_STDOUT="true"