diff --git a/config/deploy-secrets.yml.example b/config/deploy-secrets.yml.example index 696f6ce75..82f739ca8 100644 --- a/config/deploy-secrets.yml.example +++ b/config/deploy-secrets.yml.example @@ -3,18 +3,23 @@ staging: ssh_port: 21 server: staging.participacion.madrid.es user: xxxxx + full_app_name: participacion server_name: staging.participacion.madrid.es db_server: postgre.participacion.madrid.es preproduction: deploy_to: "/var/www/participacion" ssh_port: 2222 - server: xxx.xxx.xxx.xxx + server1: xxx.xxx.xxx.xxx + server2: xxx.xxx.xxx.xxx user: xxxxx + full_app_name: participacion + db_server: xxx.xxx.xxx.xxx production: deploy_to: "/var/www/participacion" ssh_port: 2222 server: xxx.xxx.xxx.xxx user: xxxxx + full_app_name: participacion diff --git a/config/deploy.rb b/config/deploy.rb index 9c45bd283..200561451 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -6,11 +6,14 @@ def deploysecret(key) @deploy_secrets_yml[key.to_s] end + set :rails_env, fetch(:stage) set :rvm_ruby_version, '2.2.2' set :rvm_type, :user set :application, 'participacion' +set :full_app_name, deploysecret(:full_app_name) + set :server_name, deploysecret(:server_name) #set :repo_url, 'git@github.com:AyuntamientoMadrid/participacion.git' # If ssh access is restricted, probably you need to use https access diff --git a/config/deploy/preproduction.rb b/config/deploy/preproduction.rb index 7a18c011d..7f433c493 100644 --- a/config/deploy/preproduction.rb +++ b/config/deploy/preproduction.rb @@ -6,4 +6,5 @@ set :ssh_options, port: deploysecret(:ssh_port) set :stage, :production set :rails_env, :production -server deploysecret(:server), user: deploysecret(:user), roles: %w(web app db importer) +server deploysecret(:server1), user: deploysecret(:user), roles: %w(web app db importer) +server deploysecret(:server2), user: deploysecret(:user), roles: %w(web app db importer) diff --git a/config/environments/production.rb b/config/environments/production.rb index 5c1b32e48..2b85ff8fb 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,3 +1,8 @@ +def deploysecret(key) + @deploy_secrets_yml ||= YAML.load_file('config/deploy-secrets.yml')['production'] + @deploy_secrets_yml[key.to_s] +end + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -42,7 +47,7 @@ Rails.application.configure do # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - # config.force_ssl = true + config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. @@ -62,7 +67,8 @@ Rails.application.configure do # 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 + config.action_mailer.raise_delivery_errors = true + config.action_mailer.default_url_options = { host: deploysecret(:server_name) } # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 5c1b32e48..d8a33ad35 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -1,3 +1,8 @@ +def deploysecret(key) + @deploy_secrets_yml ||= YAML.load_file('config/deploy-secrets.yml')['staging'] + @deploy_secrets_yml[key.to_s] +end + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -42,7 +47,7 @@ Rails.application.configure do # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - # config.force_ssl = true + config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. @@ -62,7 +67,8 @@ Rails.application.configure do # 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 + config.action_mailer.raise_delivery_errors = true + config.action_mailer.default_url_options = { host: deploysecret(:server_name) } # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). diff --git a/lib/capistrano/tasks/restart.cap b/lib/capistrano/tasks/restart.cap index ff8c028f0..54c90819a 100644 --- a/lib/capistrano/tasks/restart.cap +++ b/lib/capistrano/tasks/restart.cap @@ -3,7 +3,7 @@ namespace :deploy do %w(start stop force-stop restart upgrade reopen-logs).each do |command| task command.to_sym do on roles(:app), in: :sequence, wait: 5 do - sudo "/etc/init.d/unicorn_#{fetch(:full_app_name)} #{command}" + execute "/etc/init.d/unicorn_#{fetch(:full_app_name)} #{command}" end end end