From 17fc8ac1bcfaef4760c6ea56f076e97503c9f7e1 Mon Sep 17 00:00:00 2001 From: Max Kadel Date: Thu, 14 Nov 2024 09:32:57 -0500 Subject: [PATCH] Do not exclude Ruby files from all Rubocop checks - Fixes deploy problem - Minor style fixes to config/environments files --- .rubocop.yml | 6 +- config/deploy.rb | 118 +++++++++++------------------ config/environments/development.rb | 15 ++-- config/environments/production.rb | 11 +-- config/environments/staging.rb | 13 ++-- config/environments/test.rb | 5 +- 6 files changed, 71 insertions(+), 97 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index fb387668..282cc543 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,9 +12,6 @@ AllCops: - 'script/**/*' - 'vendor/**/*' - 'bin/*' - - 'config/deploy.rb' - - 'config/initializers/blacklight_url_helper_behavior.rb' - - 'config/environments/**/*' - 'node_modules/**/*' Layout/IndentationConsistency: @@ -35,3 +32,6 @@ Metrics/BlockLength: - 'spec/**/*' - 'lib/tasks/approvals.rake' - 'config/routes.rb' + - config/environments/development.rb + - config/environments/production.rb + - config/environments/staging.rb diff --git a/config/deploy.rb b/config/deploy.rb index 9fb53e8f..3f709d26 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,22 +1,22 @@ # frozen_string_literal: true # config valid only for Capistrano 3.1 -lock '>=3.2.1' +lock ">=3.2.1" -set :application, 'approvals' -set :repo_url, 'https://github.com/pulibrary/approvals.git' +set :application, "approvals" +set :repo_url, "https://github.com/pulibrary/approvals.git" # gets overriden to development on staging deploy -set :branch, 'main' +set :branch, "main" # Default branch is :master # ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call # Default deploy_to directory is /var/www/my_app -set :deploy_to, '/opt/approvals' +set :deploy_to, "/opt/approvals" # Install yarn devDependencies, not just the prod ones -set :yarn_flags, '--silent --no-progress' +set :yarn_flags, "--silent --no-progress" # Default value for :format is :pretty # set :format, :pretty @@ -28,16 +28,14 @@ # set :pty, true set :branch, ENV["BRANCH"] || "main" - -shared_path = "#{:deploy_to}/shared" +shared_path = "deploy_to/shared" # set :assets_prefix, '#{shared_path}/public' ## removing the following from linked files for the time being # config/redis.yml config/devise.yml config/resque_pool.yml, config/recipients_list.yml, log/resque-pool.stderr.log log/resque-pool.stdout.log # set :linked_files, %w{config/database.yml} -set :linked_dirs, %w{tmp/pids tmp/sockets log} - +set :linked_dirs, %w[tmp/pids tmp/sockets log] # Default value for :linked_files is [] # set :linked_files, %w{config/database.yml} @@ -54,84 +52,81 @@ set :passenger_restart_with_touch, true namespace :approvals do - - desc 'reset the database and reseed' + desc "reset the database and reseed" task :reset do on roles(:app) do within current_path do - with :rails_env => fetch(:rails_env) do - execute :sudo, '/usr/sbin/service nginx stop' - execute :rake, 'db:drop db:create db:migrate' - execute :sudo, '/usr/sbin/service nginx start' + with rails_env: fetch(:rails_env) do + execute :sudo, "/usr/sbin/service nginx stop" + execute :rake, "db:drop db:create db:migrate" + execute :sudo, "/usr/sbin/service nginx start" # we process the locations twice when the database is empty, since there is a chicken and egg situation # The location needs to exist to attche an AA to it, but the AA must exist to attach it to a location. - # The location processing just ignores an AA that does not exists, so if we run it once the locations + # The location processing just ignores an AA that does not exists, so if we run it once the locations # exists to connect with the new people. If we run it again after the people exists it connects the AAs. - execute :rake, 'approvals:load_locations' - execute :rake, 'approvals:process_reports' - execute :rake, 'approvals:load_locations' - execute :rake, 'approvals:make_requests_for_everyone' + execute :rake, "approvals:load_locations" + execute :rake, "approvals:process_reports" + execute :rake, "approvals:load_locations" + execute :rake, "approvals:make_requests_for_everyone" end end - end + end end - desc 'Process the staff report now' + desc "Process the staff report now" task :process_reports do on roles(:app) do within current_path do - with :rails_env => fetch(:rails_env) do - execute :rake, 'approvals:process_reports' + with rails_env: fetch(:rails_env) do + execute :rake, "approvals:process_reports" end end - end + end end - desc 'Make Requests for everyone this can take a very long time' + desc "Make Requests for everyone this can take a very long time" task :make_requests_for_everyone do on roles(:app) do within current_path do - with :rails_env => fetch(:rails_env) do - execute :rake, 'approvals:make_requests_for_everyone' - end - end - end + with rails_env: fetch(:rails_env) do + execute :rake, "approvals:make_requests_for_everyone" + end + end + end end - desc 'Make Requests for a specific user' + desc "Make Requests for a specific user" task :make_requests_for_user, [:netid] do |_t, args| netid = args[:netid] on roles(:app) do within current_path do - with :rails_env => fetch(:rails_env) do + with rails_env: fetch(:rails_env) do execute :rake, "approvals:make_requests_for_user[#{netid}]" - end - end - end + end + end + end end - desc 'Add fake users to give [:netid] someone to supervise' + desc "Add fake users to give [:netid] someone to supervise" task :make_me_a_supervisor, [:netid, :number] do |_t, args| netid = args[:netid] number = args[:number] on roles(:app) do within current_path do - with :rails_env => fetch(:rails_env) do + with rails_env: fetch(:rails_env) do execute :rake, "approvals:make_me_a_supervisor[#{netid},#{number}]" - end - end - end + end + end + end end end - - namespace :deploy do - desc 'Restart application' + 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') + execute :touch, release_path.join("tmp/restart.txt") end end @@ -143,19 +138,10 @@ # end end end +end -# TODO - We likely need a robot.txt -# task :robots_txt do -# on roles(:app) do -# within release_path do -# execute :rake, 'pulsearch:robots_txt' -# end -# end -# end -# after :publishing, :restart -# after :publishing, :robots_txt - after :finishing, 'deploy:cleanup' +after :finishing, "deploy:cleanup" namespace :application do # You can/ should apply this command to a subset of hosts @@ -166,9 +152,7 @@ on roles(:app) do count += 1 end - if count > (roles(:app).length / 2) - raise "You must run this command on no more than half the servers utilizing the --hosts= switch" - end + raise "You must run this command on no more than half the servers utilizing the --hosts= switch" if count > (roles(:app).length / 2) on roles(:app) do within release_path do execute :touch, "public/remove-from-nginx" @@ -187,17 +171,3 @@ end end end - -# before "deploy:reverted", "deploy:assets:precompile" - # # We shouldn't need this because it should be built in to Rails 5.1 - # # see https://github.com/rails/webpacker/issues/1037 - # desc 'Run yarn install' - # task :yarn_install do - # on roles(:web) do - # within release_path do - # execute("cd #{release_path} && yarn install") - # end - # end - # end - # before "deploy:assets:precompile", "deploy:yarn_install" -# end diff --git a/config/environments/development.rb b/config/environments/development.rb index 2bcecbcf..17efc9ee 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -14,12 +15,12 @@ # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. - if Rails.root.join('tmp', 'caching-dev.txt').exist? + if Rails.root.join("tmp", "caching-dev.txt").exist? config.action_controller.perform_caching = true config.cache_store = :memory_store config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{2.days.to_i}" + "Cache-Control" => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false @@ -36,8 +37,8 @@ config.action_mailer.perform_caching = false config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { - :address => "localhost", - :port => 1025 + address: "localhost", + port: 1025 } # Print deprecation notices to the Rails logger. @@ -53,8 +54,8 @@ # config.action_view.raise_on_missing_translations = true # location of the staff report (assuming current directory) - config.staff_report_location = 'Active Library Staff - Scheduled-en.csv' - config.balance_report_location = 'Balances for Employees Enrolled in Absence Management - Library-en-us.csv' + config.staff_report_location = "Active Library Staff - Scheduled-en.csv" + config.balance_report_location = "Balances for Employees Enrolled in Absence Management - Library-en-us.csv" - Rails.application.routes.default_url_options[:host] = 'localhost:3000' + Rails.application.routes.default_url_options[:host] = "localhost:3000" end diff --git a/config/environments/production.rb b/config/environments/production.rb index dea42266..696fa575 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -20,7 +21,7 @@ # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' @@ -61,7 +62,7 @@ config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { - address: 'lib-ponyexpr-prod.princeton.edu', + address: "lib-ponyexpr-prod.princeton.edu", enable_starttls: false, open_timeout: 10, read_timeout: 10 @@ -91,8 +92,8 @@ config.active_record.dump_schema_after_migration = false # location of the mounted staff report - config.staff_report_location = '/mnt/dms-smbserve/bi-library-hr/prod/Department Absence Manager Report - Library-en.csv' - config.balance_report_location = '/mnt/dms-smbserve/bi-library-hr/prod/Balances for Employees Enrolled in Absence Management - Library-en-us.csv' + config.staff_report_location = "/mnt/dms-smbserve/bi-library-hr/prod/Department Absence Manager Report - Library-en.csv" + config.balance_report_location = "/mnt/dms-smbserve/bi-library-hr/prod/Balances for Employees Enrolled in Absence Management - Library-en-us.csv" - Rails.application.routes.default_url_options[:host] = 'approvals.princeton.edu' + Rails.application.routes.default_url_options[:host] = "approvals.princeton.edu" end diff --git a/config/environments/staging.rb b/config/environments/staging.rb index dad68d07..e5d1c2ed 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -20,7 +21,7 @@ # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' @@ -58,8 +59,8 @@ config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { - :address => "localhost", - :port => 1025 + address: "localhost", + port: 1025 } # Ignore bad email addresses and do not raise email delivery errors. @@ -90,8 +91,8 @@ config.active_record.dump_schema_after_migration = false # location of the mounted staff report - config.staff_report_location = '/mnt/dms-smbserve/bi-library-hr/prod/Department Absence Manager Report - Library-en.csv' - config.balance_report_location = '/mnt/dms-smbserve/bi-library-hr/prod/Balances for Employees Enrolled in Absence Management - Library-en-us.csv' + config.staff_report_location = "/mnt/dms-smbserve/bi-library-hr/prod/Department Absence Manager Report - Library-en.csv" + config.balance_report_location = "/mnt/dms-smbserve/bi-library-hr/prod/Balances for Employees Enrolled in Absence Management - Library-en-us.csv" - Rails.application.routes.default_url_options[:host] = 'approvals-staging.princeton.edu' + Rails.application.routes.default_url_options[:host] = "approvals-staging.princeton.edu" end diff --git a/config/environments/test.rb b/config/environments/test.rb index 77359f97..5e52e510 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true Rails.application.configure do config.hosts = [] # Settings specified here will take precedence over those in config/application.rb. @@ -16,7 +17,7 @@ # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + "Cache-Control" => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. @@ -45,5 +46,5 @@ # Raises error for missing translations # config.action_view.raise_on_missing_translations = true - Rails.application.routes.default_url_options[:host] = 'localhost:3000' + Rails.application.routes.default_url_options[:host] = "localhost:3000" end