docker, docker-compose はセットアップ済の前提。
作成対象のプラグインの名前が redmine_plugin_of_yours
の場合の例。
とりあえず素の Redmine を立ち上げてみる
docker-compose.yml
を作成してアプリ・DB のコンテナを立ちあげるだけ。
## ディレクトリ作成
$ mkdir redmine_plugin_of_yours/
## 作成したディレクトリに移動
$ cd redmine_plugin_of_yours/
## docker-compose 設定ファイル作成
$ vi docker-compose.yml
内容はこんな感じ。
version: "2"
services:
app:
image: sameersbn/redmine
environment:
- DB_HOST=db
- DB_NAME=redmine_production
- DB_USER=root
- DB_PASS=root
links:
- db
depends_on:
- db
ports:
- 8080:80
volumes:
- ./:/home/redmine/redmine/plugins/redmine_plugin_of_yours/
db:
image: mysql
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=redmine_production
ドッカーコンポーザップ。
# docker-compose のバックグラウンドモードで開発用の Redmine アプリコンテナと MySQL データベースコンテナを起動
$ docker-compose up -d
Creating network "redminepluginofyours_default" with the default driver
Creating redminepluginofyours_db_1
Creating redminepluginofyours_app_1
しばらくすると http://localhost:8080 で Redmine が利用できるようになる。
(環境によっては結構時間がかかるかも。)
デフォルトの ID/PW = admin/admin でログインできることを確認しておく。
プラグインのスケルトン生成
Redmine が用意してくれているジェネレーターでプラグイン開発用のスケルトンを生成する。
## プラグイン用スケルトン生成用のコマンドを実行
$ docker-compose exec app bundle exec ruby bin/rails generate redmine_plugin redmine_plugin_of_yours
create plugins/redmine_plugin_of_yours/app
create plugins/redmine_plugin_of_yours/app/controllers
create plugins/redmine_plugin_of_yours/app/helpers
create plugins/redmine_plugin_of_yours/app/models
create plugins/redmine_plugin_of_yours/app/views
create plugins/redmine_plugin_of_yours/db/migrate
create plugins/redmine_plugin_of_yours/lib/tasks
create plugins/redmine_plugin_of_yours/assets/images
create plugins/redmine_plugin_of_yours/assets/javascripts
create plugins/redmine_plugin_of_yours/assets/stylesheets
create plugins/redmine_plugin_of_yours/config/locales
create plugins/redmine_plugin_of_yours/test
create plugins/redmine_plugin_of_yours/test/fixtures
create plugins/redmine_plugin_of_yours/test/unit
create plugins/redmine_plugin_of_yours/test/functional
create plugins/redmine_plugin_of_yours/test/integration
create plugins/redmine_plugin_of_yours/README.rdoc
create plugins/redmine_plugin_of_yours/init.rb
create plugins/redmine_plugin_of_yours/config/routes.rb
create plugins/redmine_plugin_of_yours/config/locales/en.yml
create plugins/redmine_plugin_of_yours/test/test_helper.rb
## カレントディレクトリを Redmine アプリコンテナの /home/redmine/redmine/plugins/redmine_plugin_of_yours
## にマウントしているので、ホスト側からもファイルが読み書きできるようになる
$ ls
README.rdoc assets db init.rb test
app config docker-compose.yml lib
## 立ち上げた Redmine のアプリコンテナを再起動
$ docker-compose restart app
Restarting redminepluginofyours_app_1 ... done
再び http://localhost:8080 にログインすると、「管理 -> プラグイン」から作成しようとしているプラグインが追加されていることが確認できる。
あとは git init して docker-compose.yml や生成されたスケルトンをコミットしつつ、Plugin Tutorial - Redmine を見ながらプラグイン開発していけばよさそう。
ほんとはプラグインを修正したら、Redmine アプリコンテナを自動的に再起動されるようになってるとよさそうだけど、簡単なやり方をすぐには思い浮かばないので別途考えてみよう。