diff --git a/Capfile b/Capfile index 9ef566ef3..1b5ebcf34 100644 --- a/Capfile +++ b/Capfile @@ -14,9 +14,9 @@ require 'capistrano/deploy' # https://github.com/capistrano/bundler # https://github.com/capistrano/rails # -require 'capistrano/rbenv' +#require 'capistrano/rbenv' require 'capistrano/bundler' -require 'capistrano/npm' +#require 'capistrano/npm' require 'capistrano/rails/assets' require 'capistrano/rails/migrations' require 'capistrano/deploytags' diff --git a/Gemfile.lock b/Gemfile.lock index 02665eea6..73ca10c8e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -79,6 +79,8 @@ GEM airbrake (4.3.6) builder multi_json + airbrussh (1.1.0) + sshkit (>= 1.6.1, != 1.7.0) apipie-rails (0.3.6) json arbre (1.0.3) @@ -112,15 +114,18 @@ GEM cacheable_flash (0.3.4) json stackable_flash (>= 0.0.7) - capistrano (3.4.0) + capistrano (3.6.1) + airbrussh (>= 1.0.0) + capistrano-harrow i18n rake (>= 10.0.0) - sshkit (~> 1.3) + sshkit (>= 1.9.0) capistrano-bundler (1.1.4) capistrano (~> 3.1) sshkit (~> 1.2) capistrano-deploytags (1.0.4) capistrano (>= 3.2.0) + capistrano-harrow (0.5.3) capistrano-npm (1.0.1) capistrano (>= 3.0.0) capistrano-rails (1.1.6) @@ -342,7 +347,7 @@ GEM nenv (0.3.0) net-scp (1.2.1) net-ssh (>= 2.6.5) - net-ssh (3.0.2) + net-ssh (3.2.0) newrelic_rpm (3.15.0.314) nokogiri (1.6.7.2) mini_portile2 (~> 2.0.0.rc2) @@ -504,7 +509,7 @@ GEM actionpack (>= 3.0) activesupport (>= 3.0) sprockets (>= 2.8, < 4.0) - sshkit (1.9.0) + sshkit (1.11.2) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) stackable_flash (0.0.7) diff --git a/app/assets/stylesheets/relaunch/_container.scss b/app/assets/stylesheets/relaunch/_container.scss index 1b14bebdc..a18abdd10 100644 --- a/app/assets/stylesheets/relaunch/_container.scss +++ b/app/assets/stylesheets/relaunch/_container.scss @@ -1,5 +1,5 @@ #container { - background: url('container_bg.png') repeat-x 0 $headerHeight; + background: asset-url('container_bg.png') repeat-x 0 $headerHeight; display: block; padding-bottom: $footerHeight + 10px; padding-top: $headerHeight; @@ -45,10 +45,10 @@ padding-left: 80px; } p.osm { - background: url("/assets/openstreetmap_logo_small.jpg") no-repeat left center; + background: asset-url("/assets/openstreetmap_logo_small.jpg") no-repeat left center; } p.wheelmap { - background: url("/assets/markerhead.jpg") no-repeat 4px center; + background: asset-url("/assets/markerhead.jpg") no-repeat 4px center; } em { @@ -113,4 +113,4 @@ text-shadow: rgba(255, 255, 255, 0.5), 0, 1px, 1px; } } -} \ No newline at end of file +} diff --git a/app/assets/stylesheets/relaunch/_fonts.scss b/app/assets/stylesheets/relaunch/_fonts.scss index 172dc4ed8..f0172c61a 100644 --- a/app/assets/stylesheets/relaunch/_fonts.scss +++ b/app/assets/stylesheets/relaunch/_fonts.scss @@ -3,6 +3,6 @@ $helvetica_light: 'HelveticaNeue-Light','Helvetica Neue Light','Helvetica Neue', @font-face { font-family: 'EntypoRegular'; - src: url('entypo.eot'); - src: url('entypo.eot?#iefix') format("embedded-opentype"), url('entypo.woff') format("woff"), url('entypo.ttf') format("truetype"), url('entypo.svg#EntypoRegular') format("svg"); + src: asset-url('entypo.eot'); + src: asset-url('entypo.eot?#iefix') format("embedded-opentype"), asset-url('entypo.woff') format("woff"), asset-url('entypo.ttf') format("truetype"), asset-url('entypo.svg#EntypoRegular') format("svg"); } diff --git a/app/assets/stylesheets/relaunch/_footer.scss b/app/assets/stylesheets/relaunch/_footer.scss index bba595422..e0c9e80a1 100644 --- a/app/assets/stylesheets/relaunch/_footer.scss +++ b/app/assets/stylesheets/relaunch/_footer.scss @@ -64,7 +64,7 @@ border-left: 0; padding: 1px 4px; margin-left: 5px; - background: url(/assets/bubble-left.png) no-repeat -5px center; + background: asset-url('/assets/bubble-left.png') no-repeat -5px center; } } diff --git a/app/assets/stylesheets/relaunch/_header.scss b/app/assets/stylesheets/relaunch/_header.scss index 46f7bab87..9b5e7744c 100644 --- a/app/assets/stylesheets/relaunch/_header.scss +++ b/app/assets/stylesheets/relaunch/_header.scss @@ -8,10 +8,10 @@ left: 0; z-index: 2; float: left; - background: url('bg_header.png'); + background: asset-url('bg_header.png'); @include if-min-resolution(1.3) { - background: url(bg_header@2x.png); + background: asset-url('bg_header@2x.png'); } .navbar-inner { @@ -31,10 +31,10 @@ margin: 7px 0 0 0; float: left; position: relative; - background: url(bg_logo.png) center left no-repeat; + background: asset-url('bg_logo.png') center left no-repeat; @include if-min-resolution(1.3) { - background: url(bg_logo@2x.png) center left no-repeat; + background: asset-url('bg_logo@2x.png') center left no-repeat; background-size: 150px 32px; } @@ -61,11 +61,11 @@ .christmas & { width: 160px; height: 42px; - background-image: url(bg_logo_christmas.png); + background-image: asset-url('bg_logo_christmas.png'); margin-top: 0; @include if-min-resolution(1.3) { - background-image: url(bg_logo_christmas@2x.png); + background-image: asset-url('bg_logo_christmas@2x.png'); background-size: 150px 39px; } diff --git a/app/assets/stylesheets/relaunch/_icons.scss b/app/assets/stylesheets/relaunch/_icons.scss index 0571f50c8..ad106597d 100644 --- a/app/assets/stylesheets/relaunch/_icons.scss +++ b/app/assets/stylesheets/relaunch/_icons.scss @@ -8,14 +8,14 @@ } .leaflet-marker-icon { - background: transparent url('marker-sprites.png') no-repeat; + background: transparent asset-url('marker-sprites.png') no-repeat; width: 29px; height: 32px; margin-left: -15px; margin-top: -30px; @include if-min-resolution(1.3) { - background: transparent url('marker-sprites@2x.png') no-repeat; + background: transparent asset-url('marker-sprites@2x.png') no-repeat; background-size: 29px 128px; } @@ -58,4 +58,4 @@ $icons: sprite-map("icons/*[^@2x].png"); max-width: 22px; max-height: 22px; } -} \ No newline at end of file +} diff --git a/app/assets/stylesheets/relaunch/_leaflet_overrides.scss b/app/assets/stylesheets/relaunch/_leaflet_overrides.scss index 9e1028328..6e1c2c409 100644 --- a/app/assets/stylesheets/relaunch/_leaflet_overrides.scss +++ b/app/assets/stylesheets/relaunch/_leaflet_overrides.scss @@ -18,7 +18,7 @@ .leaflet-control-locate { a { - background-image: url('locate_btn.png'); + background-image: asset-url('locate_btn.png'); background-position: center center; background-repeat: no-repeat; background-color: rgba(255,255,255,0.8); @@ -28,18 +28,18 @@ }; @include if-min-resolution(1.3) { - background-image: url('locate_btn@2x.png'); + background-image: asset-url('locate_btn@2x.png'); } } &.requesting a { - background-image: url('spinner_locate.gif'); + background-image: asset-url('spinner_locate.gif'); } &.active a { - background-image: url(locate_btn_active.png); + background-image: asset-url('locate_btn_active.png'); @include if-min-resolution(1.3) { - background-image: url('locate_btn_active@2x.png'); + background-image: asset-url('locate_btn_active@2x.png'); } } } @@ -65,4 +65,4 @@ a { white-space: nowrap; } -} \ No newline at end of file +} diff --git a/app/assets/stylesheets/relaunch/_map.scss b/app/assets/stylesheets/relaunch/_map.scss index a96b3b0db..730468951 100644 --- a/app/assets/stylesheets/relaunch/_map.scss +++ b/app/assets/stylesheets/relaunch/_map.scss @@ -36,9 +36,9 @@ text-indent:-9999px; overflow:hidden; background-repeat:no-repeat; - background-image:url('mapbox_logo.png'); + background-image: asset-url('mapbox_logo.png'); @media screen and (max-width:$breakPhone) { bottom: 13px } -} \ No newline at end of file +} diff --git a/app/assets/stylesheets/relaunch/_overlay.scss b/app/assets/stylesheets/relaunch/_overlay.scss index 4d815a62d..ed6a3192e 100644 --- a/app/assets/stylesheets/relaunch/_overlay.scss +++ b/app/assets/stylesheets/relaunch/_overlay.scss @@ -34,7 +34,7 @@ top: 50%; margin: -325px 0 0 -350px; padding: 0 0 20px 0; - background: url('bg-overlay.png') #FFF no-repeat; + background: asset-url('bg-overlay.png') #FFF no-repeat; background-position: 0 219px; @include box-shadow(0 0 10px #333); @include border-radius(3px); @@ -85,7 +85,7 @@ margin: 0 0 40px 0; text-align: center; - background: url('logo-overlay.png') center top no-repeat; + background: asset-url('logo-overlay.png') center top no-repeat; font-size: 16px; line-height: 24px; @@ -290,4 +290,4 @@ margin-top: 5px; } } -} \ No newline at end of file +} diff --git a/app/assets/stylesheets/relaunch/_toolbar.scss b/app/assets/stylesheets/relaunch/_toolbar.scss index e2c4e51a7..955968cc4 100644 --- a/app/assets/stylesheets/relaunch/_toolbar.scss +++ b/app/assets/stylesheets/relaunch/_toolbar.scss @@ -133,7 +133,7 @@ } &--yes { - background-image: url('toolbar_marker_yes.png'); + background-image: asset-url('toolbar_marker_yes.png'); .popover-title { background-color: $wheelchair-yes; @@ -141,7 +141,7 @@ } &--limited { - background-image: url('toolbar_marker_limited.png'); + background-image: asset-url('toolbar_marker_limited.png'); .popover-title { background-color: $wheelchair-limited; @@ -149,7 +149,7 @@ } &--no { - background-image: url('toolbar_marker_no.png'); + background-image: asset-url('toolbar_marker_no.png'); .popover-title { background-color: $wheelchair-limited; @@ -157,7 +157,7 @@ } &--unknown { - background-image: url('toolbar_marker_unknown.png'); + background-image: asset-url('toolbar_marker_unknown.png'); .popover-title { background-color: $wheelchair-unknown; @@ -166,19 +166,19 @@ @include if-min-resolution(1.3) { &--yes { - background-image: url(toolbar_marker_yes@2x.png); + background-image: asset-url('toolbar_marker_yes@2x.png'); } &--limited { - background-image: url(toolbar_marker_limited@2x.png); + background-image: asset-url('toolbar_marker_limited@2x.png'); } &--no { - background-image: url(toolbar_marker_no@2x.png); + background-image: asset-url('toolbar_marker_no@2x.png'); } &--unknown { - background-image: url(toolbar_marker_unknown@2x.png); + background-image: asset-url('toolbar_marker_unknown@2x.png'); } } } @@ -193,7 +193,7 @@ } &-icon { - background: url('toolbar_marker_icon.png') no-repeat; + background: asset-url('toolbar_marker_icon.png') no-repeat; background-size: 100%; width: image_width('toolbar_marker_icon.png'); height: image_height('toolbar_marker_icon.png'); @@ -201,7 +201,7 @@ margin-top: 1px; // Cosmetic surgery @include if-min-resolution(1.3) { - background-image: url('toolbar_marker_icon@2x.png'); + background-image: asset-url('toolbar_marker_icon@2x.png'); } } @@ -616,4 +616,3 @@ } } } - diff --git a/app/uploaders/photo_uploader.rb b/app/uploaders/photo_uploader.rb index 98622c999..cb22f250c 100644 --- a/app/uploaders/photo_uploader.rb +++ b/app/uploaders/photo_uploader.rb @@ -18,7 +18,9 @@ class PhotoUploader < CarrierWave::Uploader::Base # This is a sensible default for uploaders that are meant to be mounted: def store_dir File.join('system', 'uploads', model.class.to_s.underscore, subdirs) - # File.join('uploads', model.class.to_s.underscore, mounted_as.to_s, subdirs) + end + def cache_dir + File.join('system', 'uploads', 'tmp', model.class.to_s.underscore) end def subdirs diff --git a/config/deploy.rb b/config/deploy.rb index 0595fbb0f..9542eb1a1 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -23,49 +23,104 @@ set :pty, true # Default value for :linked_files is [] -set :linked_files, %w(config/database.yml config/open_street_map.yml config/metrics.yml config/librato.yml config/newrelic.yml .env config/secrets.yml) +set :linked_files, %w{ config/database.yml config/open_street_map.yml config/metrics.yml config/librato.yml config/newrelic.yml .env config/secrets.yml} -# Default value for :bundle_without is %w{development test}.join(' ') -set :bundle_without, %w(development test metrics deployment).join(' ') - -# Default value for :bundle_jobs is: nil +set :bundle_roles, [:app, :worker, :importer] +set :bundle_without, %w{ development test metrics deployment }.join(' ') set :bundle_jobs, 4 +set :bundle_binstubs, -> { shared_path.join('bin') } # Default value for linked_dirs is [] # set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} -set :linked_dirs, %w(log tmp/var tmp/osmosis-working-dir tmp/cache tmp/sockets tmp/pids vendor/bundle public/system public/assets node_modules) - -set :rbenv_type, :system # :user or :system, depends on your rbenv setup -set :rbenv_ruby, '2.2.2' -set :rbenv_custom_path, '/opt/rbenv' - -# Default value for default_env is {} -# set :default_env, { path: "/opt/ruby/bin:$PATH" } +set :linked_dirs, %w{ log tmp vendor/bundle public/system node_modules } # Default value for keep_releases is 5 set :keep_releases, 5 + +# Clear existing task so we can replace it rather than "add" to it. +Rake::Task["deploy:compile_assets"].clear +Rake::Task["deploy:set_linked_dirs"].clear + namespace :deploy do + + task :set_linked_dirs do + # noop due to cap/rails adding this to the run list + # Ref: https://github.com/capistrano/rails/blob/54da36a2dda5084a3cbe380b4a8f1ba282379f72/lib/capistrano/tasks/assets.rake#L121 + end + + desc 'Compile assets' + task :compile_assets => [:set_rails_env] do + # invoke 'deploy:assets:precompile' + invoke 'deploy:assets:precompile_local' + invoke 'deploy:assets:backup_manifest' + end + + namespace :assets do + + desc "Precompile assets locally and then rsync to web servers" + task :precompile_local do + # compile assets locally + run_locally do + execute "RAILS_ENV=#{fetch(:stage)} bundle exec rake assets:precompile" + end + + # rsync to asset server + local_dir = "./public/" + on roles(:asset) do + # this needs to be done outside run_locally in order for host to exist + remote_dir = "#{host.user}@#{host.hostname}:#{release_path}/public/" + execute "mkdir -p #{release_path}/public/assets/" + run_locally { execute "rsync -av --delete --exclude system #{local_dir} #{remote_dir}" } + + # We need to link the existing shared `/var/apps/wheelmap/public/system` folder + # into the new release. + execute :ln, "-s", "#{deploy_path}/public/system", "#{release_path}/public/system" + + # We create this file so the consul health check will pass. We can't use an + # existing file since they are all unpredictably named. + execute "touch #{release_path}/public/assets/ping" + + # stolen from https://github.com/capistrano/capistrano/blob/master/lib/capistrano/tasks/deploy.rake#L101 + # we can't directly invoke the task since that runs on deploy roles only + tmp_current_path = release_path.parent.join(current_path.basename) + execute :ln, "-s", release_path, tmp_current_path + execute :mv, tmp_current_path, current_path.parent + end + + on roles(:app) do + # this needs to be done outside run_locally in order for host to exist + remote_dir = "#{host.user}@#{host.hostname}:#{release_path}/public/" + execute "mkdir -p #{release_path}/public/assets/" + run_locally { execute "rsync -av --delete #{local_dir}/assets/.sprockets-manifest-* #{remote_dir}/assets" } + end + + # clean up + run_locally { execute "rm -rf #{local_dir}" } + end + + end + desc 'Restart application' task :restart do on roles(:app), in: :sequence, wait: 5 do # Your restart mechanism here, for example: # execute :touch, release_path.join('tmp/restart.txt') - sudo "/etc/init.d/unicorn_#{fetch(:stage)} upgrade" + sudo "systemctl restart webapp.service" end end - desc 'Stopp application' + desc 'Stop application' task :stop do on roles(:app), in: :sequence, wait: 5 do - sudo "/etc/init.d/unicorn_#{fetch(:stage)} stop" + sudo "systemctl stop webapp.service" end end desc 'Start application' task :start do on roles(:app), in: :sequence, wait: 5 do - sudo "/etc/init.d/unicorn_#{fetch(:stage)} start" + sudo "systemctl start webapp.service" end end @@ -98,6 +153,6 @@ end end - after :finished, 'airbrake:deploy' - after :finished, 'newrelic:notice_deployment' +# after :finished, 'airbrake:deploy' +# after :finished, 'newrelic:notice_deployment' end diff --git a/config/deploy/production.rb b/config/deploy/production.rb index 8ec07b93e..570187c95 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -4,9 +4,9 @@ set :rails_env, 'production' # added for delayed job set :stage, :production -set :deploy_to, "/var/apps/#{fetch(:application)}/#{fetch(:stage)}" +set :deploy_to, "/var/apps/#{fetch(:application)}/" -set :branch, :production +set :branch, :"feature/infra-rebuild" set :rev, proc { `git rev-parse --short #{fetch(:branch)}`.chomp } # Simple Role Syntax @@ -15,10 +15,10 @@ # is considered to be the first unless any hosts have the primary # property set. Don't declare `role :all`, it's a meta role. -role :app, %w(176.9.63.170) -role :web, %w(176.9.63.170) -role :db, %w(176.9.63.170) -role :worker, %w(176.9.63.170) +#role :app, %w{176.9.63.170} +#role :web, %w{176.9.63.170} +#role :db, %w{176.9.63.170} +#role :worker, %w{176.9.63.170} # Extended Server Syntax # ====================== @@ -26,7 +26,12 @@ # server list. The second argument is a, or duck-types, Hash and is # used to set extended properties on the server. -server '176.9.63.170', user: 'rails', roles: %w(web app db worker), port: 22_022 +server 'app0.node.production', user: 'deploy', roles: %w{app}, port: 22 +server 'app1.node.production', user: 'deploy', roles: %w{app}, port: 22 +server 'asset.node.production', user: 'deploy', roles: %w{asset}, port: 22, :no_release => true +server 'worker0.node.production', user: 'deploy', roles: %w{worker}, port: 22 +server 'osm-database.node.production', user: 'deploy', roles: %w{importer}, port: 22 # Used for replication. +#server 'mysql.node.production', user: 'wheelmap', roles: %w{mysql}, port: 22 # Custom SSH Options # ================== @@ -35,13 +40,13 @@ # # Global options # -------------- -set :ssh_options, - keys: %w(~/.ssh/wheelmap_rsa), - forward_agent: true, - config: true, - port: 22_022 -# auth_methods: %w(password) - +#set :ssh_options, { +# keys: %w(~/.ssh/wheelmap_rsa), +# forward_agent: true, +# config: true, +# port: 22022 +# # auth_methods: %w(password) +#} # # And/or per server (overrides global) # ------------------------------------ diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb index 25f63d6dc..e261c705d 100644 --- a/config/deploy/staging.rb +++ b/config/deploy/staging.rb @@ -4,31 +4,29 @@ set :rails_env, 'staging' # added for delayed job set :stage, :staging -set :deploy_to, "/var/apps/#{fetch(:application)}/#{fetch(:stage)}" +set :deploy_to, "/var/apps/#{fetch(:application)}/" -set :branch, ENV['BRANCH'] || 'master' +set :branch, :"feature/infra-rebuild" set :rev, proc { `git rev-parse --short #{fetch(:branch)}`.chomp } -set :whenever_identifier, -> { "#{fetch(:application)}_#{fetch(:stage)}" } - # Simple Role Syntax # ================== # Supports bulk-adding hosts to roles, the primary server in each group # is considered to be the first unless any hosts have the primary # property set. Don't declare `role :all`, it's a meta role. -role :app, %w(176.9.63.171) -role :web, %w(176.9.63.171) -role :db, %w(176.9.63.171) -role :worker, %w(176.9.63.171) # Extended Server Syntax # ====================== # This can be used to drop a more detailed server definition into the # server list. The second argument is a, or duck-types, Hash and is # used to set extended properties on the server. - -server '176.9.63.171', user: 'rails', roles: %w(web app), my_property: :my_value +server 'app0.node.staging', user: 'deploy', roles: %w{app}, port: 22 +server 'app1.node.staging', user: 'deploy', roles: %w{app}, port: 22 +server 'asset.node.staging', user: 'deploy', roles: %w{asset}, port: 22, :no_release => true +server 'worker0.node.staging', user: 'deploy', roles: %w{worker}, port: 22 +server 'osm-database.node.staging', user: 'deploy', roles: %w{importer}, port: 22 # Used for replication. +#server 'mysql.node.production', user: 'wheelmap', roles: %w{mysql}, port: 22 # Custom SSH Options # ================== @@ -37,13 +35,13 @@ # # Global options # -------------- -set :ssh_options, - keys: %w(~/.ssh/wheelmap_rsa), - forward_agent: true, - config: true, - port: 22_022 -# auth_methods: %w(password) - +#set :ssh_options, { +# keys: %w(~/.ssh/wheelmap_rsa), +# forward_agent: true, +# config: true, +# port: 22022 +# # auth_methods: %w(password) +#} # # And/or per server (overrides global) # ------------------------------------ diff --git a/config/environments/production.rb b/config/environments/production.rb index 7a3f8a460..6df959d28 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -40,42 +40,45 @@ # config.force_ssl = true # See everything in the log (default is :info) - config.log_level = :info + config.log_level = :warn - config.logger = Logger.new('log/production.log', 3, 1_073_741_824) # 1GB + config.logger = Logger.new($stdout) # Use a different cache store in production # default is: # config.cache_store = :file_store, "tmp/cache/" - config.cache_store = :mem_cache_store, 'localhost', { namespace: "wheelmap/#{Rails.env}/", - c_threshold: 10_000, - compression: true, - debug: Rails.env.development?, - readonly: false, - urlencode: false } + config.cache_store = :mem_cache_store, 'app-database', { :namespace => "wheelmap/#{Rails.env}/", + :c_threshold => 10_000, + :compression => true, + :debug => Rails.env.development?, + :readonly => false, + :urlencode => false + } + # Disable Rails's static asset server # In production, Apache or nginx will already do this config.serve_static_assets = false # Enable serving of images, stylesheets, and javascripts from an asset server - config.action_controller.asset_host = 'asset%d.wheelmap.org' + config.action_controller.asset_host = "new-production-asset.wheelmap.org" # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method = :smtp - config.action_mailer.default_url_options = { host: 'wheelmap.org' } + config.action_mailer.default_url_options = { + :host => 'wheelmap.org', + :from => 'noreply@wheelmap.org', + } config.action_mailer.smtp_settings = { - address: 'mail.wheelmap.org', - enable_starttls_auto: false, - port: 25, - domain: 'wheelmap.org', - authentication: :login, - user_name: Rails.application.secrets.mail_user, - password: Rails.application.secrets.mail_password - + :authentication => :plain, + :address => 'smtp.mailgun.org', + :port => 587, + :domain => 'mg.wheelmap.org', + :user_name => Rails.application.secrets.mail_user, + :password => Rails.application.secrets.mail_password } # Enable threaded mode diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 28bd17813..b11a8bab2 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -39,40 +39,42 @@ # Use a different logger for distributed setups # config.logger = SyslogLogger.new - config.logger = Logger.new('log/staging.log', 3, 1_073_741_824) # 1GB + config.logger = Logger.new($stdout) # Use a different cache store in staging # default is: # config.cache_store = :file_store, "tmp/cache/" - config.cache_store = :mem_cache_store, 'localhost', { namespace: "wheelmap/#{Rails.env}/", - c_threshold: 10_000, - compression: true, - debug: Rails.env.staging?, - readonly: false, - urlencode: false } + config.cache_store = :mem_cache_store, 'app-database', { :namespace => "wheelmap/#{Rails.env}/", + :c_threshold => 10_000, + :compression => true, + :debug => Rails.env.staging?, + :readonly => false, + :urlencode => false + } # Disable Rails's static asset server # In production, Apache or nginx will already do this config.serve_static_assets = false # Enable serving of images, stylesheets, and javascripts from an asset server - config.action_controller.asset_host = 'staging.wheelmap.org' + config.action_controller.asset_host = 'new-staging-asset.wheelmap.org' # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method = :smtp - config.action_mailer.default_url_options = { host: 'staging.wheelmap.org' } + config.action_mailer.default_url_options = { + :host => 'staging.wheelmap.org', + :from => 'noreply@wheelmap.org', + } config.action_mailer.smtp_settings = { - address: 'mail.wheelmap.org', - enable_starttls_auto: false, - port: 25, - domain: 'wheelmap.org', - authentication: :login, - user_name: Rails.application.secrets.mail_user, - password: Rails.application.secrets.mail_password - + :authentication => :plain, + :address => 'smtp.mailgun.org', + :port => 587, + :domain => 'mg.wheelmap.org', + :user_name => Rails.application.secrets.mail_user, + :password => Rails.application.secrets.mail_password } # Enable threaded mode diff --git a/config/initializers/delayed_job_config.rb b/config/initializers/delayed_job_config.rb index dddfe4a7b..db7dd8242 100644 --- a/config/initializers/delayed_job_config.rb +++ b/config/initializers/delayed_job_config.rb @@ -3,7 +3,7 @@ Delayed::Worker.sleep_delay = 5 Delayed::Worker.max_attempts = 20 Delayed::Worker.max_run_time = 5.minutes -Delayed::Worker.logger = Logger.new("#{Rails.root}/log/delayed_job.log") +Delayed::Worker.logger = Logger.new($stdout) # require 'delayed_job_plugin' # Delayed::Worker.plugins << DelayedJobPlugin diff --git a/config/unicorn.rb b/config/unicorn.rb index 788779f98..2f5b630c7 100644 --- a/config/unicorn.rb +++ b/config/unicorn.rb @@ -2,9 +2,9 @@ # Set environment to development unless something else is specified env = ENV['RAILS_ENV'] || 'staging' -worker_processes env == 'production' ? 9 : 1 -base_dir = "/var/apps/wheelmap/#{env}/current" -shared_path = "/var/apps/wheelmap/#{env}/shared" +worker_processes 4 +base_dir = "/var/apps/wheelmap/current" +shared_path = "/var/apps/wheelmap/shared" working_directory base_dir # This loads the application in the master process before forking @@ -23,15 +23,13 @@ timeout env == 'production' ? 300 : 30 -# This is where we specify the socket. -# We will point the upstream Nginx module to this socket later on -listen "#{shared_path}/unicorn.sock", backlog: 1024 +listen 3000, :backlog => 1024 pid "#{shared_path}/pids/unicorn.pid" -# Set the path of the log files inside the log folder of the testapp -stdout_path "#{shared_path}/log/unicorn.stdout.log" -stderr_path "#{shared_path}/log/unicorn.stderr.log" +## Set the path of the log files inside the log folder of the testapp +#stdout_path "#{shared_path}/log/unicorn.stdout.log" +#stderr_path "#{shared_path}/log/unicorn.stderr.log" # The new check_client_connection option allows unicorn to detect # most disconnected local clients before potentially expensive diff --git a/lib/capistrano/tasks/delayed_job.rake b/lib/capistrano/tasks/delayed_job.rake index 29255d853..35214858b 100644 --- a/lib/capistrano/tasks/delayed_job.rake +++ b/lib/capistrano/tasks/delayed_job.rake @@ -4,49 +4,27 @@ namespace :delayed_job do end def delayed_job_roles - fetch(:delayed_job_server_role, :app) + fetch(:delayed_job_server_role, :worker) end desc 'Stop the delayed_job process' task :stop do on roles(delayed_job_roles) do - within release_path do - with rails_env: fetch(:rails_env) do - begin - sudo '/usr/bin/monit unmonitor delayed_job' - rescue - nil - end - execute :bundle, :exec, :'script/delayed_job', :stop - end - end + sudo "systemctl stop worker.service" end end desc 'Start the delayed_job process' task :start do on roles(delayed_job_roles) do - within release_path do - with rails_env: fetch(:rails_env) do - execute :bundle, :exec, :'script/delayed_job', args, :start - begin - sudo '/usr/bin/monit monitor delayed_job' - rescue - nil - end - end - end + sudo "systemctl start worker.service" end end desc 'Restart the delayed_job process' task :restart do on roles(delayed_job_roles) do - within release_path do - with rails_env: fetch(:rails_env) do - execute :bundle, :exec, :'bin/delayed_job', args, :restart - end - end + sudo "systemctl restart worker.service" end end end diff --git a/lib/rack_request_logger.rb b/lib/rack_request_logger.rb index 710854214..63e85e088 100644 --- a/lib/rack_request_logger.rb +++ b/lib/rack_request_logger.rb @@ -3,17 +3,17 @@ module Rack # especially to investigate XML stuff going through the API class RequestLogger def initialize(app) - @logger = ::Logger.new(Rails.root.join('log/rack_requests.log')) + @logger = ::Logger.new($stdout) @app = app end def call(env) if env['HTTP_USER_AGENT'] =~ /Wheelmap/ - @logger.debug('>>>>>>>>>>>>>>>>>>>>>>>>>>') + @logger.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>") @logger.debug("#{Time.now.utc} new request:") - @logger.debug('----------- REQUEST HEADERS -----------') - headers = env.select { |k, _v| k =~ /^HTTP_/ } || [] - @logger.debug(headers.map { |k, v| "#{k}: #{v}" }.join("\n")) + @logger.debug("----------- REQUEST HEADERS -----------") + headers = env.select { |k, v| k =~ /^HTTP_/ } || [] + @logger.debug(headers.map { |k, v| "#{k}: #{v}"}.join("\n")) request = Rack::Request.new env @logger.debug('----------- REQUEST BODY (RAW_POST_DATA) -----------') diff --git a/lib/tasks/planet_reader.rake b/lib/tasks/planet_reader.rake index 9e49d187a..e2fe4ed72 100644 --- a/lib/tasks/planet_reader.rake +++ b/lib/tasks/planet_reader.rake @@ -8,6 +8,7 @@ SHAPE_FILE = "#{VAR_DIR}/shapes.osc".freeze STATE_FILE = "#{WORKING_DIR}/state.txt".freeze BACKUP_FILE = "#{WORKING_DIR}/state.old".freeze DOWNLOAD_LOCK = "#{WORKING_DIR}/download.lock".freeze +MAKE_OSC_DIR = "/var/apps/make_osc/".freeze require 'rake' @@ -54,9 +55,8 @@ def get_new_replication_file end def get_new_shape_replication_files - puts 'INFO: Fetching shape changes.' - system "ssh -p 22022 osm@176.9.63.171 \"ruby make_osc.rb -d\" 2> /dev/null >> #{SHAPE_FILE}" - puts "INFO: Downloaded #{File.size(SHAPE_FILE)} bytes" + puts "INFO: Fetching shape changes." + system "BUNDLE_GEMFILE=#{MAKE_OSC_DIR}/Gemfile bundle exec #{MAKE_OSC_DIR}/make_osc.rb -d >> #{SHAPE_FILE}" end def merge_replication_files