はじめに
これまでは、Windowsマシン上でRedmineプラグイン開発環境を用意するのに、仮想マシン(Hyper-Vなど)にLinuxを入れてその上でLinuxベースの開発環境を整える方法を取っていました。ただしCUI環境が主です。Hyper-VでGUI環境を動かすとかなり動作がもっさりして快適とは程遠いので(キー入力も一呼吸待たされる)、開発環境として使う気になれないほどです。
そこで、WSL(Windows Subsystem for Linux)でLinux環境を使う方法を試してみました。こちらはRailsサーバーの起動が著しく重く、やはり開発環境としては使いたくないほどです。また、Windows環境(ツール)からWSL上のファイルを編集するとパーミッションがおかしくなって崩壊することがあります。
そのため、RubyMineが宝の持ち腐れとなっていました。今回、Windows上にRubyを展開して素のWindowsのみでRedmineプラグイン開発環境を用意してみようとおもいました。
インストール
Windows上のRubyは、次のサイトから入手しました。
https://rubyinstaller.org/downloads/
[with Devkit]と書かれている開発キット込みのRubyをインストールします。2019年10月14日現在、2.6系の最新は
rubyinstaller-devkit-2.6.5-1-x64.exe
です。
インストーラーを実行し、ライセンス受諾し、インストール先を指定、PATH、関連付け、UTF-8デフォルトをチェックして(最初の2つはデフォルトでチェック)、MSYS2 development toolchainをチェックして(デフォルトでチェック)インストールします。
インストール完了するときに、MSYS2セットアップを実行するチェックを付けます。
すると、コマンドプロンプトでMSYS2セットアップが実行されます。
インストールするコンポーネントはデフォルトの[1,2,3]を実行(ENTERキーのみ入力でよい)します。
インストールが終わると、ENTERのみ入力してコマンドプロンプトを閉じます。
SQLite3のインストール
Windows用のSQLite3は次のサイトから入手しました。
https://www.sqlite.org/download.html
まず、Precompiled Binaries for Windows にある次のファイルを入手します。ここにはDLLファイルが含まれます。
sqlite-dll-win64-x64-3300100.zip
このDLLファイルを環境変数PATHの通っているディレクトリにコピーします。ここでは暫定でruby.exeのある場所(C:\tools\Ruby26-x64\bin\)に置きました。
次に、Source Codeにある次のファイルを入手します。開発用のヘッダーファイル、ソースファイルが含まれます。
sqlite-amalgamation-3300100.zip
このうちヘッダーファイル(sqlite3.h、sqlite3ext.h)を、rubyのincludeディレクトリ(ここではC:\tools\Ruby26-x64\include\ruby-2.6.0\)にコピーします。
RubyMineでRedmineのセットアップ
RubyMineを起動し、「Welcome to RubyMine」画面の右下[Configure]をクリックし、ドロップダウンリストから[Settings]を選択します。
「Settings for New Projects」画面の左側ペインで[Languages & Frameworks] > [Ruby SDK and Gems]を選択、[+]をクリックし、先ほどインストールしたRubyを追加します。環境変数PATHにruby.exeがあれば候補に登場するのでそれを選択します。
「Welcome to RubyMine」画面の[Check out from Version Control]をクリックし、リポジトリURLとクローン先のローカルディレクトリを指定します。
database.ymlの編集
config\database.ymlファイルを作成し、SQLite3の設定を記述します。
production:
adapter: sqlite3
database: db/redmine.sqlite3
development:
adapter: sqlite3
database: db/redmine.sqlite3
test:
adapter: sqlite3
database: db/redmine_test.sqlite3
bundlerでGemをインストール
Redmineが必要とするGemファイル群をプロジェクト配下にインストールします。
[Tools]メニュー > [Bundler] > [Install]をクリックし、「Bundle Install」ダイアログでオプション
--path vendor/bundler
を追記して実行します。
sqlite3でエラー
Fetching sqlite3 1.4.1
Installing sqlite3 1.4.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory:
D:/work/trunk_redmine/vendor/bundler/ruby/2.6.0/gems/sqlite3-1.4.1/ext/sqlite3
d:/tools/Ruby26-x64/bin/ruby.exe -I d:/tools/Ruby26-x64/lib/ruby/2.6.0 -r
./siteconf20191014-17576-1unxgm.rb extconf.rb
checking for sqlite3.h... yes
checking for pthread_create() in -lpthread... yes
checking for -ldl... no
checking for sqlite3_libversion_number() in -lsqlite3... no
sqlite3 is missing. Install SQLite3 from http://www.sqlite.org/ first.
*** 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.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=d:/tools/Ruby26-x64/bin/$(RUBY_BASE_NAME)
--with-sqlcipher
--without-sqlcipher
--with-sqlite3-config
--without-sqlite3-config
--with-pkg-config
--without-pkg-config
--with-sqlcipher
--without-sqlcipher
--with-sqlite3-dir
--without-sqlite3-dir
--with-sqlite3-include
--without-sqlite3-include=${sqlite3-dir}/include
--with-sqlite3-lib
--without-sqlite3-lib=${sqlite3-dir}/lib
--with-pthreadlib
--without-pthreadlib
--with-dllib
--without-dllib
--with-sqlcipher
--without-sqlcipher
--with-sqlite3lib
--without-sqlite3lib
bundle installでは、--with-sqlite3-libのオプションを指定しても認識できない模様なので、直接gem installで指定してみました。ただしgem installなのでシステム共通のgemとしてインストールされてしまいます。
>gem install sqlite3 --platform=ruby -- --with-sqlite3-include=c:/tools/ruby26-x64/include/ruby-2.6.0 --with-sqlite3-lib=c:/tools/ruby26-x64/bin
Fetching sqlite3-1.4.1.gem
Temporarily enhancing PATH for MSYS/MINGW...
Installing required msys2 packages: mingw-w64-x86_64-sqlite3
Building native extensions with: '--with-sqlite3-include=c:/tools/ruby26-x64/include/ruby-2.6.0 --with-sqlite3-lib=c:/tools/ruby26-x64/bin'
This could take a while...
Successfully installed sqlite3-1.4.1
Parsing documentation for sqlite3-1.4.1
Installing ri documentation for sqlite3-1.4.1
Done installing documentation for sqlite3 after 1 seconds
1 gem installed
セッション秘密鍵の生成
RubyMineからの実行方法が分からないので、コマンドプロンプトから実行しました。
bundle exec rails generate_secret_token
データベーススキーマの生成
bundle exec rails db:migrate
RubyMineの[Run]メニュー > [Run] で [Development: trunk_redmine]を選択すると、デフォルトサーバーが起動します。
めでたく起動しました
No Rails とエラーが出てRailsサーバーが実行できない場合
コマンドプロンプト上でbundle installを実行した後に、Runメニューから実行したらエラーとなってしまいました。その後、RubyMineの[Tools]メニューからbundle installを再実行し、Runメニューから実行したら実行できました。