LoginSignup
13
14

More than 5 years have passed since last update.

Redmineテーマやプラグイン開発環境を構築する (rbenv版)

Last updated at Posted at 2013-03-20

テーマやプラグインが開発したくなったので運用環境で作業せずに開発環境を構築してみたメモ。

RVMからrbenvに切り替えたので http://qiita.com/items/31982ee3de80efa4c31b の書き直し。

前提

ポリシー的にはなるべく簡単に、そして環境を限定的に。

  • Redmine 2.x向け
  • GitでRedmine本体を管理する
  • Redmine本体の開発については対象外
  • 自分のテーマやプラグインは個別のGitリポジトリで管理(submoduleとかは使わない)
  • rbenvを使う
  • gemパッケージはbundlerでプロジェクト内にインストールする
  • データベースはSQLiteを使う

RVM版からの変更点

  • RVMの代わりにrbenvを使う
  • gemsetの代わりにbundler install --pathでRedmineのディレクトリにインストール
    • コマンドを叩くときにbundle execする

rbenvのセットアップ

OS X

OS Xが楽。Homebrew + bashの例

brew update
brew install rbenv
brew install ruby-build
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

Ubuntu

Ubuntuはaptでrbenvは見つかったが古い、そしてruby-buildがない。でもrbenv/ruby-buildともにgitから取得するだけでいいようだ。

git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.profile
echo 'eval "$(rbenv init -)"' >> ~/.profile

Redmineの実行環境を作る

Redmineの配置

git clone https://github.com/redmine/redmine redmine-dev
cd redmine-dev
git checkout -b develop/2.2.1 2.2.1

Redmineをgitで落として、バージョンのタグからdevelop/{version}という名前のローカルブランチを作って使う。

Rubyのインストール

RedmineのRubyのバージョンを確認する。
http://www.redmine.org/projects/redmine/wiki/RedmineInstall

rbenvをセットアップしておき、適切なRubyのバージョンを以下のようにインストールする。Rubyのインストールを後回しにしたのはrbenv localをRedmineのパスで実行したかったそれ以上の深い理由はなし。

rbenv install 1.9.3-p327
gem install bundler
rbenv rehash

Redmineのセットアップ

Redmine 2.3.1にあげたらGemfileが改良されておりdatabase.ymlのadapterを見て適切なデータベースドライバをインストールするようになり、--without mysqlなどのグループによる除外が機能しなくなる

cp -p config/database.yml.example config/database.yml

でデータベースの構成ファイルを作成して以下のように修正。

config/database.yml
production:
  adapter: sqlite3
  database: db/production.sqlite3
development:
  adapter: sqlite3
  database: db/development.sqlite3
test:
  adapter: sqlite3
  database: db/development.sqlite3

bundlerで依存モジュールを解決する。

rbenv local 1.9.3-p327
bundle install --without development test rmagick mysql postgresql --path vendor/bundle

粛々とセットアップ。

bundle exec rake generate_secret_token
RAILS_ENV=production bundle exec rake db:migrate
RAILS_ENV=production bundle exec rake redmine:load_default_data
mkdir tmp tmp/pdf public/plugin_assets

Redmineの実行

bundle exec ruby script/rails server webrick -e production

で実行して、 http://localhost:3000/ にアクセス。admin/adminでログインできる。

あとはテーマやプラグインを好き勝手に開発。基本的にRedmine本体の開発はしないのでredmine-dev/.gitはRedmineのバージョンアップ時にブランチを切り替えるだけで特にコミットはせず、自分のテーマやプラグインについてはnew fileで差分が出たままの状態にしておく。

Redmineバージョンアップ時の作業

リポジトリの最新を取得して、新しいバージョンのタグからローカルブランチを切り替えてデータのマイグレーションとかを行う。

ブランチの切り替え

git checkout master
git pull; git pull --tags
git checkout -b develop/x.x.x x.x.x

データの再セットアップ。

bundle install --without development test rmagick mysql postgresql --path vendor/bundle
bundle exec rake db:migrate RAILS_ENV="production"
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
bundle exec rake tmp:cache:clear
bundle exec rake tmp:sessions:clear

.bundle/configに前回のオプションが残っているからbundle installのオプションはいらない気もするけど念のため。

13
14
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
13
14