gpt4 book ai didi

ruby-on-rails - 为什么 capistrano 总是使用 git clone

转载 作者:太空狗 更新时间:2023-10-29 13:53:52 25 4
gpt4 key购买 nike

我有一些关于 Capistrano 部署的基本问题。首先,我需要知道当 git 存储库已经存在时,capistrano 是否正在使用 git clone 甚至是第二个或第三个。使用git pull有什么问题吗?我在我的 capfile 中添加了 set :deploy_via, :remote_cache。我问这个是因为我尝试在服务器的路径中添加一个新文件,而不是在 git repo 中添加一个新文件,因为它是一个特定于服务器的文件。下次我使用 capistrano 部署时,文件消失了。看起来 capistrano 正在使用 git clone 即使已经创建了 git repo。为什么 capistrano 不能使用 git pull 来更新代码?

最佳答案

像这样,Capistrano 在 realeases 中为每个版本创建一个新的子目录

horse:releases xxx$ ls -lart
total 0
drwxrwxr-x 22 xxx staff 748 Jun 26 20:08 20120626180809
drwxrwxr-x 22 xxx staff 748 Jun 26 20:11 20120626181103
drwxrwxr-x 22 xxx staff 748 Jun 26 20:29 20120626182908
drwxrwxr-x 22 xxx staff 748 Jun 26 20:34 20120626183442
drwxrwxr-x 22 xxx staff 748 Jun 26 20:35 20120626183525
drwxrwxr-x 8 xxx staff 272 Jun 27 13:11 .
drwxrwxr-x 22 xxx staff 748 Jun 27 13:11 20120627111102
drwxrwxr-x 5 xxx staff 170 Jun 27 13:11 ..

然后像这样简单地设置一个指向当前版本的符号链接(symbolic link)

horse:deployed xxx$ ls -lart
total 8
drwxrwxr-x 4 xxx staff 136 Jun 26 19:51 ..
drwxrwxr-x 7 xxx staff 238 Jun 26 20:22 shared
drwxrwxr-x 8 xxx staff 272 Jun 27 13:11 releases
lrwxrwxr-x 1 xxx staff 70 Jun 27 13:11 current -> /Users/xxx/RailsDeployment/server/deployed/releases/20120627111102

这样,服务器上部署的回滚非常容易,因为您只需将符号链接(symbolic link)更改回上次(工作)部署,但每次使用 git clone 时都会创建一个新的完整子目录git pull.

如果你想要特定于服务器的文件,你必须将 capistrano 部署任务添加到你的 config/deploy.rb 文件中,以便从应用程序目录(通常是共享子文件夹)之外的其他地方复制它。这样做的原因是部署应该是全自动的,并在自动化过程中记录所有必要的步骤,而不依赖于手动放置在服务器上的文件,因为这是 snowflake server 的第一步。 .因此,如果您需要一个不属于您的 git 存储库的文件,例如通常包含生产密码的文件,您需要更改 config/deploy.rb 以将此文件复制到您需要的位置。要了解如何执行此操作,请查看我的 deploy.rb 中的 copy_db_credentials 任务:

namespace :deploy do
desc "cause Passenger to initiate a restart"
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
desc "Copies database credentials"
task :copy_db_credentials do
run "cp #{shared_path}/credentials/database.yml #{current_path}/config/database.yml"
end

desc "reload the database with seed data"
task :seed do
run "cd #{current_path}; rake db:seed RAILS_ENV=#{rails_env}"
end
end
after :deploy, "deploy:copy_db_credentials"
after "deploy:update_code", :bundle_install
desc "install the necessary prerequisites"
task :bundle_install, :roles => :app do
run "cd #{release_path} && bundle install"
end

关于ruby-on-rails - 为什么 capistrano 总是使用 git clone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11697972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com