Add task to move SMTP settings to secrets.yml
Existing installations having their configuration settings in the capistrano shared folder needed this migration. Note we can't just use `YAML.load` because we'd lose the anchors defined in the file. So we have to parse the file the hard way.
This commit is contained in:
@@ -46,6 +46,9 @@ namespace :deploy do
|
|||||||
before "deploy:migrate", "remove_local_census_records_duplicates"
|
before "deploy:migrate", "remove_local_census_records_duplicates"
|
||||||
|
|
||||||
after "deploy:migrate", "add_new_settings"
|
after "deploy:migrate", "add_new_settings"
|
||||||
|
|
||||||
|
before :publishing, "smtp_secrets"
|
||||||
|
|
||||||
after :publishing, "deploy:restart"
|
after :publishing, "deploy:restart"
|
||||||
after :published, "delayed_job:restart"
|
after :published, "delayed_job:restart"
|
||||||
after :published, "refresh_sitemap"
|
after :published, "refresh_sitemap"
|
||||||
@@ -127,3 +130,13 @@ task :setup_puma do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
task :smtp_secrets do
|
||||||
|
on roles(:app) do
|
||||||
|
within release_path do
|
||||||
|
with rails_env: fetch(:rails_env) do
|
||||||
|
execute :rake, "secrets:smtp"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|||||||
23
lib/tasks/secrets.rake
Normal file
23
lib/tasks/secrets.rake
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
namespace :secrets do
|
||||||
|
desc "Add SMTP settings to secrets.yml"
|
||||||
|
task smtp: :environment do
|
||||||
|
exit if Rails.application.secrets.smtp_settings
|
||||||
|
|
||||||
|
current_settings = {
|
||||||
|
"mailer_delivery_method" => ActionMailer::Base.delivery_method.to_s,
|
||||||
|
"smtp_settings" => ActionMailer::Base.smtp_settings.stringify_keys
|
||||||
|
}
|
||||||
|
|
||||||
|
secrets = Rails.application.config.paths["config/secrets"].first
|
||||||
|
stream = Psych.parse_stream(File.read(secrets))
|
||||||
|
nodes = stream.children.first.children.first
|
||||||
|
|
||||||
|
environment_index = nodes.children.index do |child|
|
||||||
|
child.is_a?(Psych::Nodes::Scalar) && child.value == Rails.env
|
||||||
|
end
|
||||||
|
|
||||||
|
nodes.children[environment_index + 1].children.push(*Psych.parse(current_settings.to_yaml).children.first.children)
|
||||||
|
|
||||||
|
File.open(secrets, "w") { |file| file.write stream.to_yaml }
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user