2017-05-03 114 views
0

我試圖將我們的capistrano2腳本升級到最新的capistrano,但是努力讓它工作。爲了限制轉換的任何問題,我開始了一個空的項目,並做了cap installCapistrano 3.8.1從窗口部署

添加了一個自定義任務以在本機上運行並試用它。同樣的結果。

這是我發現了錯誤:Errno::ENOENT: No such file or directory - /usr/bin/env dir

精確操作的指令:

1)MKDIR capdemo

2)CD capdemo

3)蓋安裝

4 )使用以下內容在lib/capistrano/tasks/foo.rake下創建文件:

namespace :foo do desc "Foo" task :local do run_locally do execute :dir end end end

5)運行cap staging foo:local

我在Windows 10,紅寶石2.2.4和斯特拉努與Capistrano的執行與/usr/bin/env默認前綴3.8.1

```[email protected] MINGW64 ~/inpay_git/capdemo 
$ cap staging foo:local -p --trace 
** Invoke staging (first_time) 
** Execute staging 
** Invoke load:defaults (first_time) 
** Execute load:defaults 
** Invoke foo:local (first_time) 
** Execute foo:local 
Config variable set: :print_config_variables => true 
Config variable set: :stage => :staging 
Config variable set: :scm => :"default-git" 
Config variable set: :branch => "master" 
Config variable set: :deploy_to => #<Proc:[email protected]:/Ruby/224/lib/ruby/gems/2.2.0/gems/capistrano-3.8.1/lib/capistrano/defaults.rb:25 (lambda)> 
Config variable set: :tmp_dir => "/tmp" 
Config variable set: :default_env => {} 
Config variable set: :keep_releases => 5 
Config variable set: :format => :airbrussh 
Config variable set: :log_level => :debug 
Config variable set: :pty => false 
Config variable set: :local_user => #<Proc:[email protected]:/Ruby/224/lib/ruby/gems/2.2.0/gems/capistrano-3.8.1/lib/capistrano/defaults.rb:36 (lambda)> 
Config variable set: :format => :airbrussh 
Config variable set: :git_shallow_clone => false 
Config variable set: :git_wrapper_path => #<Proc:[email protected]:/Ruby/224/lib/ruby/gems/2.2.0/gems/capistrano-3.8.1/lib/capistrano/scm/git.rb:9 (lambda)> 
Config variable set: :git_environmental_variables => #<Proc:[email protected]:/Ruby/224/lib/ruby/gems/2.2.0/gems/capistrano-3.8.1/lib/capistrano/scm/git.rb:15 (lambda)> 
Config variable set: :application => "my_app_name" 
Config variable set: :repo_url => "[email protected]:me/my_repo.git" 
Config variable set: :scm => :git 
00:00 foo:local 
     01 dir 
cap aborted! 
Errno::ENOENT: No such file or directory - /usr/bin/env dir 
C:/Ruby/224/lib/ruby/2.2.0/open3.rb:193:in `spawn' 
C:/Ruby/224/lib/ruby/2.2.0/open3.rb:193:in `popen_run' 
C:/Ruby/224/lib/ruby/2.2.0/open3.rb:93:in `popen3' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/sshkit-1.13.1/lib/sshkit/backends/local.rb:44:in `execute_command' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/sshkit-1.13.1/lib/sshkit/backends/abstract.rb:141:in `block in create_command_and_execute' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/sshkit-1.13.1/lib/sshkit/backends/abstract.rb:141:in `tap' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/sshkit-1.13.1/lib/sshkit/backends/abstract.rb:141:in `create_command_and_execute' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/sshkit-1.13.1/lib/sshkit/backends/abstract.rb:74:in `execute' 
C:/Users/mr/inpay_git/capdemo/lib/capistrano/tasks/foo.rake:5:in `block (3 levels) in <top (required)>' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/sshkit-1.13.1/lib/sshkit/backends/abstract.rb:29:in `instance_exec' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/sshkit-1.13.1/lib/sshkit/backends/abstract.rb:29:in `run' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/capistrano-3.8.1/lib/capistrano/dsl.rb:70:in `run_locally' 
C:/Users/mr/inpay_git/capdemo/lib/capistrano/tasks/foo.rake:4:in `block (2 levels) in <top (required)>' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `call' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in execute' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `each' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/airbrussh-1.2.0/lib/airbrussh/rake/context.rb:62:in `execute' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in invoke_with_call_chain' 
C:/Ruby/224/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:152:in `invoke_task' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block (2 levels) in top_level' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `each' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block in top_level' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:117:in `run_with_threads' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:102:in `top_level' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:80:in `block in run' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:77:in `run' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/capistrano-3.8.1/lib/capistrano/application.rb:14:in `run' 
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/capistrano-3.8.1/bin/cap:3:in `<top (required)>' 
C:/Ruby/224/bin/cap:22:in `load' 
C:/Ruby/224/bin/cap:22:in `<main>' 
Tasks: TOP => foo:local``` 

回答

0

命令運行。如果您的系統上沒有/usr/bin/env,則該命令將失敗。我不熟悉Windows,所以我不知道這是不是一個難以克服的問題。

如果你想刪除/usr/bin/env前綴,你可以修改Capistrano酒店的「命令映射」刪除所有默認行爲:

# In deploy.rb 
# NOT RECOMMENDED 
SSHKit.config.command_map = SSHKit::CommandMap.new({}) 

但是,這將影響到當地遠程命令,這是不可取的。同樣,Capistrano假設你想在本地和遠程環境中以相同的方式運行。

如果這些限制和解決方法過於嚴格,則不必使用run_locally。事實上,無論如何,Capistrano並沒有很好地支持run_locally,並且維護者(包括我自己)discourage using it。相反,您可以使用Ruby的內置方法來運行本地命令,如system或back-ticks。

http://ruby-doc.org/core-2.4.1/Kernel.html#method-i-system

http://ruby-doc.org/core-2.4.1/Kernel.html#method-i-60

+0

好了 - 這樣的「run_locally」方法實際上並不意味着當地有關部署與正在運行的任務 - 在跨平臺環境,或者至少沒有。根據這個反饋,我編寫了我自己的部署策略,使用git archive將最新的頭部從git拉到本地存儲的tarball,並將其上傳到遠程服務器。 –

+0

恭喜!很高興聽到你的工作。 –