73
74

More than 5 years have passed since last update.

Redmine3.0系をHerokuで動かせるようにする

Last updated at Posted at 2015-04-26

なかなか一つのことに集中できないタチで、複数プロジェクトの掛け持ちや複数アプリの並行開発なんかをしたりします。すると、
「あれ、○○アプリって次に何をすればいいんだっけ?」
となります。しょっちゅう。
なので、個人Redmineを建てようと思い、個人用だしHeroku上で無料運用だな、と考えたのですが、地味に引っかかりポイントが多かったので、手順を残しておきます。

説明は少なめ、コード中心に行きます。
出来上がりはGitHubにおいてあります。
What Should I do next?

前提

Redmineの3.0系がリリースされたので、それを使うことにする。

  • rubyは2.2
  • Railsは4.2

が対応している。

最新版をクローンする

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

でローカルにクローンしてきて、

$ cd redmine

に移動する。

.gitignoreを編集する

/config/configuration.yml
/config/email.yml
/config/initializers/session_store.rb
/config/initializers/secret_token.rb
/public/plugin_assets
/Gemfile.lock
/Gemfile.local

を削除して、

/vendor/bundle

を追加する。

Gemfileを編集する

Gemfileの上部に

ruby '2.2.1'

と追記する。その後、

# Include database gems for the adapters found in the database
# configuration file
require 'erb'
require 'yaml'
database_file = File.join(File.dirname(__FILE__), "config/database.yml")
if File.exist?(database_file)
  database_config = YAML::load(ERB.new(IO.read(database_file)).result)
  adapters = database_config.values.map {|c| c['adapter']}.compact.uniq
  if adapters.any?
    adapters.each do |adapter|
      case adapter
      when 'mysql2'
        gem "mysql2", "~> 0.3.11", :platforms => [:mri, :mingw, :x64_mingw]
        gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
      when 'mysql'
        gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
      when /postgresql/
        gem "pg", "~> 0.17.1", :platforms => [:mri, :mingw, :x64_mingw]
        gem "activerecord-jdbcpostgresql-adapter", :platforms => :jruby
      when /sqlite3/
        gem "sqlite3", :platforms => [:mri, :mingw, :x64_mingw]
        gem "jdbc-sqlite3", "< 3.8", :platforms => :jruby
        gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
      when /sqlserver/
        gem "tiny_tds", "~> 0.6.2", :platforms => [:mri, :mingw, :x64_mingw]
        gem "activerecord-sqlserver-adapter", :platforms => [:mri, :mingw, :x64_mingw]
      else
        warn("Unknown database adapter `#{adapter}` found in config/database.yml, use Gemfile.local to load your own database gems")
      end
    end
  else
    warn("No adapter found in config/database.yml, please configure it first")
  end
else
  warn("Please configure your config/database.yml first")
end

これを全部コメントアウトして、その下に

group :production do
  gem "pg", ">= 0.11.0", :platforms => [:mri, :mingw, :x64_mingw]
  gem 'rails_12factor'
  gem "activerecord-jdbcpostgresql-adapter", :platforms => :jruby
end

を追加。

config/application.rbを編集する

config.assets.initialize_on_precompile = false

を追加。

gemパッケージをインストールする

$ bundle install --path vendor/bundle --without development test rmagick

セッションストアを初期化

$ bundle exec rake generate_secret_token

初期化する。

Herokuにアップする

まずはHeroku上に新規アプリを作る。

$ heroku login

  Enter your Heroku credentials.
  Email: ********
  Password (typing will be hidden):
  Authentication successful.

$ heroku create [NAME]

  Creating [NAME]... done, stack is cedar
  http://[NAME].herokuapp.com/ | git@heroku.com:[NAME].git
  Git remote heroku added

次に、Postgreを入れておく。

$ heroku addons:add heroku-postgresql

普段RailsアプリをPushするときは行わないステップだが、これをやらないと

Precompiling assets failed.
remote:  !     Attempted to access a nonexistent database:
remote:  !     https://devcenter.heroku.com/articles/pre-provision-database

と怒られた。
で、

$ git add .
$ git commit -am "make it better"
$ git push heroku master

でHerokuへとPushする。

Redmineをセットアップする

まずはmigrateする。

$ heroku run rake db:migrate RAILS_ENV=production

次は初期データの読み込み。

$ heroku run rake redmine:load_default_data RAILS_ENV=production

最後に再起動。

$ heroku restart

これでHerokuアプリのURLにアクセスしてみて、画面が表示されれば完了!
初期状態だとID、Passwordともにadminになっているので、それぞれ変更しておくこと。

お世話になったページ

73
74
0

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
73
74