我正在使用capistrano 3部署我们的机架应用程序。我们可以按预期部署分支机构。但是在部署之后,当我使用所有代码登录到当前文件夹中的服务器时,我没有看到.git。即使我git init,下次部署时,它也会再次丢失。无论如何,我可以保留.git并跟踪我们正在部署哪个分支?谢谢
current
目录不是git工作副本。 Capistrano故意不包括.git
目录。
实际的git存储库可以在repo
目录中的current
目录中找到,但我不认为这就是你要求的。听起来您希望能够找出用于部署current
内容的分支或SHA。
与current
一起应该是一个名为revisions.log
的文件。如果你tail
它你可以看到最新的版本,包括分支,SHA和执行发布的用户:
$ tail -n 3 revisions.log
Branch master (at 609bf349776b24f85f85b1950b92314b2d8f3bdc) deployed as release 20170927161115 by mbrictson
Branch master (at 6a77bde58a2de42428b44da669c8f01475d6cd46) deployed as release 20171107004019 by mbrictson
Branch master (at 6d0395ca4067180e0d76735c36b6852691b360ea) deployed as release 20171107011743 by mbrictson
或者,您可以编写自定义Capistrano任务以将分支写入特殊文件。例如:
desc "Write the branch to a .branch file in the release that was deployed"
task :write_branch do
on release_roles(:all) do
within release_path do
execute :echo, "#{fetch(:branch)} > .branch"
end
end
end
after "deploy:updating", "write_branch"