如何configurationCapistrano从本地Git仓库部署?

我需要对下面的deploy.rb文件进行哪些更改才能使其从本地git库中部署我的应用程序? 如果我不能从本地回购部署,我可以让Capistrano使用工作拷贝吗?

 set :application, "my_app" set :repository, "." set :local_repository, "file:///path/to/application/.git" set :deploy_to, "/data/www/apps/#{application}" set :deploy_via, :copy set :copy_cache, true set :user, "dane" set :use_sudo, false set :scm, :git # Should I change this to :none set :branch, "master" 

这很容易:

 set :scm, :none set :repository, "." set :deploy_via, :copy 

只需从项目的根部运行Capistrano即可。

 set :repository, 'file:///path/to/your/git_repository' set :local_repository, "file://." set :scm, :git # set :deploy_via, :copy # you must comment it 

版本3中已经放弃了deploy_via, :copy

https://github.com/capistrano/capistrano/issues/695

在大多数情况下,你应该在github或者bitbucket之类的在线仓库中存放你的代码,然后你只需要在你的deploy.rb文件中设置这一行:

 set :repo_url, 'git@bitbucket.org:my_account/my_project.git' 

虽然如果您碰巧在您正在部署的远程服务器上有一个存储库,那么您可以将您的deploy.rb文件中的那一行更改为:

 set :repo_url, 'file:///home/deploy/bare_repo/my_project.git' 

请记住,三个斜杠是重要的,因为file://告诉capistrano你正在寻找一个文件,而前面的斜杠需要指向一个根path,这个path就像/home/deploy/bare_repo/my_project.git

我使用了@Ariejan和@HungYuHei为我工作的答案。

 set :deploy_via, :copy set :use_sudo, false set :scm, "git" set :repository, "." set :local_repository, "." set :branch, "master" 

如果使用本地副本(并且没有Github上的项目),那么禁用:check_revision deploy.rb中的:check_revision任务也是明智的,它检查远程是否与本地git同步。

Capistrano 3解决scheme正在运行:

  before :deploy, :deploy_from_local_repo task :deploy_from_local_repo do set :repo_url, "file:///tmp/.git" run_locally do execute "tar -zcvf /tmp/repo.tgz .git" end on roles(:all) do upload! '/tmp/repo.tgz', '/tmp/repo.tgz' execute 'tar -zxvf /tmp/repo.tgz -C /tmp' end end 

在部署之前,您需要上传一个tar.gz文件到服务器,解压并最终将repo_url重置为文件模式。

小心删除以前的回购:

 task :remove_repo do on roles(:all) do execute "rm -r #{repo_path}" end end 

通常通过复制部署是非常缓慢的。 但是copy_cache只有在scm不是none的情况下才可用(sync使用scm),这意味着从工作副本的部署只能用慢速拷贝来完成。 我设法find一个快速的本地回购复制部署快速设置。 你仍然需要在本地提交更改,但不需要推送。

 set :scm, "git" set :local_repository, "file://." set :deploy_via, :copy # cache only seems to work if use scm set :copy_cache, true set :copy_via, :scp set :copy_exclude, [".zeus*", ".bundle", ".git", "tmp/*", "doc", "log/*", "fixtures/*"] 

不幸的是,它有时会被神秘地打破:

 fatal: Could not parse object 'c438b9d1242cb311be43d681e3f89bc486d748ed'.` 

理想情况下,即使没有使用scm从工作副本部署到工作,也应该实施本地caching同步。 伟大的function添加到capistrano