cluchのブログ

業務で使ったり、学んでいる知識を忘れないために覚書として使っていく予定。

デプロイ

Herokuのセットアップ

Herokuにユーザ登録する

https://signup.heroku.com/identity

必要なHerokuソフトウェアをインストール

Heroku Toolbeltを使用する。
Ubuntuの場合下記コマンドのみでインストールできた。

wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh


本番(production)環境に pg gem をインストール

HerokuではPostgreSQLデータベスを使用するみたいなので、
RailsPostgreSQLと通信できるようにする。

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


Herokuサーバ上にアプリケーション用の場所を作成する

アプリケーションのルートディレクトリにて行う。

$ heroku create

Herokuにデプロイする

Gitを使用してHerokuにリポジトリをプシュする
$ git push heroku master


ブラウザを起動させる
$ heroku open



エラー

無料で使える制限

Herokuでは、無料で使える制限が5個までみたいなので、
6個目を作ろうとすると(heroku create)下記のエラーが発生する。

!    You've reached the limit of 5 apps for unverified accounts.
!    Add a credit card to verify your account.

その場合、Heroku | Loginからログインし、
アプリを削除するか、
カードの登録をして、制限を無くす方法があるみたい。

Herokuに未対応のRubyバージョン

Herokuにプッシュしようとすると下記のエラーが発生

Counting objects: 67, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (56/56), done.
Writing objects: 100% (67/67), 14.84 KiB | 0 bytes/s, done.
Total 67 (delta 6), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote:  !
remote:  !     An error occurred while installing Ruby ruby-2.1.1
remote:  !     For supported Ruby versions see https://devcenter.heroku.com/articles/ruby-support#supported-runtimes
remote:  !     Note: Only the most recent version of Ruby 2.1 is supported on Cedar-14
remote:  !     Command: 'set -o pipefail; curl --fail --retry 3 --retry-delay 1 --connect-timeout 3 --max-time 30 https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/cedar-14/ruby-2.1.1.tgz -s -o - | tar zxf - ' failed unexpectedly:
remote:  !     
remote:  !     gzip: stdin: unexpected end of file
remote:  !     tar: Child returned status 1
remote:  !     tar: Error is not recoverable: exiting now
remote:  !
remote: 
remote:  !     Push rejected, failed to compile Ruby app
remote: 
remote: Verifying deploy...
remote: 
remote: !	Push rejected to blooming-plains-4354.
remote: 
To https://git.heroku.com/blooming-plains-4354.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/blooming-plains-4354.git'

調べてみると、Herokuには対応しているRubyのバージョンが限られているみたいで、

Supported runtimes
Heroku supports the following Ruby versions and the associated Rubygems:
MRI:
1.8.7 : patchlevel 376, Rubygems : 1.8.24 (Not supported on cedar-14)
1.9.2 : patchlevel 327, Rubygems: 1.3.7.1 (Not supported on cedar-14)
1.9.3 : patchlevel 551, Rubygems : 1.8.23.2
2.0.0 : patchlevel 598, Rubygems : 2.0.14
2.1.5 : patchlevel 265, Rubygems: : 2.2.2
2.2.0 : patchlevel 0, Rubygems: ; 2.4.5
Ruby 1.8.7 and Ruby 1.9.2 will reach end-of-life on 30 June 2014. After this date, security patches will no longer be available for these versions of Ruby.

との事みたいです。(2015/01/17現在)