いちいちsshでサーバー繋いで、git pullするのもめんどくさくなってきた事と
Capistranoのオプションが気になったので設定してみた。
参考
Capistranoでアプリケーションのデプロイ作業を効率化
git使用です。
# SCM(Software Configuration Management)はgit使用 set :scm, :git
後、他にも色々オプションがあるみたい
Deploying with Capistrano
特に気になったのがこれ
set :deploy_via, :remote_cache
説明読んでみると
In most cases you want to use this option, otherwise each deploy will do a full repository clone every time
(ほとんどのケースであなたはこのオプションを使用する。そうしないと、毎回のデプロイでフルリポジトリクローンをします)Remote caching will keep a local git repo on the server you’re deploying to and simply run a fetch
from that rather than an entire clone.
(リモートキャッシングはサーバーでローカルgitレポジトリを保って、全てのクローンよりもむしろそれから取得してきます)This is probably the best option as it will only fetch the changes since the last.
(最後から変化を取得するだけで、これは多分ベストオプションでしょう)
デプロイ時に毎回全クローンされるのはこれを指定しないからっぽい
というわけで、このオプションをつけた時にコマンドがどう変わるのかが気になったので調べてみた。
・オプションつけない時
executing " git clone -q git@github.com:mamehiko/app.git /home/user/app/app/releases/20110510080527 && cd /home/user/app/app/releases/20110510080527 && git checkout -q -b deploy xxxhashxxx && (echo xxxhashxxx > /home/user/app/app/releases/20110510080527/REVISION)" executing " rm -f /home/user/app/app/current && ln -s /home/user/app/app/releases/20110510080527 /home/user/app/app/current"
cloneをreleaseに直で作成しcurrentのシンボリックリンク変えてるだけ
常に全取得をしているので時間がかかる!
・オプションつけた時
executing " if [ -d /home/user/app/app/shared/cached-copy ]; then cd /home/user/app/app/shared/cached-copy && git fetch -q origin && git reset -q --hard xxxhashxxx && git clean -q -d -x -f; else git clone -q git@github.com:mamehiko/app.git /home/user/app/app/shared/cached-copy && cd /home/user/app/app/shared/cached-copy && git checkout -q -b deploy xxxhashxxx; executing " cp -RPp /home/user/app/app/shared/cached-copy /home/user/app/app/releases/20110510081544 && (echo xxxhashxxx > /home/user/app/app/releases/20110510081544/REVISION)" executing " rm -f /home/user/app/app/current && ln -s /home/user/app/app/releases/20110510080527 /home/user/app/app/current"
一回目
shared/cached-copyディレクトリがないのでshared/cached-copyにcloneを作成し、cached-copyをreleaseにコピーしcurrentのシンボリックリンク変更
二回目以降
shared/cached-copyディレクトリが作成されているので、それに対し更新をかける。
その後cached-copyをreleaseにコピーしcurrentのシンボリックリンク変更
なるほどなるほど。sharedのcached-copyに常に最新がコピーされるので差分だけで済む訳かー
まさしくベストオプション!