LoginSignup
22
21

More than 5 years have passed since last update.

OpenFastladderをherokuにデプロイする方法

Last updated at Posted at 2013-03-21

前提

  • heroku toolbelt がインストール済であること
  • Heroku のアカウントを持っていること

準備

まずはheroku用にGemfileの整理などを行なう。

$ git clone https://github.com/fastladder/fastladder.git
$ cd fastladder/

heroku用に依存するGemの置き換え。(sqlite3とmysql2をやめて、かわりにpgとthinをいれる)

$ sed -i -e 's/sqlite3/pg/' Gemfile
$ sed -i -e 's/mysql2/thin/' Gemfile
$ bundle install --path .bundle
    $ git add Gemfile Gemfile.lock
$ git commit -m "Gemfile"

Procfileを作る。

$ echo 'web: bundle exec rails server -p $PORT' > Procfile
$ echo 'crawler: bundle exec ruby script/crawler' >> Procfile
$ git add Procfile
$ git commit -m "Procfile"

それ以外の設定ファイルを生成する。

$ echo 'gem "therubyracer"' >> Gemfile
$ echo 'gem "sqlite3"' >> Gemfile
$ bundle
$ cp config/database.yml.sqlite3 config/database.yml
$ bundle exec rake setup i18n:js:export
$ git add -f app/assets/javascripts/i18n/
$ git add -f config/initializers/secret_token.rb
$ git commit -m "some other files"
$ git checkout .

Webのデプロイ

$ heroku apps:create openfl-demo
$ heroku addons:add heroku-postgresql:dev
$ git push heroku master
$ heroku run bundle exec rake db:migrate --app openfl-demo
$ heroku ps:scale crawler=0 web=1

http://openfl-demo.herokuapp.com にアクセスして、デプロイ結果を確認する。

クローラのデプロイ

heroku configで、Postgresqlの接続URLを確認する。

$ heroku config --app openfl-demo
=== openfl-demo Config Vars
DATABASE_URL:               postgres://xxxx:yyyy@zzz.amazonaws.com:5432/wwwww
HEROKU_POSTGRESQL_GOLD_URL: postgres://xxxx:yyyy@zzz.amazonaws.com:5432/wwwww

クローラをデプロイする。

$ heroku apps:create openfl-demo-crawler
$ heroku config:set --app openfl-demo-crawler  DATABASE_URL=postgres://xxxx:yyyy@zzz.amazonaws.com:5432/wwwww HEROKU_POSTGRESQL_GOLD_URL=postgres://xxxx:yyyy@zzz.amazonaws.com:5432/wwwww
$ git push git@heroku.com:openfl-demo-crawler.git master
$ heroku ps:scale --app openfl-demo-crawler crawler=1 web=0

動作してるかどうかはheroku logsで確認する。

$ heroku logs -t --app openfl-demo-crawler

その他

  • Heroku Postgresqlはサイズ制限が厳しいので、本格的に使うなら有料プランを検討したほうがいい
  • 動作のカスタマイズは config/application.yml をいじる
22
21
1

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
22
21