【发布时间】:2014-11-01 02:33:54
【问题描述】:
我正在打电话给bundle exec cap staging demo:foo。
demo:foo Cap 任务调用 Rake 任务,打印出 Rails.env。
但是……Rails 任务正在打印“开发”而不是预期的“暂存”。为什么这样做?为什么不使用我传递给cap 的任何环境?
我知道我可以添加with rails_env: staging,但我不想硬编码环境。我希望能够将此 Cap 任务用于多个环境,并且我希望 Rake 使用我告诉 Cap 使用的任何内容。
### CAP TASK
namespace :demo do
desc "run a demo command"
task :foo do
on roles(:app) do
within release_path do
execute 'pwd'
execute :rake, 'grant:foo'
end
end
end
end
### RAKE TASK (called by above cap task)
namespace :grant do
desc "do-nothing demo task"
task :foo do
puts "args: #{ARGV}"
puts "Rails.env: #{Rails.env}"
puts "pwd: #{Dir.pwd}"
end
end
输出:
3404 ~/dev/myblog$ bundle exec cap staging demo:foo
DEBUG[40846cbf] Running /usr/bin/env if test ! -d /home/blog/rails_apps/blog/staging/current; then echo "Directory does not exist '/home/blog/rails_apps/blog/staging/current'" 1>&2; false; fi on 172.245.32.193
DEBUG[40846cbf] Command: if test ! -d /home/blog/rails_apps/blog/staging/current; then echo "Directory does not exist '/home/blog/rails_apps/blog/staging/current'" 1>&2; false; fi
DEBUG[40846cbf] Finished in 0.815 seconds with exit status 0 (successful).
INFO[8615517c] Running /usr/bin/env pwd on 172.245.32.193
DEBUG[8615517c] Command: cd /home/blog/rails_apps/blog/staging/current && /usr/bin/env pwd
DEBUG[8615517c] /home/blog/rails_apps/blog/staging/releases/20141031234442
INFO[8615517c] Finished in 0.230 seconds with exit status 0 (successful).
INFO[1afa8e9e] Running bundle exec rake grant:foo on 172.245.32.193
DEBUG[1afa8e9e] Command: cd /home/blog/rails_apps/blog/staging/current && bundle exec rake grant:foo
DEBUG[1afa8e9e] args: ["grant:foo"]
DEBUG[1afa8e9e] ENV: development <<<<<<<<< WHY IS THIS?
DEBUG[1afa8e9e] pwd: /home/blog/rails_apps/blog/staging/releases/20141031234442
INFO[1afa8e9e] Finished in 1.491 seconds with exit status 0 (successful).
版本:
- capistrano 是 3.2.1
- capistrano-rails 是 1.1.1
【问题讨论】:
标签: rake capistrano3