はじめてのHeroku

■前提
Ruby1.9.2とRails3.0.10がインストール済
・Herokuアカウント登録済
・gitインストール済(sudo apt-get install git-core)
・libssl-dev, openssl, libopenssl-ruby がインストール済
ssh-keygen で鍵情報作成済

Railsアプリ新規作成

$ mkdir -p ~/git/heroku
$ cd git/heroku
$ rails new hogeheroku01
$ cd hogeheroku01

$ vi Gemfile

group :production do
  gem 'pg'
end

group :development, :test do
  gem 'sqlite3'
end

$ bundle install
$ rails server
(WEBrickが起動されるので、localhost:3000にアクセスして確認)

■scaffold

$ rails g scaffold Person name:string gender:string birthday:date
$ rake db:migrate
$ rails server
(WEBrickが起動されるので、localhost:3000/people にアクセスして確認)

■herokuコマンドインストール
(heroku Toolbelt 以前)

$ gem install heroku
$ sudo apt-get install libreadline-dev
$ cd ~/.rvm/src/ruby-1.9.2-p290/ext/readline/
$ ruby extconf.rb && make && make install
$ heroku keys:add
Email: xxxxxx@gmail.com
Password:
Could not find an existing public key.
Would you like to generate one? [Yn] Y
Generating new SSH public key.
Uploading ssh public key /home/xxxx/.ssh/id_rsa.pub

(heroku Toolbelt)

$ sudo apt-get install heroku-toolbelt

■gitコミット&Herokuデプロイ

$ cd ~/git/heroku/hogeheroku01
$ git init
$ git add .
$ git commit -m "first commit"
$ heroku create
(以下のように出ていればOK)
Createing xxxxxxxxx... done, 〜
http:xxxxxxxxx.heroku.com/ | git@heroku.com:xxxxxxxxx.git
Git remote heroku added
(HerokuのMyAppに作られているか確認。アプリ名はこの時点では適当につけられている)
(MyAppsでアプリ名を好きなものに変更)

$ vi .git/config
(以下の変更を行う)
url = git@heroku.com:変更したアプリ名.git

$ git push heroku master
(色々とpushされているログがでる)

$ heroku rake db:migrate
$ heroku open
(http://hogeheroku01.heroku.com/people にアクセス)
(RailsアプリがデプロイされていればOK)