LoginSignup
5
3

More than 5 years have passed since last update.

HerokuでRedmineをデプロイ(までの長い道のり)

Last updated at Posted at 2016-12-15

2016/10/10にリリースされた 3.3.1 をHerokuにデプロイして利用できるようにする。
しかしこれがわりとハマるところが多かった…
前例多いけど、わりと環境にも依存するので なかなか一筋縄でいかない感じが(

そしてまだリアルタイム作業中だよ!よ!

そもそもなぜHerokuを選んだか

みなさんいろんな観点で選定すると思うんですよ。
クラウド使う人が多いとは思う。
今回はこういう観点で選定してみまんた。

  • 自前でリソース準備しなくても良い(=PaaS含めクラウドのメリット)
  • 初期構築コストが(IaaSほど)かからない
    • IaaSの場合:OSにも左右されるのでライブラリの依存関係もわりとシビアに考えないといけなかったり
  • Ruby、Java、Python、Scalaなど複数言語とフレームワークをサポート
  • 基本的な機能は無料枠で利用できる。お財布に優しい
  • Gitを使ってデプロイ
    • Gitに慣れているデベロッパはNO学習コスト

RedmineのDLページ

Guide » Installation Guide » RedmineInstall » Download

3rd-party製のもの

RedmineがバンドルされたVMもある。
* とにかく Redmine 使いたいんや(震え声
* 環境構築 手間かかりすぎィ!?
* パッケージの 依存関係 考えるのマンド!
という諸々の理由により手っ取り早くデプロイしたい場合
こちらを利用するのもあり。

今回はあえてマンドイ手法を採用します。
そして案の定マンドかったです。

Redmineをインストール

先人のお知恵をかなり拝借させていただきました。
Redmine3.0系をHerokuで動かせるようにする

RedmineはRedmineなだけあって、公式もちゃんとRedmine上で書かれてる。
Guide » Installation Guide » Installing Redmine

Redmineの動作環境

Redmine version Supported Ruby versions Rails version used
3.3, current trunk ruby 1.9.3, 2.0.0, 2.1, 2.2, 2.3 Rails 4.2
3.2, 3.1 ruby 1.9.3, 2.0.0, 2.1, 2.2 Rails 4.2

各パッケージのアップデート/インストール

当方の環境は MacOS Sierra なのでその環境ベースでの手順。
尚、パッケージ管理には Homebrew 使用。

Ruby

    > % ruby -v
    ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]

stable版で2.3.3が出てる。Redmineでもサポートされているのでここでアップデートしてしまう。

    -> % brew info ruby
    ruby: stable 2.3.3 (bottled), devel 2.4.0-beta3, HEAD
    Powerful, clean, object-oriented scripting language
    https://www.ruby-lang.org/
    /usr/local/Cellar/ruby/2.3.1_2 (1,261 files, 18.8M) *
      Poured from bottle on 2016-10-14 at 21:14:58
    From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/ruby.rb
    ==> Dependencies
    Build: pkg-config ✔
    Required: libyaml ✔, openssl ✔
    Recommended: readline ✘
    Optional: gdbm ✔, gmp ✘, libffi ✔

    ・・・ (以下略) ・・・

どうせなら上げてしまいたいのでアップデートする。

    -> % brew upgrade ruby

    ・・・ (中略) ・・・

    ==> Installing ruby
    ==> Downloading https://homebrew.bintray.com/bottles/ruby-2.3.3.sierra.bottle.tar.gz
    ######################################################################## 100.0%
    ==> Pouring ruby-2.3.3.sierra.bottle.tar.gz
    ==> Using the sandbox
    ==> Caveats
    Emacs Lisp files have been installed to:
      /usr/local/share/emacs/site-lisp/ruby
    ==> Summary
    🍺  /usr/local/Cellar/ruby/2.3.3: 1,263 files, 18.9M

2.3.1 → 2.3.3 へ上がったことを確認

    -> % ruby -v
    ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16]

RubyGems(gem)

Rails含め、ruby関連のパッケージ管理用に RubyGems を使用(以下gemとする
まずgem本体をアップデートする
※ ここは用途・目的に応じてアップデートの要否は自身の判断で

    -> % gem update --system
    Updating rubygems-update
    Fetching: rubygems-update-2.6.8.gem (100%)
    Successfully installed rubygems-update-2.6.8

Rails - インストール時にまさかのビルドエラー発生

Railsはサポートされてるバージョンが 4.2 であるため、バージョンを指定してインストールしたが、ビルド時にエラー発生。nokogiri怪しい。

    -> % gem install rails -v 4.2.0
    ERROR:  Error installing rails:
        ERROR: Failed to build gem native extension.

        current directory: /usr/local/lib/ruby/gems/2.3.0/gems/nokogiri-1.6.8/ext/nokogiri
    /usr/local/opt/ruby/bin/ruby -r ./siteconf20161215-7511-1r17cb1.rb extconf.rb
    Using pkg-config version 1.1.7
    checking if the C compiler accepts ... /usr/local/Cellar/ruby/2.3.3/lib/ruby/2.3.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
    You have to install development tools first.
        from /usr/local/Cellar/ruby/2.3.3/lib/ruby/2.3.0/mkmf.rb:571:in `block in try_compile'
        from /usr/local/Cellar/ruby/2.3.3/lib/ruby/2.3.0/mkmf.rb:522:in `with_werror'
        from /usr/local/Cellar/ruby/2.3.3/lib/ruby/2.3.0/mkmf.rb:571:in `try_compile'
        from extconf.rb:138:in `nokogiri_try_compile'
        from extconf.rb:162:in `block in add_cflags'
        from /usr/local/Cellar/ruby/2.3.3/lib/ruby/2.3.0/mkmf.rb:629:in `with_cflags'
        from extconf.rb:161:in `add_cflags'
        from extconf.rb:414:in `<main>'

    To see why this extension failed to compile, please check the mkmf.log which can be found here:

      /usr/local/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-16/2.3.0/nokogiri-1.6.8/mkmf.log

    extconf failed, exit code 1

    Gem files will remain installed in /usr/local/lib/ruby/gems/2.3.0/gems/nokogiri-1.6.8 for inspection.
    Results logged to /usr/local/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-16/2.3.0/nokogiri-1.6.8/gem_make.out

前El Capitanの時はビルドエラーにならなかったので (Railsインストール自体は実は以前やってる
あれ?と思い、とりあえずログをあさる。

    /RubyGems_PATH/2.3.0/extensions/x86_64-darwin-16/2.3.0/nokogiri-1.6.8/mkmf.log

このへんが問題っぽい。

    xcrun: error: invalid active developer path 
    (/Library/Developer/CommandLineTools), 
    missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

Sierraだとわりと発生してる問題なのかな。
macOS Sierra: invalid active developer path

あと本家にも明記されてる。
Installing Nokogiri - MacOS X

なのでインストールする。
コマンド実行したらGUIでインストールのポップアップ画面が出てくるので、ウィザードに沿ってインストール。

    > % xcode-select --install
    xcode-select: note: install requested for command line developer tools

xcode-select-install 2016-12-15 20-09-15.png

からのgemパッケージアップデート

    > % gem update

で、Railsインストール(--no-ri --no-rdocオプションつけ忘れ
やっと成功したがまだ先は長い。。。

    -> % gem install rails -v 4.2.0
    Fetching: rails-4.2.0.gem (100%)
    Successfully installed rails-4.2.0
    Parsing documentation for rails-4.2.0
    Installing ri documentation for rails-4.2.0
    Done installing documentation for rails after 334 seconds
    1 gem installed

Heroku

herokuもここでインストールしておく

> % gem install heroku

ここからやっと本題のRedmineの設定へ

とりあえずホームディレクトリに移動

-> % cd ~/

ホームディレクトリ配下にRedmineをgit cloneする

    -> % git clone https://github.com/redmine/redmine.git
    Cloning into 'redmine'...
    remote: Counting objects: 131947, done.
    remote: Compressing objects: 100% (19/19), done.
    remote: Total 131947 (delta 6), reused 0 (delta 0), pack-reused 131928
    Receiving objects: 100% (131947/131947), 46.56 MiB | 5.01 MiB/s, done.
    Resolving deltas: 100% (100519/100519), done.
    Checking connectivity... done.

Redmine - バージョン確認

取得してきたRedmineのバージョンを確認する。
3.3.1だから現時点の最新のバージョン。

version.rb
    module Redmine
      module VERSION #:nodoc:
        MAJOR = 3
        MINOR = 3
        TINY  = 1

ディレクトリを移動する

    -> % cd redmine

各種設定はこちらを参考に。
HerokuにRedmineをデプロイする方法

Herokuの設定

herokuコマンドで設定する。

デプロイ用のスペース(=アプリ名)を作成

    -> % heroku create redmine-XXX
    Creating ⬢ redmine-XXX... done
    https://redmine-XXX.herokuapp.com/ | https://git.heroku.com/redmine-XXX.git

gitでローカルにコミットする

    -> % git status
    On branch master
    Your branch is up-to-date with 'origin/master'.
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)

        modified:   .gitignore
        modified:   Gemfile
        new file:   Gemfile.lock
        renamed:    config/database.yml.example -> config/_database.yml.example
        modified:   config/application.rb
        modified:   config/environments/production.rb

    > % git commit -am "[add]redmine deploy"
    [master 7f3bd7dea] [add]redmine deploy
     6 files changed, 229 insertions(+), 39 deletions(-)
     create mode 100644 Gemfile.lock
     rename config/{database.yml.example => _database.yml.example} (100%)

HerokuにPush → エラー発生

nonexistent database だからDBがなくてrejectされたっぽかったので

    remote:        Tasks: TOP => environment
    remote:        (See full trace by running task with --trace)
    remote:  !
    remote:  !     Precompiling assets failed.
    remote:  !     Attempted to access a nonexistent database:
    remote:  !     https://devcenter.heroku.com/articles/pre-provision-database
    remote:  !
    remote:  !     Push rejected, failed to compile Ruby app.
    remote:
    remote:  !     Push failed
    remote: Verifying deploy....
    remote:
    remote: !   Push rejected to redmine-XXX.

Heroku Postgresアドオンを追加。

    -> % heroku addons:add heroku-postgresql
    Creating heroku-postgresql on ⬢ redmine-XXX... free
    Database has been created and is available
     ! This database is empty. If upgrading, you can transfer
     ! data from another database with pg:copy
    Created postgresql-tetrahedral-60883 as DATABASE_URL
    Use heroku addons:docs heroku-postgresql to view documentation

Herokuに再度Push → それでもエラー

Gemfile見直さないと。。。

    remote:        Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
    remote:        Gem::LoadError: pg is not part of the bundle. Add it to Gemfile.

後半につづく

5
3
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
5
3