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
Related
On Rails 6 (6.1.4.1) we had a RakeFile that would run a subset of tests. For example:
# lib/tasks/carrier.rake
namespace :test do
task carriers: "test:prepare" do
$: << "test"
test_files = FileList["test/models/carrier_test.rb",
"test/controllers/admin/carriers/**/*_test.rb",
"test/system/admin/carriers/**/*_test.rb"]
Rails::TestUnit::Runner.run(test_files)
end
end
This would execute just fine when called:
rails test:carriers
However, somewhere along the way, something changed and we began seeing errors when trying to run our RakeFile test tasks. (I haven't tracked down exactly what changed and when it changed -- perhaps it was part of the Rails 7 release.) Here's the error we began seeing:
rails aborted!
NameError: uninitialized constant Shoulda
Shoulda::Matchers.configure do |config|
^^^^^^^
/path/test/test_helper.rb:15:in `<main>'
/path/test/models/carrier_test.rb:1:in `<main>'
/path/lib/tasks/carriers.rake:11:in `block (2 levels) in <main>'
Tasks: TOP => test:carriers
(See full trace by running task with --trace)
The error appeared with no changes to our tests or environment configuration. (Running a full rake worked just fine.)
When reviewing the source code for Rails::TestUnit::Runner, I came across rake_run. Simply replacing Rails::TestUnit::Runner.run with Rails::TestUnit::Runner.rake_run addressed the issue (no other changes required):
# lib/tasks/carrier.rake
namespace :test do
task carriers: "test:prepare" do
$: << "test"
test_files = FileList["test/models/carrier_test.rb",
"test/controllers/admin/carriers/**/*_test.rb",
"test/system/admin/carriers/**/*_test.rb"]
Rails::TestUnit::Runner.rake_run(test_files)
end
end
Right now, our company has a working production version of our company hosted on cloud66. I went through and set all of our environment variables and got our manifest up to snuff. Right now, aside from our API keys, staging is an exact replica of production. Our production.rb file is the same as sour staging.rb file:
#staging.rb
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Mailer
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => "587",
:authentication => :plain,
:user_name => 'apikey',
:password => ENV['SENDGRID_API_KEY'],
:domain => ENV['BASE_DOMAIN'],
:enable_starttls_auto => true
}
# Mailer for Devise
config.action_mailer.default_url_options = { host: ENV['FULL_URL'] }
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Mount Action Cable outside main process or domain
# config.action_cable.mount_path = nil
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :debug
# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "gathrly_#{Rails.env}"
config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Use a different logger for distributed setups.
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
end
I added the staging settings to our c66 manifest file, which again, is an exact copy of production:
# C66 manifest file
production:
postgresql:
configuration:
version: 9.6.1
postgis: false
staging:
postgresql:
configuration:
version: 9.6.1
postgis: false
Deployment failed and the logs are pointing to Devise:
#C66 deployment logs
[52.36.55.118] /var/deploy/OurApp/web_head/releases/20170311214608/config/database.yml
[52.36.55.118] done
* sftp upload complete
* executing `deploy:db:create'
* executing "cd /var/deploy/OurApp/web_head/releases/20170311214608 && bundle exec rake RAILS_ENV=staging db:create"
[52.36.55.118] executing command
Database 'OurApp_staging' already exists
command finished in 2328ms
* executing `deploy:db:load_schema'
* executing "cd /var/deploy/OurApp/web_head/releases/20170311214608 && bundle exec rake RAILS_ENV=staging db:schema:load"
[52.36.55.118] executing command
rake aborted!
Devise.secret_key was not set. Please add the following to your Devise initializer:
config.secret_key = **REDACTED**
Please ensure you restarted your application after installing Devise or setting the key.
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/devise-4.2.0/lib/devise/rails/routes.rb:498:in `raise_no_secret_key'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/devise-4.2.0/lib/devise/rails/routes.rb:226:in `devise_for'
/var/deploy/OurApp/web_head/releases/20170311214608/config/routes.rb:5:in `block in '
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/route_set.rb:389:in `instance_exec'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/route_set.rb:389:in `eval_block'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/route_set.rb:371:in `draw'
/var/deploy/OurApp/web_head/releases/20170311214608/config/routes.rb:1:in `'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_reloader.rb:40:in `each'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_reloader.rb:40:in `load_paths'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_reloader.rb:16:in `reload!'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_r
eloader.rb:26:in `block in updater'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/file_update_checker.rb:77:in `execute'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_reloader.rb:27:in `updater'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application/finisher.rb:119:in `block in '
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in `instance_exec'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in `run'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:55:in `block in run_initializers'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:54:in `run_initializers'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:352:in `initialize!'
/var/deploy/OurApp/web_head/releases/20170311214608/config/environment.rb:5:in `'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:328:in `require_environment!'
/var/deploy/OurApp/web_head/shared/bundle/ru
by/2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:448:in `block in run_tasks_blocks'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/rake-11.3.0/exe/rake:27:in `'
/usr/local/bin/bundle:22:in `load'
/usr/local/bin/bundle:22:in `'
Tasks: TOP => db:schema:load => environment
(See full trace by running task with --trace)
command finished in 2584ms
*** [deploy:update_code] rolling back
* executing "rm -rf /var/deploy/OurApp/web_head/releases/20170311214608; true"
[52.36.55.118] executing command
command finished in 286ms
failed: ". /var/.cloud66_env 2>/dev/null || true && unset BUNDLE_GEMFILE && sh -c 'cd /var/deploy/OurApp/web_head/releases/20170311214608 && bundle exec rake RAILS_ENV=**REDACTED** db:schema:load'" on 52.36.55.118
21:47:27 – Deployment failed: Failed to setup the deployment on the server during "cap deploy"
So, I'm looking in the devise.rb file and I see this commented out code:
# The secret key used by Devise. Devise uses this key to generate
# random tokens. Changing this key will render invalid all existing
# confirmation, reset password and unlock tokens in the database.
# Devise will use the `secret_key_base` as its `secret_key`
# by default. You can change it below and use your own secret key.
# config.secret_key = 'somekey' # Real key removed for security.
I don't know much about this chunk of code. I would assume since everything is an exact replica of production that this should stay commented out for our staging environment as well. I don't know the implications of uncommenting out the config.secret_key and what that might do to our production environment.
Can someone explain why this works in production but is failing in staging which is identical in the rest of the settings?
I found the issue. I forgot to add in staging information to secrets.yml where the secret_key_base is set.
Newbie here trying to create a development environment for a project. I've installed MySQL and Ruby on Rails on my device already. However, I'm running into the below error message when trying to run the 3 commands below after "bundle install" runs successfully. Any ideas?
bundle exec rake db:setup RAILS_ENV="development"
bundle exec rake db:migrate RAILS_ENV="development"
bundle exec rake db:seed RAILS_ENV=“development"
error message is as follows:
wcai-projects already exists
rake aborted!
uninitialized constant Settings
EDIT-here's the console log:
$ bundle exec rake db:setup RAILS_ENV=development
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-3.2.12/lib/active_support/values/time_zone.rb:270: warning: circular argument reference - now
wcai-projects already exists
rake aborted!
uninitialized constant Settings
/wcai-web/config/initializers/carrier_wave.rb:4:in `block in <top (required)>'
/wcai-web/config/initializers/carrier_wave.rb:1:in `<top (required)>'
/wcai-web/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:setup => db:schema:load_if_ruby => environment
(See full trace by running task with --trace)
EDIT-contents of config/initializers/carrier_wave.rb:
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => Settings.aws_access_key, # required
:aws_secret_access_key => Settings.aws_secret_key # required
# :region => 'eu-west-1' # optional, defaults to 'us-east-1'
}
config.fog_directory = Settings.aws_bucket # required
config.fog_public = false
config.fog_authenticated_url_expiration = 120
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {}
#config.asset_host = 'https://assets.example.com' # optional, defaults to nil
end
Update your Rails version in Gemfile to 4.2.4. Then type bundle update rails and try again.
I updated a Rails 2.3 app to 3.2 and it seemed to be a pretty simple process but when setting up the Figaro gem I came across this error:
C:\Sites\JustManage>rails generate figaro:install
C:/Sites/JustManage/config/environment.rb:5:in `<top (required)>': uninitialized
constant Projectmanagement (NameError)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
/lib/rails/application.rb:103:in `require_environment!'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
/lib/rails/commands.rb:25:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Here is what my environment.rb looks like:
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Projectmanagement::Application.initialize!
Here is my application.rb file:
require File.expand_path('../application', __FILE__)
require 'rails/all'
if defined?(Bundler)
Bundler.require(*Rails.groups(:assets => %w(development test)))
end
module Railsapp
class Application < Rails::Application
config.encoding = "utf-8"
config.filter_parameters += [
:password,
:password_clear,
:password_verify
]
config.assets.enabled = true
config.assets.version = '1.0'
end
end
I've never run into this error before and don't know why it's happening.
It seems like the name of your application is not the same in the different places it needs to appear in. Check the following files and see if they contain either Projectmanagement::Application or Railsapp::Application:
config/application.rb (Actually initializes the constant)
config/environment.rb
config/environments/development.rb
config/environments/production.rb
config/environments/test.rb
config/initializers/secret_token.rb
config/initializers/session_store.rb
config/mongoid.yml (if using Mongoid)
config/routes.rb
config.ru
Rakefile
app/views/layouts/application.html.erb, in title tag
Then pick a name (either Projectmanagement or Railsapp) and change all the names in the above files so they match. That should resolve the uninitialized constant error you are having.
I can't be certain that they are not errors from copy/pasting, but your application.rb appears to be incorrect. Issues I see:
L1: You are requiring application.rb a second time where you mean to be requiring boot.rb.
L12: The name of this module (i.e. the name of your app) is not consistent here with what is in your environment.rb file (Railsapp vs. Projectmanagement).
The second issue is actually causing the error you are seeing - you have not defined the Projectmanagement constant before calling a method on it.
I used the following guide: http://www.tweetegy.com/2012/10/setting-up-a-captcha-with-recaptcha-service-and-the-captcha-gem/
I have the following in development.rb:
ENV['RECAPTCHA_PUBLIC_KEY'] = 'keyString'
ENV['RECAPTCHA_PRIVATE_KEY'] = 'keyString'
In config/initializers/recaptcha.rb:
Recaptcha.configure do |config|
config.public_key = RECAPTCHA_PUBLIC_KEY
config.private_key = RECAPTCHA_PRIVATE_KEY
end
I get the following error when I run rails server in development:
Exiting
/home/action/visualhaggard.org/config/initializers/recaptcha.rb:2:in `block in <top (required)>': uninitialized constant RECAPTCHA_PUBLIC_KEY (Nam
eError)
Has anyone encountered and solved this problem? Do I have a typo? Thanks.
The example doesn't define the RECAPTCHA_PUBLIC_KEY in an environment variable. It just defines it as a constant.
#put this in development.rb and in production.rb (separate keys in each so you can test!)
RECAPTCHA_PUBLIC_KEY= 'your-public-key'
RECAPTCHA_PRIVATE_KEY= 'your-private-key'