如何配置Capistrano从本地Git存储库部署?

时间:2021-12-08 07:23:54

What changes do I need to make to the deploy.rb file below to make it deploy my app from a local git repo? If I can't deploy from a local repo, can I have capistrano use the working copying instead?

我需要对部署做什么更改。下面的rb文件让它从本地git repo部署我的应用?如果我不能从本地repo部署,是否可以让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"

6 个解决方案

#1


56  

That's easy:

这很简单:

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

Simply run Capistrano from the root of your project.

简单地从项目的根运行Capistrano。

#2


7  

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

#3


7  

The deploy_via, :copy has been dropped in version 3.

deploy_via:copy在版本3中已经被删除。

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

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

In most cases you should have your code in a online repository like github or bitbucket, and then you just have to set this line in your deploy.rb file:

在大多数情况下,您应该将代码放在像github或bitbucket这样的在线存储库中,然后您只需在部署中设置这一行即可。rb文件:

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

Though if you happen to have a repository on the remote server that you are deploying too, then you would change that line in your deploy.rb file to be this:

尽管如果您碰巧在正在部署的远程服务器上有一个存储库,那么您将在部署中更改这一行。rb文件如下:

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

Keep in mind that the three forward slashes are important since the file:// tells capistrano that you are looking for a file, and the preceding slash is needed to point to a root path which would be something like /home/deploy/bare_repo/my_project.git.

请记住,三个前斜杠是很重要的,因为文件://告诉capistrano您正在寻找一个文件,需要前面的斜杠指向一个根路径,该路径类似于/home/deploy/bare_repo/my_project.git。

#4


5  

I used a combination of @Ariejan and @HungYuHei answers which worked for me.

我使用了@Ariejan和@HungYuHei答案的组合,这对我很有效。

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

If you use local copy (and don't have the project on Github), then it is also wise to disable :check_revision task in your deploy.rb which checks whether remote is in sync with local git.

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

#5


4  

Capistrano 3 solution which is running for me:

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

Before deploying you are uploading a tar.gz file to the server, unzip and finally reset the :repo_url to file mode.

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

Take care to remove the pervious repo:

注意去除之前的回复:

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

#6


0  

normally deploy via copy is super slow. but copy_cache only available if scm is NOT none (sync uses scm) this means that deploy from working copy can only be done with sluggish copy. I managed to find a fast setup for copy deploy from local repo that is fast. You still need to locally commit changes though but do not need to push them.

通常通过复制部署是非常缓慢的。但是,只有当scm不是none(同步使用scm)时,copy_cache才可用,这意味着从工作副本中部署只能通过缓慢的副本完成。我设法从本地repo找到了一个快速的复制部署设置。您仍然需要在本地提交更改,但不需要推动它们。

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/*"]

Unfortunately it sometimes breaks mysteriously with:

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

fatal: Could not parse object 'c438b9d1242cb311be43d681e3f89bc486d748ed'.`

Ideally syncing local cache should be implemented even if no scm is used for deploy from working copy to work. great feature to add to capistrano

理想的同步本地缓存应该是实现的,即使没有scm用于从工作副本部署到工作。这是capistrano的一大特色。

#1


56  

That's easy:

这很简单:

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

Simply run Capistrano from the root of your project.

简单地从项目的根运行Capistrano。

#2


7  

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

#3


7  

The deploy_via, :copy has been dropped in version 3.

deploy_via:copy在版本3中已经被删除。

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

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

In most cases you should have your code in a online repository like github or bitbucket, and then you just have to set this line in your deploy.rb file:

在大多数情况下,您应该将代码放在像github或bitbucket这样的在线存储库中,然后您只需在部署中设置这一行即可。rb文件:

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

Though if you happen to have a repository on the remote server that you are deploying too, then you would change that line in your deploy.rb file to be this:

尽管如果您碰巧在正在部署的远程服务器上有一个存储库,那么您将在部署中更改这一行。rb文件如下:

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

Keep in mind that the three forward slashes are important since the file:// tells capistrano that you are looking for a file, and the preceding slash is needed to point to a root path which would be something like /home/deploy/bare_repo/my_project.git.

请记住,三个前斜杠是很重要的,因为文件://告诉capistrano您正在寻找一个文件,需要前面的斜杠指向一个根路径,该路径类似于/home/deploy/bare_repo/my_project.git。

#4


5  

I used a combination of @Ariejan and @HungYuHei answers which worked for me.

我使用了@Ariejan和@HungYuHei答案的组合,这对我很有效。

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

If you use local copy (and don't have the project on Github), then it is also wise to disable :check_revision task in your deploy.rb which checks whether remote is in sync with local git.

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

#5


4  

Capistrano 3 solution which is running for me:

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

Before deploying you are uploading a tar.gz file to the server, unzip and finally reset the :repo_url to file mode.

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

Take care to remove the pervious repo:

注意去除之前的回复:

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

#6


0  

normally deploy via copy is super slow. but copy_cache only available if scm is NOT none (sync uses scm) this means that deploy from working copy can only be done with sluggish copy. I managed to find a fast setup for copy deploy from local repo that is fast. You still need to locally commit changes though but do not need to push them.

通常通过复制部署是非常缓慢的。但是,只有当scm不是none(同步使用scm)时,copy_cache才可用,这意味着从工作副本中部署只能通过缓慢的副本完成。我设法从本地repo找到了一个快速的复制部署设置。您仍然需要在本地提交更改,但不需要推动它们。

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/*"]

Unfortunately it sometimes breaks mysteriously with:

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

fatal: Could not parse object 'c438b9d1242cb311be43d681e3f89bc486d748ed'.`

Ideally syncing local cache should be implemented even if no scm is used for deploy from working copy to work. great feature to add to capistrano

理想的同步本地缓存应该是实现的,即使没有scm用于从工作副本部署到工作。这是capistrano的一大特色。