2014-09-27 65 views
1

运行bundle命令时,我的Capistrano部署未设置RAILS_ENV变量。我不明白为什么。My Capistrano未设置RAILS_ENV变量

我的Gemfile是:

source 'https://rubygems.org' 

ruby '2.1.3' 

gem 'capistrano', '~> 3.2.1' 
gem 'capistrano-rails', '~> 1.1.1' 

我deploy.rb:

set :stage, :production 
set :rails_env, 'production' 

set :bundle_flags, '--deployment' 
set :bundle_env_variables, { rails_env: "production" } 

namespace :sphinx do 
    desc "Index Sphinx" 
    task :index do 
    on roles(:app) do 
     within release_path do 
     execute :rake, "rake ts:index" 
    end 
    end 
end 

当运行:

➜ ansible-sharetribe git:(master) ✗ bin/cap production sphinx:index --trace 
** Invoke production (first_time) 
** Execute production 
** Invoke load:defaults (first_time) 
** Execute load:defaults 
** Invoke bundler:map_bins (first_time) 
** Execute bundler:map_bins 
** Invoke deploy:set_rails_env (first_time) 
** Execute deploy:set_rails_env 
** Invoke deploy:set_rails_env 
** Invoke sphinx:index (first_time) 
** Execute sphinx:index 
INFO[3ca70ab5] Running bundle exec rake rake ts:index on www.myapplication.com 
cap aborted! 
SSHKit::Runner::ExecuteError: Exception while executing on host www.myapplication.com: rake exit status: 1 
rake stdout: Nothing written 
rake stderr: Digest::Digest is deprecated; use Digest 
rake aborted! 
NameError: uninitialized constant Annotate 

如果我写:

execute :rake, "rake ts:index RAILS_ENV=production" 

它的工作原理。为什么RAILS_ENV =生产不会自动设置?

+0

您是否找到答案?看起来像我面临同样的问题... – KIR 2016-09-22 13:40:57

+0

我有同样的问题。穿越了很多修补程序,但都没有工作。 – codenoob 2017-02-14 00:38:05

回答

1

你可以使用这个语法在任务

execute :rake, "rake ts:index", "RAILS_ENV=#{fetch :rails_env}" 
1

我有同样的问题。 我跑耙秘密,并得到“NameError:未初始化常量注释”错误。 我设置RAILS_ENV =生产后,它的工作就像魅力。 我不知道为什么RAILS_ENV没有设置,但BTW非常感谢。 为我节省了很多时间