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 ..
然后像这样简单地设置一个指向当前版本的符号链接
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
这样,在服务器上回滚部署非常容易,因为您只需将符号链接更改回最后(工作)部署,但是每次使用 git clone 有意义时都会创建一个新的完整子目录git pull。
如果您想拥有特定于服务器的文件,则必须将 capistrano 部署任务添加到您的 config/deploy.rb 文件中,以便从 app 目录之外的其他位置(通常是共享子文件夹)复制它。这样做的原因是部署应该是全自动的,并在自动化过程中记录所有必要的步骤,而不是依赖于服务器上手动放置的文件,因为这是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