Mina – シンプルで汎用的なデプロイツール
サーバのデプロイ作業というのは意外と面倒なもので、ミスも発生しやすいです。そこでデプロイツールが活躍します。RubyではCapistranoというツールが有名ですが、汎用的に使えてシンプルなデプロイツールとしてMinaが登場しました。
Minaのインストール
Rubygemsを使って簡単にインストールできます。
$ gem install mina
Minaの使い方
まずはヘルプを見てみましょう。
$ mina
mina - Really fast server deployment and automation tool
Options:
-h, --help Show help
-V, --version Show program version
-v, --verbose Show commands as they happen
-S, --simulate Run in simulation mode
-t, --trace Show backtraces when errors occur
-f FILE Use FILE as the deploy configuration
Basic usage:
mina help # Show help
mina init # Creates a sample config file
mina tasks # Show all tasks
Run this command in a project with a 'config/deploy.rb' file to see more options.
All of Rake's options are also available as 'mina' options. See 'rake --help'
for more information.
最初に初期設定を行います。initサブコマンドで設定ファイルが生成されます。
$ mina init
-----> Created ./config/deploy.rb
Edit this file, then run `mina setup` after.
そして実行。deployサブコマンドでデプロイします。
$ mina deploy --verbose
-----> Creating the build path
$ mkdir tmp/build-128293482394
-----> Cloning the Git repository
$ git clone https://github.com/nadarei/flipstack.git . -n --recursive
Cloning... done.
-----> Installing gem dependencies using Bundler
$ bundle install --without development:test
Using i18n (0.6.0)
Using multi_json (1.0.4)
...
Your bundle is complete! It was installed to ./vendor/bundle
-----> Moving to releases/4
$ mv "./tmp/build-128293482394" "releases/4"
-----> Symlinking to current
$ ln -nfs releases/4 current
-----> Launching
$ cd releases/4
$ sudo service nginx restart
-----> Done. Deployed v4
Minaの特徴としては、Capistranoなどが個々のコマンドごとにSSHセッションを分けているのに対して、Minaは一つのセッションの中で実行しているのでスピードアップが臨めるようです。実際には実行しないシミュレーション機能、ログもあります。
特にRuby/Ruby on Railsに密接している訳ではないので(専用モジュールはありますが)、Ruby以外の言語向けのデプロイに使うこともできそうです(Capistranoもバージョン3から汎用的になったようですが)。
MinaはRuby製、MIT Licenseのオープンソース・ソフトウェアです。