xxxcaqui.log

ツッコミお待ちしています

HerokuでRedmine使ってみた。

Redmineを落とす

$ git clone git://github.com/redmine/redmine.git
$ cd redmine

使用するバージョンを指定する

使いたいバージョンを選んで、git checkoutする。

$ git checkout 2.3-stable

precompile設定をする

#config/application.rb
module RedmineApp
  class Application < Rails::Application
    config.assets.initialize_on_precompile = false
  end
end

environment.rbを編集する

environment.rbの「exit 1」があるとmigration時に怒られるため、コメントアウトします。*1

# Make sure there's no plugin in vendor/plugin before starting
vendor_plugins_dir = File.join(Rails.root, "vendor", "plugins")
  if Dir.glob(File.join(vendor_plugins_dir, "*")).any?
  $stderr.puts "Plugins in vendor/plugins (#{vendor_plugins_dir}) are no longer allowed. " +
    "Please, put your Redmine plugins in the `plugins` directory at the root of your " +
    "Redmine directory (#{File.join(Rails.root, "plugins")})"
# exit 1
end

database.ymlを編集

あらかじめ用意されているスケルトンを編集して、Heroku向けのdatabase.ymlを作成する。

$ cp config/database.yml.example config/database.yml

MySQLの設定をコメントアウトし、下の方にあるPostgreSQLの設定を使用します。

#config/database.yml

production:
  adapter: postgresql
  database: redmine
  host: localhost
  username: postgres
  password: "postgres"

#production:
#  adapter: mysql2
#  database: redmine
#  host: localhost
#  username: root
#  password: ""
#  encoding: utf8

シークレットトークンを作成する

必要なgemを入れ、secret_token.rbを作成します。*2

$ bundle install
$ bundle exec rake generate_secret_token

PostgreSQLのgem「pg」が入らない場合。

gitignoreを編集する

作成したシークレットトークンや編集したdatabase.ymlなどをGitの管理対象に加えるために.gitignoreから以下の6行を削除する。

#.gitignore
/config/database.yml
/config/initializers/session_store.rb
/config/initializers/secret_token.rb
/public/plugin_assets
/Gemfile.lock
/Gemfile.local

Heroku上にアプリケーションを作成・設定する

$ heroku apps:create your_app_name
$ git push heroku 2.3-stable:master
$ heroku run rake db:migrate
$ heroku run rake redmine:load_default_data
Select language[en]: ja
====================================
Default configuration data loaded.
$ heroku restart
$ heroku open

heroku openで開ければOKです。

初期アカウントadmin/adminでログインしてアカウントを作成し、admin/adminを削除してください。

補足:PostgreSQLのgemが入らない場合

bundle installしたときに、以下のようなエラーが出て、pgが入らないとこがあります。

Gem::Installer::ExtensionBuildError:
  ERROR: Failed to build gem native extension.

  ~/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb 
checking for pg_config... no
No pg_config... trying anyway.
If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason,
probably lack of necessary libraries and/or headers.
Check the mkmf.log file for more
details.  You may need configuration options.

Gem files will remain installed
in ~/.rvm/gems/ruby-1.9.3-p194/gems/pg-0.15.1 for inspection.
Results logged
to ~/.rvm/gems/ruby-1.9.3-p194/gems/pg-0.15.1/ext/gem_make.out
An error occured while installing pg (0.15.1),
and Bundler cannot continue.

その場合には、libpq-devを入れてください。*3

$ sudo apt-get install libpq-dev

*1:ローカルに/vendor/pluginsがなくても、if文の中に入ります。Heroku側の仕様?

*2:このbundle installはdatabase.ymlの編集後に行なってください。Gemfile内でdatabase.ymlを読み込んで、インストールするgemを判別します。

*3:少なくとも、Ubuntu12.04の場合。