【问题标题】:My Capistrano does not set the RAILS_ENV variable我的 Capistrano 没有设置 RAILS_ENV 变量
【发布时间】:2014-09-27 12:54:14
【问题描述】:

我的 Capistrano 部署在运行 bundle 命令时没有设置 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=production?

【问题讨论】:

  • 你找到答案了吗?看起来我遇到了同样的问题......
  • 我也有同样的问题。遇到了很多修复,但都没有奏效。

标签: ruby-on-rails capistrano capistrano3


【解决方案1】:

您可以在任务中使用此语法

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

【讨论】:

    【解决方案2】:

    我也有同样的问题。 我运行 rake secret 并得到“NameError:未初始化的常量注释”错误。 在我设置 RAILS_ENV=production 后,它就像魅力一样。 我不知道为什么没有设置 RAILS_ENV 但顺便说一句非常感谢。 节省了我很多时间

    【讨论】:

      猜你喜欢
      • 2014-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      • 2015-12-22
      相关资源
      最近更新 更多