Browse Source

Fixed prod emails and added deployment tasks

development
Godwin 7 years ago
parent
commit
a0658485b2
  1. 62
      Rakefile
  2. 16
      config/environments/development.rb
  3. 2
      config/environments/preview.rb
  4. 13
      config/environments/production.rb

62
Rakefile

@ -89,11 +89,63 @@ task "cucumber:debug" do
ENV['TEST_DEBUG'] = nil ENV['TEST_DEBUG'] = nil
end end
task deploy: :environment do namespace :deployment do
if Rails.env.preview? || Rails.env.production? task pull: :environment do
UserMailer.delay(queue: Rails.env.to_s).server_startup(Rails.env.to_s) branch = Rails.env.production? ? :master : :development
else `git reset --hard origin/#{branch}`
UserMailer.server_startup(Rails.env.to_s).deliver_now raise "\nPull failed" $?.exitstatus > 0
changed = !(`git pull` =~ /Already up to date/)
raise "\nPull failed" $?.exitstatus > 0
`bundle install --no-deployment && bundle update bundle install --deployment`
raise "\nPull failed" $?.exitstatus > 0
end
task update: :environment do
tasks = [
'lingua_franca:import',
'bumbleberry:update',
'assets:clean',
'assets:precompile',
'routes',
'db:migrate'
]
cmd = tasks.map { |t| "RAILS_ENV=#{Rails.env} bundle exec #{t}"}.join(' && ')
`#{cmd}`
raise "\nUpdate failed" $?.exitstatus > 0
end
task bounce: :environment do
dir = Rails.env.production? ? :rails : Rails.env
pid = `cat /home/unicorn/#{Rails.env}.pid`
sk_pid = `cat /home/unicorn/sidekiq_#{Rails.env}.pid`
sk_processes = Rails.env.production? ? 25 : 5
system("kill #{pid}")
`bundle exec unicorn_rails -E #{Rails.env} -D -c /home/#{dir}/config/unicorn.rb`
system("kill #{sk_pid}")
`bundle exec sidekiq -d -C config/sidekiq_#{Rails.env}.yml -e #{Rails.env} -c #{sk_processes}`
end
# send an email to admins once deployment is complete
task complete: :environment do
if Rails.env.preview? || Rails.env.production?
UserMailer.delay(queue: Rails.env.to_s).server_startup(Rails.env.to_s)
else
UserMailer.server_startup(Rails.env.to_s).deliver_now
end
end
task db: :start do
[
:pull,
:update,
:bounce,
:complete
].each do |t|
Rake::Task["deployment:#{t}"].execute
end
end end
end end

16
config/environments/development.rb

@ -1,7 +1,3 @@
#require 'perftools'
#OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
BikeBike::Application.configure do BikeBike::Application.configure do
# Settings specified here will take precedence over those in config/application.rb. # Settings specified here will take precedence over those in config/application.rb.
@ -36,22 +32,10 @@ BikeBike::Application.configure do
# to deliver to the browser instead of email # to deliver to the browser instead of email
config.action_mailer.delivery_method = :letter_opener config.action_mailer.delivery_method = :letter_opener
# config.action_mailer.delivery_method = :smtp
# config.action_mailer.smtp_settings = {
# address: 'smtp.gmail.com',
# domain: 'bikebike.org',
# port: 587,
# authentication: :plain,
# enable_starttls_auto: true,
# openssl_verify_mode: 'none',
# user_name: 'info@bikebike.org',
# password: 'Toronto@)!)'
# }
config.action_mailer.raise_delivery_errors = true config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true config.action_mailer.perform_deliveries = true
config.serve_static_files = true config.serve_static_files = true
# config.action_controller.perform_caching = true
I18n.config.language_detection_method = I18n::Config::DETECT_LANGUAGE_FROM_URL_PARAM I18n.config.language_detection_method = I18n::Config::DETECT_LANGUAGE_FROM_URL_PARAM

2
config/environments/preview.rb

@ -52,7 +52,7 @@ BikeBike::Application.configure do
# config.assets.digest = true # config.assets.digest = true
# Prepend all log lines with the following tags. # Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ] config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups. # Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

13
config/environments/production.rb

@ -46,13 +46,10 @@ BikeBike::Application.configure do
# Set to :debug to see everything in the log. # Set to :debug to see everything in the log.
config.log_level = :info config.log_level = :info
#config.cache_classes = true config.assets.compile = false
#config.serve_static_assets = true
#config.assets.compile = true
# config.assets.digest = true
# Prepend all log lines with the following tags. # Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ] config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups. # Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
@ -64,11 +61,7 @@ BikeBike::Application.configure do
# config.action_controller.asset_host = "http://assets.example.com" # config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets. # Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif *.json *.ttf *.otf *.woff *.woff2 *.svg *.json)
# config.assets.precompile += %w( search.js )
#config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif *.svg)
#config.action_controller.asset_host = "https://cdn.bikebike.org"
# Ignore bad email addresses and do not raise email delivery errors. # 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. # Set this to true and configure the email server for immediate delivery to raise delivery errors.

Loading…
Cancel
Save