簡體   English   中英

Capistrano 3 / SSHKit寫入自定義任務中的文件

[英]Capistrano 3 / SSHKit write to a file in custom task

我想用我的版本號標記當前部署的目錄。

我試過這種方法:

獲取本地應用程序版本,將其存儲到變量中,並在遠程主機上將其存儲在文件中。

namespace :deploy do
  desc "Set a release number as the app version"
  task :mark_release do
    release_number = `git describe`
      on roles(:web) do
        execute("echo #{release_number} > #{current_path}/RELEASE")
      end
    end
  end

問題是,當我通過以下方式運行時:

cap deploy:mark_release

命令看起來像這樣:

echo v9.3.0-254-g178d1f8; > /foo/bar/current/RELEASE

分號正在制造麻煩。 我的RELEASE文件當然是空的。

我認為這是由於SSHKit的一些轉義。

有線索嗎?

我管理它:

1)我從機器上的repo目錄中獲取了版本號

2)我通過上傳用流寫入文件! 方法

namespace :deploy do
 desc "Set a release number as the app version"
 task :mark_release do
   on roles(:web) do
     within "/foo/bar/repo/" do
       upload! StringIO.new(capture(:git, "describe")), "#{current_path}/RELEASE"
     end
   end
 end
end

這是我提出的解決方案,不需要上傳本地文件。 它進入repo路徑執行git命令以解壓縮版本,然后將輸出重定向到文件。 然后,Rails應用程序可以讀取該文件。 執行需要分別傳遞不同的參數。 由於轉義和空白的問題, https://github.com/capistrano/sshkit#the-command-map提供了有關命令映射及其原因的更多信息。

namespace :deploy do
  before :restart, :add_revision_file
  task :add_revision_file do
    on roles(:app) do
      within repo_path do
        execute(:git, :'rev-parse', :'--short', :'HEAD', ">#{release_path}/REVISION")
      end
    end
  end
end

使用SSHKit::Command

SSHKit::Command.new("echo #{release_number} > #{current_path}/RELEASE")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM