15
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

herokuにrailsdeploy

Last updated at Posted at 2017-10-15

設定方法

HerokuCLIインストール

上記が詳しい

gitの登録

git上でのアカウント認証

$ heroku login
Enter your Heroku credentials.
Email: adam@example.com
Password (typing will be hidden):
Authentication successful.

herokuにアプリ作成

既存のアプリがない場合は下記

$ heroku create
Creating app... done, stack is cedar-14
https://xxxxxxxxxx.herokuapp.com/ | https://git.heroku.com/xxxxxxxxxx.git

remoteの設定

git remote add heroku url

上記コマンドで紐づけてもいいが、下記のherokuコマンドでも可能

環境変数の設定

環境変数を設定しておかないとdeploy時にerrorがでるので先に設定しておく。aws関連の環境変数があったら先にawsの設定をしておいたほうが良い。

pgの設定

remote:        In Gemfile:
remote:        sqlite3
remote:  !
remote:  !     Failed to install gems via Bundler.
remote:  !     Detected sqlite3 gem which is not supported on Heroku:
remote:  !     https://devcenter.heroku.com/articles/sqlite3
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !    Push rejected to looploop.
remote: 
To https://git.heroku.com/looploop.git

sqliteのままdeployすると上記のようなエラーが出てしまう。これはherokuがsqlite未対応のためである。

  • アプリにpostgresを追加
  • gemfileにpgを追加(productionのみに)
  • gemfileでsqliteをdevelopmentに移動

database.ymlの編集

database.ymlもpg用に書き換えないといけません。

database.yml
production:
  <<: *default
  adapter: postgresql
  username:
  host:
  database:
  password:
  database: db/production.sqlite3

gemfile

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
  # Use sqlite3 as the database for Active Record
  gem 'sqlite3'
end

group :production do
 gem 'pg'
end

デプロイ

$ git push heroku master

DBmigrate

heroku run rake db:migrate
15
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?