さくらVPSでgitの自動デプロイを構築しています。
ローカルからのgit pushコマンドでVPS(以下、リモートの)にデプロイできるように設定したつもりなのですが、一部機能しません。
【環境】
git push origin master
でリモートの/var/www//html/dev/hogeTest
に
git push origin master:prod
でリモートの/var/www//html/dev/hogeTest
と/var/www/html/hogeProd
の両方にデプロイする。
-
上記のhogeTestとhogeProdはそれぞれリモートブランチからの
git clone /var/lib/git/hogeRemote.git
で設置されています。 (ブランチを指定してcloneはしていません。それぞれmasterブランチのみ保持しています。) -
リモートブランチの場所は
/var/lib/git/hogeRemote.git
-
post-update
/var/lib/git/hogeRemote.git/hooks/post-update
は以下のような記述となっています。
################ # test-deploy ################ if [ "$branch" = "master" ] then # Git Deploy to Test ENV cd /var/www/html/dev/hogeTest git --git-dir=.git pull origin master fi ################################ # test-deploy and prod-deploy ################################ if [ "$branch" = "prod" ] then # Git Deploy to Product ENV cd /var/www/html/hogeProd git --git-dir=.git pull origin master fi
【問題点】
git push origin master
で/var/www/html/dev/hogeTest
へのデプロイはできるが、git push origin master:prod
へのデプロイができない。
git push origin master:prod
をすると以下のような出力がされます。
Total 0 (delta 0), reused 0 (delta 0) remote: From /var/lib/git/hogeRemote remote: * branch master -> FETCH_HEAD remote: Already up-to-date. To git:/var/lib/git/hogeRemote.git 859d57e..b53f3ee master -> prod
リモートのprodブランチは更新されているようですが、/var/www/html/hogeProd
でのgit pullが実行先がおかしいせいか、hogeProdへのデプロイができません。
しかし、/var/www/html/hogeProd
にて手動でgit pull origin master
をすると問題なく動作し、デプロイが完了します。
ちなみに、git push origin master
の場合は以下のような出力です。
Counting objects: 5, done. Delta compression using up to 4 threads. Compressing objects: 100% (5/5), done. Writing objects: 100% (5/5), 396 bytes | 0 bytes/s, done. Total 5 (delta 4), reused 0 (delta 0) remote: From /var/lib/git/hogeRemote remote: * branch master -> FETCH_HEAD remote: Updating b53f3ee..cb429a0 remote: Fast-forward remote: hogehoge.php | 1 + remote: 1 files changed, 1 insertions(+), 0 deletions(-) To git:/var/lib/git/hogeRemote.git b53f3ee..cb429a0 master -> master
なぜ?
post-updateのtestもprodも同じベースに沿って記述しているのに、なぜprodだけ上手くいかないのでしょうか?
原因究明の方法や解決策等にアイデアがある方がいましたら助力頂けますと幸いです。
回答2件
あなたの回答
tips
プレビュー