From a0658485b28a3c3cdc45f7c3e69220adb28d417c Mon Sep 17 00:00:00 2001 From: Godwin Date: Sun, 23 Jul 2017 08:25:22 -0700 Subject: [PATCH] Fixed prod emails and added deployment tasks --- Rakefile | 62 +++++++++++++++++++++++++++--- config/environments/development.rb | 16 -------- config/environments/preview.rb | 2 +- config/environments/production.rb | 13 ++----- 4 files changed, 61 insertions(+), 32 deletions(-) diff --git a/Rakefile b/Rakefile index 0c21bcb..bf6a490 100644 --- a/Rakefile +++ b/Rakefile @@ -89,11 +89,63 @@ task "cucumber:debug" do ENV['TEST_DEBUG'] = nil end -task deploy: :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 +namespace :deployment do + task pull: :environment do + branch = Rails.env.production? ? :master : :development + `git reset --hard origin/#{branch}` + 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 diff --git a/config/environments/development.rb b/config/environments/development.rb index 178a127..1c74b76 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,7 +1,3 @@ -#require 'perftools' - -#OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE - BikeBike::Application.configure do # 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 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.perform_deliveries = true config.serve_static_files = true - # config.action_controller.perform_caching = true I18n.config.language_detection_method = I18n::Config::DETECT_LANGUAGE_FROM_URL_PARAM diff --git a/config/environments/preview.rb b/config/environments/preview.rb index 365a034..748ef3e 100644 --- a/config/environments/preview.rb +++ b/config/environments/preview.rb @@ -52,7 +52,7 @@ BikeBike::Application.configure do # config.assets.digest = true # 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. # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) diff --git a/config/environments/production.rb b/config/environments/production.rb index 2afbc8f..8f5eab4 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -46,13 +46,10 @@ BikeBike::Application.configure do # Set to :debug to see everything in the log. config.log_level = :info - #config.cache_classes = true - #config.serve_static_assets = true - #config.assets.compile = true - # config.assets.digest = true + config.assets.compile = false # 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. # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) @@ -64,11 +61,7 @@ BikeBike::Application.configure do # config.action_controller.asset_host = "http://assets.example.com" # Precompile additional assets. - # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. - # 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" + config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif *.json *.ttf *.otf *.woff *.woff2 *.svg *.json) # 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.