chef - git レポジトリを扱う
最近のアプリケーションは git clone してパスを設定するだけ、
というものも増えてますが、chefにも git リソースがあります。
git のリモートリポジトリと同期をとり、更新を検出してくれる
点で execute リソースより優れています。
git "/home/hogehoge/somehoge" do repository "https://github.com/deratame/somehoge.git" revision "master" user "hogehoge" group "hogehoge" action :sync end
actionについてですが、
:syncは、ローカルリポジトリが存在しなければclone、それ以外は更新
:checkoutは、ローカルリポジトリが存在しない場合のみcloneを行い、それ以外は何もしない
:exportは、そのまんまexport
です
revision(reference)で、ブランチを指定します。未指定の場合は HEAD です。
notifies と組み合わせれば、更新した場合にコマンドを実行させることができます。
git "/home/hogehoge/somehoge" do repository "https://github.com/deratame/somehoge.git" revision "master" notifies :run, "execute[command]" end execute "commend" do cwd "/home/hogehoge/somehoge" command <<-EOF ./refresh.sh EOF action :nothing end
なお、デプロイを行うには git ではなく deployリソースがあります。
deployリソースを使うと、webアプリケーションのデプロイの流れ、
checkout して、DBをマイグレーションし、シンボリックリンクを張り替え、再起動するという制御ができます。