LoginSignup
36
34

More than 5 years have passed since last update.

Redmine on Heroku

Last updated at Posted at 2013-04-24

=================

RedmineのSidekiqプラグインを作ったのでHerokuにRedmineをデプロイしました。
(MOGOKにデプロイした手順はこちら)

Sidekiqは非同期の処理が簡単に実装できるライブラリです。
Redmineではチケットの一括処理やレポーティングなど時間のかかる
処理を実施するときに非同期処理が便利です。

Clockworkも便利なライブラリでcronの様な定期的な処理が簡単に実装できます。
時間帯によってメニューを変更するやロールを自動で設定するなどの用途に使えます。

Sidekiqプラグインを利用するとClockworkのGemもインストールされます。
また、SidekiqのアドインのGemもいくつかインストールされます。
Sandboxのサンプルを使えばすぐにSidekiqの非同期処理を試す事ができます。

今回はHerokuでSidekiqのWorkerをClockworkで定期的に実行してみました。
Rails(Redmine),Sidekiq,Clockworkの3プロセスを動かすとコストは高いですが
多様なアプリケーションを実装することができます。

環境

  • Mac OS X Lion
  • Ruby 1.9.3p392
  • Redmine 2.2.4
  • Sidekiq 2.10.0
  • Clockwork 0.5.0

手順

エディタを使わないでコマンドのみでRedmineを公開できます。
(作業時間は10分程度です。)

主にgitbundlerherokuのコマンドを利用します。

$ gem install bundler
$ gem install heroku

Redmine

GitのリポジトリからRedmineをダウンロードして安定版を使います。

$ git clone https://github.com/redmine/redmine.git
$ cd redmine
$ git checkout 2.2-stable

Comment Out

Herokuのデプロイでエラーになる箇所をコメントアウトします。

HerokuでSqliteは使えません。

$ sed -i.bak 's/gem "sqlite3"/#gem "sqlite3"/g' Gemfile
$ rm Gemfile.bak

secret_token.rbなどをリポジトリに含めます。

$ sed -i.bak 's/\/config\/configuration.yml/#\/config\/configuration.yml/g' .gitignore
$ sed -i.bak 's/\/config\/email.yml/#\/config\/email.yml/g' .gitignore
$ sed -i.bak 's/\/config\/initializers\/session_store.rb/#\/config\/initializers\/session_store.rb/g' .gitignore
$ sed -i.bak 's/\/config\/initializers\/secret_token.rb/#\/config\/initializers\/secret_token.rb/g' .gitignore
$ sed -i.bak 's/\/public\/plugin_assets/#\/public\/plugin_assets/g' .gitignore
$ sed -i.bak 's/\/Gemfile.lock/#\/Gemfile.lock/g' .gitignore
$ sed -i.bak 's/\/Gemfile.local/#\/Gemfile.local/g' .gitignore
$ rm .gitignore.bak

exit 1をコメントアウトします。

$ sed -i.bak 's/exit/#exit/g' ./config/environment.rb
$ rm ./config/environment.rb.bak

Sidekiq

Redisが必要なのでREDIS TO GOfree planを使いました。

$ git clone https://github.com/ogom/redmine_sidekiq.git ./plugins/redmine_sidekiq
$ rm -rf ./plugins/redmine_sidekiq/.git
$ rm ./plugins/redmine_sidekiq/.gitignore 
$ cat << __EOS__ > ./plugins/redmine_sidekiq/config/sidekiq.yml
production:
  redis:
    url: redis://redistogo:abc123def456hij789@dogfish.redistogo.com:9876
    namespace: sidekiqspace
  status:
    expiration: 30
__EOS__

Foreman

HerokuはForemanでSidekiqのWorkerを管理します。
Procfileを作成するとHerokuでForemanが実行されます。

$ cat << __EOS__ > Procfile
web:    bundle exec rails server -p \$PORT
worker: bundle exec sidekiq -c 2
clock:  bundle exec clockwork schedule/clock.rb
__EOS__

Clockwork

こちらのサンプルはSandboxWorkerが1分間隔で実行されます。

$ mkdir schedule
$ cat << __EOS__ > ./schedule/clock.rb
require_relative '../config/boot'
require_relative '../config/environment'

require 'clockwork'
module Clockwork
  every(1.minutes, 'SandboxWorker') { SandboxWorker.perform_async }
end
__EOS__

Bundler

シークレットトークンを作成します。

$ bundle install --path=.bundle --without development test mysql postgresql rmagick
$ bundle exec rake generate_secret_token

Heroku

Deploy

Herokuにアプリケーションをデプロイします。
(ブランチはstablemasterにします。)

heroku openコマンドでブラウザにRedmineが表示されるとデプロイは成功です。

$ heroku create redmine224
$ git add .
$ git commit -m "prepare for heroku"
$ git push heroku 2.2-stable:master
$ heroku run rake db:migrate
$ heroku run rake redmine:load_default_data REDMINE_LANG=en
$ heroku restart
$ heroku open

デフォルト管理アカウント

  • username:admin
  • password:admin

デフォルトの管理アカウントは変更しましょう!

Resources

Herokuは単体プロセスの利用のみ無料です。順番にプロセスを切替えて
Rails、Sidekiq、Clockworkの動作を確認しましょう。
(heroku psコマンドでプロセスの一覧が表示されます。)

まず、clockworkを起動して、次にsidekiqWorkerが実施します。
最後にWeb UIProcessedの数字が増えていたら処理が実行されています。
(heroku logsコマンドでForemanの標準出力が表示されます。)

$ heroku ps:scale web=0 worker=0 clock=0
$ heroku ps:scale web=0 worker=0 clock=1
$ heroku ps:scale web=0 worker=1 clock=0
$ heroku ps:scale web=1 worker=0 clock=0

Tips

SidekiqプラグインはTopメニューにSidekiqが表示されます。
クリックするとSidekiqのWeb UIが表示されます。
(Web UIは管理者でログインすると表示されます。管理者のみ利用可能です。)

Herokuはファイルの書き込みが可能なのでチケットにファイルの添付ができます。

info

36
34
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
36
34