2011-04-03 101 views
50

我需要對下面的deploy.rb文件進行哪些更改才能使其從本地git倉庫部署我的應用程序?如果我無法從本地回購部署,我可以讓capistrano使用工作複製嗎?如何配置Capistrano從本地Git存儲庫進行部署?

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" 

回答

56

這很簡單:

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

只需從你的項目的根目錄運行Capistrano的。

+5

+1。但是,在capistrano v 2.12.0中,我還必須執行'set:local_repository','' – Zabba 2012-04-14 07:37:55

+3

這將包括scm中被忽略的文件嗎? – lulalala 2012-05-31 03:16:41

+13

它不適用於capistrano 3.想法? – 2013-11-04 15:24:24

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

通常通過複製部署是超慢的。 但是copy_cache只有在scm不是none的情況下才可用(sync使用scm) 這意味着從工作副本的部署只能用緩慢的副本完成。 我設法從本地倉庫快速找到複製部署的快速設置。 儘管您仍然需要在本地提交更改,但不需要推送更改。

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用於部署從工作拷貝本地緩存應予執行。偉大的功能添加到卡皮斯特拉諾

5

我使用@Ariejan和@HungYuHei答案的組合爲我工作。

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

如果使用本地副本(而不必在Github上的項目),那麼它也是明智的你deploy.rb它檢查遠程是否與當地的git同步禁用:check_revision任務。

+2

我收到以下'致命的:沒有遠程配置來列出refs .' – Intentss 2013-10-29 14:10:39

7

deploy_via, :copy已經版本已經降至3

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

在大多數情況下,你應該有你的代碼像github上或一個到位桶在線倉庫,然後你只需要設置這條線在你的deploy.rb文件:

set :repo_url, '[email protected]:my_account/my_project.git' 

但如果你碰巧有要部署過的遠程服務器上的存儲庫,那麼你會改變這條線在deploy.rb文件是這樣的:

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

請記住,這三個正斜槓是重要的,因爲file://告訴你正在尋找一個文件Capistrano的,並且需要前面的斜線指向這將是像/home/deploy/bare_repo/my_project.git根路徑。這是運行對我來說

4

Capistrano的3溶液:

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 
+0

這適用於我,除非我得到一個錯誤'refs/stash不指向有效的對象!',直到我將tar命令更改爲'tar -zcvf/tmp /repo.tgz --exclude = .git/refs/stash .git'。謝謝! – 2015-09-25 19:29:44

相關問題