LoginSignup
4
4

More than 5 years have passed since last update.

capistrano3: cap install後にまずやること

Last updated at Posted at 2014-07-31

はじめに

capistrano3使う時、cap installコマンドでディレクトリ構成とかを作りますよね。
その後、installタスクが生きたままだと悲しい事が起きるので、それを無効化しておこうという話です。

いきなり結論

以下のコマンドでinstallタスクを無効化します。

echo "Rake::Task[:install].clear" >> Capfile

悲しい事?

cap installの実装を見ると、こうなっています。

capistrano-3.2.1/lib/capistrano/tasks/install.rake
...
 18   file = config_dir.join('deploy.rb')
 19   File.open(file, 'w+') do |f|
 20     f.write(ERB.new(template).result(binding))
 21     puts I18n.t(:written_file, scope: :capistrano, file: file)
 22   end
...

"w+"でdeploy.rbを開いてるので、まっさらにしてからテンプレートを書き出す実装ですね。
つまり、deploy.rbに何かを書いた状態でcap installを叩いてしまうと、deploy.rbが初期化されてしまいます。(Capfile/[env].rbも同じくですが)

そんなことする?

私はやらかしましたorz
具体的には、初回だけ叩くようなタスクをinstallという名前で実装したため、cap hoge installと叩いて誤爆してしまいました。
Rakeの仕様として、同名のタスクが定義された場合は、既にあるタスクに処理が追加されるため、意図せずinstallが走ってしまいます。

4
4
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
4
4