【问题标题】:How to write out the deployed git revision to a file in Capistrano如何将已部署的 git 修订版写入 Capistrano 中的文件
【发布时间】:2012-09-07 19:57:47
【问题描述】:

我使用 Capistrano 部署我的 rails 应用程序。如何写出部署到 public_html/revision.txt 的 git 修订版?

【问题讨论】:

    标签: git capistrano


    【解决方案1】:

    如果其他人必须这样做:

        namespace :deploy do
          # ...
    
          desc "Write the current version to public_html/revision.txt"
          task :write_revision, :except => { :no_release => true } do
            run "cd #{latest_release}; git rev-parse HEAD > #{latest_release}/public/revision.txt"
          end
    
          # ...
        end
    
        after "deploy:update_code", "deploy:write_revision"
    

    【讨论】:

      【解决方案2】:

      我将此添加到我的 deploy.rb:

      execute "git rev-parse --abbrev-ref HEAD > public/revision.txt"
      execute `"git log --oneline -1 >> public/revision.txt"`
      

      然后在我的内部管理页面中:

      File.read("#{Rails.root}/public/revision.txt")
      

      如果需要,您可以放入 Rails.root 而不是 public。

      【讨论】:

        【解决方案3】:

        这可能是在提出原始问题后添加的一项新功能,但 Capistrano 已经在应用根目录中创建了一个 REVISION 文件。你可以把这个复制过来。这是我所拥有的:

              desc "Write the current version to public/revision.txt"
              task :write_revision do
                on roles(:app, :api) do
                  execute :cp, "#{fetch(:release_path)}/REVISION #{fetch(:release_path)}/public/revision.txt"
                end
              end
              after "deploy:finished", "deploy:write_revision"
        

        【讨论】:

          【解决方案4】:

          您可以使用 log 命令获取最新的提交 ID,然后将其重定向到您的文件:

          git --no-pager log -1 --pretty=format:%H > public_html/revision.txt
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2011-07-31
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2010-11-24
            • 1970-01-01
            相关资源
            最近更新 更多