ハイパーニートプログラマーへの道

頑張ったり頑張らなかったり

Rails Tutorial 1.5 Deploying Nitrous.ioからHerokuへプッシュするまで

Rails Tutorial Chapter1に沿ってやっていきます。

1.5 Deploying

1.5.1 Heroku setup

前回の続きですが 、何はともあれHerokuでアカウント作成します。

Rails Tutorial Chapter1をやる Nitrous.ioからBitbucketにリポジトリも作ってみる - ハイパーニートプログラマーへの道

通常は使用している環境にHeroku Toolbeltをインストールするのですが、Nitrousなら用意されています。

$ heroku version                                                                                                                 
heroku-toolbelt/3.25.0 (x86_64-linux) ruby/2.1.1                                                                                                                   
You have no installed plugins.  

Herokuにログイン

Nitorous.ioのコンソール上で

$ heroku login 

herokuに登録したメースアドレスとパスワードを入力

Enter your Heroku credentials.                                                                                                                                     
Email: YOUR EMAIL ADDRESS                                                                                                             
Password (typing will be hidden):                                                                                                                                  
Found existing public key: /home/action/.ssh/id_rsa.pub                                                                                                            
Uploading SSH public key /home/action/.ssh/id_rsa.pub... done                                                                                                      
Authentication successful.

Herokuから確認のメールがきます。

Gemfileの編集

Herokuで使用するDBはPostgreSQLなので、その設定をします。
チュートリアルにならい、バージョンも指定しました。

group :production do
  gem 'pg',             '0.17.1'
  gem 'rails_12factor', '0.0.2'
end

これらの本番環境でだけ必要なgemをローカルに入れないように--without productionオプションをつけてbundle install

忘れずにコミット。

git commit -am "Update Gemfile.lock for Heroku"

Herokuにアプリ作成

heroku create (アプリ名)

アプリ名を省略してもいいそうなので、そうしましたところ、pure-garden-2482という素敵な名前がつきました。

$ heroku create                                                                                      
Creating pure-garden-2482... done, stack is cedar-14                                                                                                               
WARNING: Incomplete credentials detected, git may not work with Heroku. Run `heroku login` to update your credentials. See documentation for details: https://devce
nter.heroku.com/articles/http-git#authentication

しかし何か警告が出ていますね。

Deploying with Git | Heroku Dev Center

よくわからんが、もう一回heroku loginしてメルアドとパスワード入力。すると Authentication successful.とでました。

またRails 4の場合は, rake rails:update:bin というコマンドを打っておく必要があります (rails newした後かも)

Nitrous.ioでRuby on RailsをHerokuへ - temp.txt

とあるので、タイミングははっきりしませんが、pushする直前にやりました。

$ rake rails:update:bin                                                                              
       exist  bin                                                                                                                                                  
   identical  bin/bundle                                                                                                                                           
    conflict  bin/rails                                                                                                                                            
Overwrite /home/action/workspace/hello_app/bin/rails? (enter "h" for help) [Ynaqdh] h                                                                              
        Y - yes, overwrite                                                                                                                                         
        n - no, do not overwrite                                                                                                                                   
        a - all, overwrite this and all others                                                                                                                     
        q - quit, abort                                                                                                                                            
        d - diff, show the differences between the old and the new                                                                                                 
        h - help, show this help                                                                                                                                   
Overwrite /home/action/workspace/hello_app/bin/rails? (enter "h" for help) [Ynaqdh] Y                                                                              
       force  bin/rails                                                                                                                                            
    conflict  bin/rake                                                                                                                                             
Overwrite /home/action/workspace/hello_app/bin/rake? (enter "h" for help) [Ynaqdh] Y                                                                               
       force  bin/rake                                                                                                                                             
   identical  bin/setup

gitは作成してあるので、

heroku git:remote -a pure-garden-2482

でリモート登録。

デプロイの方法はHerokuの自分のアプリページ>Deployの欄に書いてあります。

f:id:noriyo_tcp:20150205215355p:plain

git push heroku master

http://アプリの名前.heroku.com/でページを開く。

f:id:noriyo_tcp:20150205215414p:plain

ポップアップが邪魔ですが・・・w

heroku run rake db:migrate

はまだ。hello, worldしただけですしな。


その他参考記事:

Deploying with Git | Heroku Dev Center