Rails: развертывание промежуточной среды: Devise Secret Key не был установлен
Прямо сейчас у нашей компании есть рабочая производственная версия нашей компании, размещенная на облаке66. Я прошел и установил все наши переменные среды и довел наш манифест до нюхательного табака. Прямо сейчас, кроме наших ключей API, постановка является точной копией производства. Наш файл production.rb совпадает с файлом sour staging.rb:
#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
Я добавил промежуточные настройки в наш файл манифеста c66, который, опять же, является точной копией производства:
# C66 manifest file
production:
postgresql:
configuration:
version: 9.6.1
postgis: false
staging:
postgresql:
configuration:
version: 9.6.1
postgis: false
Развертывание не удалось, и журналы указывают на 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"
Итак, я смотрю в файле devise.rb и вижу закомментированный код:
# 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.
Я не знаю много об этом куске кода. Я бы предположил, что поскольку все является точной копией производства, это должно быть закомментировано и для нашей промежуточной среды. Я не знаю, что значит раскомментировать config.secret_key
и что это может сделать для нашей производственной среды.
Может кто-нибудь объяснить, почему это работает в производстве, но не в стадии подготовки, которая идентична в остальных настройках?
1 ответ
Я нашел проблему. Я забыл добавить в промежуточную информацию secrets.yml
где secret_key_base установлен.