Trying to run cap deploy:check I get this error:
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host #<SSHKit::Host:0x007fc04888dcf8>: undefined local variable or method `rubber_env' for #<SSHKit::Backend::Netssh:0x007fc04888d050>
NameError: undefined local variable or method `rubber_env' for #<SSHKit::Backend::Netssh:0x007fc04888d050>
(See full trace by running task with --trace)
Capfile
gemfile = File.expand_path(File.join(__FILE__, '..', 'Gemfile'))
if File.exist?(gemfile) && ENV['BUNDLE_GEMFILE'].nil?
puts "Respawning with 'bundle exec'"
exec("bundle", "exec", "cap", *ARGV)
end
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
env = ENV['RUBBER_ENV'] ||= (ENV['RAILS_ENV'] || 'production')
root = File.dirname(__FILE__)
# this tries first as a rails plugin then as a gem
$:.unshift "#{root}/vendor/plugins/rubber/lib/"
require 'rubber'
Rubber::initialize(root, env)
require 'capistrano'
require 'capistrano-passenger'
require 'bundler'
require 'rails'
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy.rb'
I think I fixed the problem by putting set :rubber_env in deploy.rb, but now I get this error
cap aborted!
ArgumentError: wrong number of arguments (1 for 2)
/Users/user1/app1/Capfile:24:in `load'
/Users/user1/app1/Capfile:24:in `<top (required)>'
Related
Every time I execute bundle exec rake db:create I'm always getting this error in the terminal:
rake aborted!
LoadError: cannot load such file -- /Users/davidnoldner/Documents/GitHub/RatatamBot/rakefile/User/Documents/RatatamBot
/Users/davidnoldner/Documents/GitHub/RatatamBot/rakefile:1:in `require'
/Users/davidnoldner/Documents/GitHub/RatatamBot/rakefile:1:in `<top (required)>'
/Users/davidnoldner/.rvm/gems/ruby-head/gems/rake-12.3.1/exe/rake:27:in `<top (required)>'
/Users/davidnoldner/.rvm/gems/ruby-head/bin/ruby_executable_hooks:24:in `eval'
/Users/davidnoldner/.rvm/gems/ruby-head/bin/ruby_executable_hooks:24:in `<main>'
(See full trace by running task with --trace)
I've been stuck at this since yesterday and was looking for the answer often here on Stackoverflow but didn't find any solution matching to my problem. That's kinda frustrating. I really need your help.
Rakefile:
require File.expand_path('/Users/davidnoldner/Documents/GitHub/RatatamBot/rakefile', __FILE__)
require 'rake'
require 'resque/tasks'
+ # temp fix for NoMethodError: undefined method `last_comment'
+ # remove when fixed in Rake 11.x
+ module TempFixForRakeLastComment
+ def last_comment
+ last_description
+ end
+ end
+ Rake::Application.send :include, TempFixForRakeLastComment
+ ### end of temfix
+
task "resque:preload" => :environment
Rails.application.load_tasks
When I try to run rake db:migrate I am getting following error:
DEPRECATION WARNING: The factory_girl gem is deprecated. Please upgrade to factory_bot. See https://github.com/thoughtbot/factory_bot/blob/v4.9.0/UPGRADE_FROM_FACTORY_GIRL.md for further instructions. (called from <top (required)> at /var/www/html/sophy_web/config/application.rb:14)
/root/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/actionpack-4.2.8/lib/action_dispatch/http/mime_type.rb:163: warning: already initialized constant Mime::PDF
/root/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/actionpack-4.2.8/lib/action_dispatch/http/mime_type.rb:163: warning: previous definition of PDF was here
rake aborted!
NoMethodError: undefined method `>' for nil:NilClass
/var/www/html/application/config/initializers/rollbar.rb:2:in `<top (required)>'
/var/www/html/application/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
I am using ruby version 2.5.1 and rails 4.2.8.
Code of my rollbar.rb:
require 'rollbar/rails'
Rollbar.configure do |config|
config.access_token = '9234902384023843203fsd23'
# Here we'll disable in 'test':
if Rails.env.test?
config.enabled = false
end
end
Code of my environment.rb
# Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
Rails.application.initialize!
I have been deploying rails 4.1 application with capistrano 3. it has been working fine. but
when i tried to do rake tasks (uncommenting require 'capistrano/rails/assets'). i get this error
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host xxx.xxx.xxx.xxx: rake exit status: 1
rake stdout: Nothing written
rake stderr: config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
* development - set it to false
* test - set it to false (unless you use a tool that preloads your test environment)
* production - set it to true
rake aborted!
ArgumentError: Missing required arguments: google_storage_access_key_id, google_storage_secret_access_key
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/core/service.rb:237:in `validate_options'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/core/service.rb:261:in `handle_settings'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/core/service.rb:98:in `new'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/storage.rb:26:in `new'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:83:in `eager_load_fog'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:96:in `fog_credentials='
/home/deploy/yelo/releases/20140910131617/config/initializers/carrierwave.rb:8:in `block in <top (required)>'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:118:in `configure'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/carrierwave-0.10.0/lib/carrierwave.rb:14:in `configure'
/home/deploy/yelo/releases/20140910131617/config/initializers/carrierwave.rb:5:in `<top (required)>'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `load'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `block in load'
the config.eager_load is set to true. the thing with google_storage_access_key_id the keys are initialized inside a initializer with values config.secrets.yml
require 'fog'
require 'rails'
require 'carrierwave'
CarrierWave.configure do |config|
config.root = Rails.root.join('tmp')
config.cache_dir = 'carrierwave'
config.fog_credentials = {
:provider => 'Google',
:google_storage_access_key_id => Rails.application.secrets.storage_access_key,
:google_storage_secret_access_key => Rails.application.secrets.storage_access_secret
}
config.fog_directory = 'yelostore'
end
config.secrets.yml
storage_access_key: <%= ENV['STORAGE_ACCESS_KEY']%>
storage_access_secret: <%= ENV['STORAGE_ACCESS_SECRET']%>
i stored my environmental variables in /etc/profile.
there issues arise only if i do some rake or execute tasks.
if i removed the initializer file i get another error
Devise.secret_key was not set. Please add the following to your Devise initializer:
config.secret_key = '6b88a299ed1361b5c0275e.....'
this is essentiall because of secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> not getting loaded at that point.
Finally i can run all tasks i go to the root path. only while doing it through capistarno these errors arise. as capistarno not getting the config.scecrets env variables which is stored in /etc/profile
capistrano seems like to look into environmental variables from /etc/environment rather than shell so bashrc or profile didnt't work.
The config.eager_load issue was solved after i upgraded to capistrano 3.0rc to 3.2
The Error has nothing to do with the secret_key_base.
In the file config/initializers/devise.rb add the config.secret_key='6b88...' within the setup block:
Devise.setup do |config|
config.secret_key = '6b88a299ed1361b5c0275e...'
...
end
I'm using Rails 4.1 and Ruby 2.0.0. I'm trying to set up testing with minitest-rails and I'm running into this strange error. When I include:
require 'minitest/spec'
In my 'spec_helper' file it give me a NameError: uninitialized constant Minitest::VERSION error. When I comment out this line, everything seems to work fine. The odd thing is that 'minitest/autorun' is also in there and not causing any problems. Maybe you guys can shed some light on what's going on here.
spec_helper.rb:
ENV["RAILS_ENV"] ||= "test"
require File.expand_path('../../config/environment', __FILE__)
require 'minitest/spec'
require 'minitest/autorun'
require 'minitest-rails'
require 'minitest-rails-capybara'
Rakefile:
require File.expand_path('../config/application', __FILE__)
Pinteresting::Application.load_tasks
namespace :test do
task :run do
ENV["RACK_ENV"] = "test"
$LOAD_PATH.unshift("lib", "spec")
if ARGV[1]
require_relative ARGV[1]
else
Dir.glob("./spec/**/*_spec.rb").each { |file| require file }
end
end
end
.spec:
require "spec_helper"
describe "Test" do
describe "When two is equal to two" do
it "asserts true" do
assert_equal(2, 2)
end
end
end
Stack trace:
nbp-93-202:pinteresting Frank$ rake test:run
rake aborted!
NameError: uninitialized constant Minitest::VERSION
/usr/local/rvm/gems/ruby-2.0.0-p481/gems/minitest-5.3.4/lib/minitest/unit.rb:22:in `<class:Unit>'
/usr/local/rvm/gems/ruby-2.0.0-p481/gems/minitest-5.3.4/lib/minitest/unit.rb:21:in `<module:Minitest>'
/usr/local/rvm/gems/ruby-2.0.0-p481/gems/minitest-5.3.4/lib/minitest/unit.rb:20:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.0.0-p481/gems/minitest-5.3.4/lib/minitest/spec.rb:1:in `<top (required)>'
/Users/Frank/Desktop/pinteresting/spec/spec_helper.rb:4:in `<top (required)>'
/Users/Frank/Desktop/pinteresting/spec/diagnostic_spec.rb:1:in `<top (required)>'
/Users/Frank/Desktop/pinteresting/Rakefile:12:in `block (3 levels) in <top (required)>'
/Users/Frank/Desktop/pinteresting/Rakefile:12:in `each'
/Users/Frank/Desktop/pinteresting/Rakefile:12:in `block (2 levels) in <top (required)>'
Tasks: TOP => test:run
Interestingly, if try to run or require a file with just the two requires minitest/spec and minitest/autorun the interpreter raises a warning saying that you should require 'minitest/autorun' instead or add "gem 'minitest'" before require 'minitest/autorun', although it doesn't rise the NameErrorto me.
So switching the require statements around (in order to first require minitest/autorun) seems to do the trick. Requiring minitestin the first place seems to do the trick also.
I think you can resolve this warning by making your implementation simpler. In spec/spec_helper.rb:
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require "minitest/rails"
require "minitest/rails/capybara"
You are missing the require for rails/test_help. Did you remove that for a specific reason?
In Rakefile:
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
Rails.application.load_tasks
Rails::TestTask.new("test:spec" => "test:prepare") do |t|
t.pattern = "spec/**/*_spec.rb"
end
Rake::Task["test:run"].enhance ["test:spec"]
And now run either $ rake test:spec to run all your specs, or $ rake test to run all your tests. The reason behind keeping the rake tasks under the test namespace is because this is what Spring keys on to use the running test environment. Spring uses the task namespace, not the directory name.
I have this rake task in a Rails 3.2.11 application in lib/rake/searches.rb:
namespace :searches do
desc "Start background searches"
task :start => :environment do
Rails.logger.info "Starting searches..."
Campaign.all.each do |c|
next unless c.recurring?
Rails.logger.info "Starting searches for campaign '#{c.name}'"
SearchWorker.enqueue(:campaign_id => c.id, :clear => true)
end
end
end
When I run it locally everything goes well. When I run it in production it errors out:
$ bundle exec rake searches:start
rake aborted!
uninitialized constant SearchWorker
/var/apps/web/lib/tasks/searches.rake:9:in `block (3 levels) in <top (required)>'
/var/apps/web/lib/tasks/searches.rake:5:in `block (2 levels) in <top (required)>'
Tasks: TOP => searches:start
(See full trace by running task with --trace)
When I jump into a console session, I can see that the class is correctly auto loaded:
$ bundle exec rails console
Loading production environment (Rails 3.2.11)
irb(main):001:0> SearchWorker
=> SearchWorker
This workers live in app/workers and they are added to the autoload_paths config setting in application.rb:
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
config.autoload_paths += %W(
#{config.root}/custom_scripts
#{config.root}/app/workers
#{config.root}/app/models/filters
)
So I have no clue why the error only occurs in production, and when running from a rake task.
Any ideas?
It seems you have created the rake file with .rb extension
lib/rake/searches.rb
can you try changing it to
lib/rake/searches.rake
That should work
This is due to the production environment in Rails 3.2 not being fully loaded, after the :environment task is complete.
If you explicitly require SearchWorker ie.
require 'app/workers/search_worker'
Within the beginning of the task block, it'll work.
(Why auto-loads isn't doing this for you, I don't know)