【问题标题】:Why is capistrano using git clone always为什么 capistrano 总是使用 git clone
【发布时间】:2012-07-28 03:17:56
【问题描述】:

我在 capistrano 部署方面遇到了一些基本问题。首先,当 git repo 已经存在时,我需要知道 capistrano 是否使用 git clone 甚至是第二个或第三个。如果它使用git pull 有什么问题吗?我在我的 capfile 中添加了set :deploy_via, :remote_cache。我问这个是因为我尝试在服务器的路径中添加一个新文件,而不是在 git repo 中,因为它是服务器特定的文件。下次我使用 capistrano 进行部署时,该文件消失了。即使已经创建了 git repo,capistrano 似乎也在使用 git clone。为什么capistrano不能使用git pull更新代码?

【问题讨论】:

    标签: ruby-on-rails git capistrano


    【解决方案1】:

    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
    

    【讨论】:

    • 谢谢..这完全有道理。
    • 现在我知道如何正确处理这些服务器特定文件了:)
    猜你喜欢
    • 1970-01-01
    • 2013-09-03
    • 2014-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    • 2015-05-06
    • 1970-01-01
    相关资源
    最近更新 更多