From 110b3f63352e85c6ac138918b285d963382ce623 Mon Sep 17 00:00:00 2001 From: ThibG Date: Sat, 11 Aug 2018 22:02:55 +0200 Subject: Add some feedback to maintenance rake tasks (#8173) --- lib/tasks/mastodon.rake | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib') diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake index de8c0bb86..f693c8b5a 100644 --- a/lib/tasks/mastodon.rake +++ b/lib/tasks/mastodon.rake @@ -502,18 +502,24 @@ namespace :mastodon do desc 'Remove media attachments attributed to silenced accounts' task remove_silenced: :environment do + nb_media_attachments = 0 MediaAttachment.where(account: Account.silenced).select(:id).find_in_batches do |media_attachments| + nb_media_attachments += media_attachments.length Maintenance::DestroyMediaWorker.push_bulk(media_attachments.map(&:id)) end + puts "Scheduled the deletion of #{nb_media_attachments} media attachments" end desc 'Remove cached remote media attachments that are older than NUM_DAYS. By default 7 (week)' task remove_remote: :environment do time_ago = ENV.fetch('NUM_DAYS') { 7 }.to_i.days.ago + nb_media_attachments = 0 MediaAttachment.where.not(remote_url: '').where.not(file_file_name: nil).where('created_at < ?', time_ago).select(:id).find_in_batches do |media_attachments| + nb_media_attachments += media_attachments.length Maintenance::UncacheMediaWorker.push_bulk(media_attachments.map(&:id)) end + puts "Scheduled the deletion of #{nb_media_attachments} media attachments" end desc 'Set unknown attachment type for remote-only attachments' @@ -527,10 +533,13 @@ namespace :mastodon do task redownload_avatars: :environment do accounts = Account.remote accounts = accounts.where(domain: ENV['DOMAIN']) if ENV['DOMAIN'].present? + nb_accounts = 0 accounts.select(:id).find_in_batches do |accounts_batch| + nb_accounts += accounts_batch.length Maintenance::RedownloadAccountMediaWorker.push_bulk(accounts_batch.map(&:id)) end + puts "Scheduled the download of avatars/headers for #{nb_accounts} remote users" end end -- cgit From 018a9e4e7fdfac0f2e482f4b5fa66247afbc2ddb Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 13 Aug 2018 13:40:01 +0200 Subject: Add post-deployment migration system (#8182) Adopted from GitLab CE. Generate new migration with: rails g post_deployment_migration name_of_migration_here By default they are run together with db:migrate. To not run them, the env variable SKIP_POST_DEPLOYMENT_MIGRATIONS must be set Code by Yorick Peterse , see also: https://gitlab.com/gitlab-org/gitlab-ce/commit/83c8241160ed48ab066e2c5bd58d0914a745197c --- .rubocop.yml | 1 + config/initializers/0_post_deployment_migrations.rb | 15 +++++++++++++++ db/post_migrate/.gitkeep | 0 lib/generators/post_deployment_migration_generator.rb | 17 +++++++++++++++++ .../rails/post_deployment_migration/migration.rb | 8 ++++++++ 5 files changed, 41 insertions(+) create mode 100644 config/initializers/0_post_deployment_migrations.rb create mode 100644 db/post_migrate/.gitkeep create mode 100644 lib/generators/post_deployment_migration_generator.rb create mode 100644 lib/templates/rails/post_deployment_migration/migration.rb (limited to 'lib') diff --git a/.rubocop.yml b/.rubocop.yml index 6faeaca6f..4f9e09b43 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,6 +11,7 @@ AllCops: - 'Vagrantfile' - 'vendor/**/*' - 'lib/json_ld/*' + - 'lib/templates/**/*' Bundler/OrderedGems: Enabled: false diff --git a/config/initializers/0_post_deployment_migrations.rb b/config/initializers/0_post_deployment_migrations.rb new file mode 100644 index 000000000..61121ccd7 --- /dev/null +++ b/config/initializers/0_post_deployment_migrations.rb @@ -0,0 +1,15 @@ +# Post deployment migrations are included by default. This file must be loaded +# before other initializers as Rails may otherwise memoize a list of migrations +# excluding the post deployment migrations. + +unless ENV['SKIP_POST_DEPLOYMENT_MIGRATIONS'] + Rails.application.config.paths['db'].each do |db_path| + path = Rails.root.join(db_path, 'post_migrate').to_s + + Rails.application.config.paths['db/migrate'] << path + + # Rails memoizes migrations at certain points where it won't read the above + # path just yet. As such we must also update the following list of paths. + ActiveRecord::Migrator.migrations_paths << path + end +end diff --git a/db/post_migrate/.gitkeep b/db/post_migrate/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/lib/generators/post_deployment_migration_generator.rb b/lib/generators/post_deployment_migration_generator.rb new file mode 100644 index 000000000..798c01b88 --- /dev/null +++ b/lib/generators/post_deployment_migration_generator.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'rails/generators' + +module Rails + class PostDeploymentMigrationGenerator < Rails::Generators::NamedBase + def create_migration_file + timestamp = Time.zone.now.strftime('%Y%m%d%H%M%S') + + template 'migration.rb', "db/post_migrate/#{timestamp}_#{file_name}.rb" + end + + def migration_class_name + file_name.camelize + end + end +end diff --git a/lib/templates/rails/post_deployment_migration/migration.rb b/lib/templates/rails/post_deployment_migration/migration.rb new file mode 100644 index 000000000..503205b84 --- /dev/null +++ b/lib/templates/rails/post_deployment_migration/migration.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class <%= migration_class_name %> < ActiveRecord::Migration[5.2] + disable_ddl_transaction! + + def change + end +end -- cgit From b0f4fe456b15bfe74b9feca247d0ac67a8ba21fb Mon Sep 17 00:00:00 2001 From: Immae Date: Wed, 15 Aug 2018 18:12:44 +0200 Subject: Add ldap search filter (#8151) --- .env.production.sample | 1 + config/initializers/devise.rb | 3 +++ lib/devise/ldap_authenticatable.rb | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/.env.production.sample b/.env.production.sample index ebb078878..349daedd8 100644 --- a/.env.production.sample +++ b/.env.production.sample @@ -162,6 +162,7 @@ STREAMING_CLUSTER_NUM=1 # LDAP_BIND_DN= # LDAP_PASSWORD= # LDAP_UID=cn +# LDAP_SEARCH_FILTER="%{uid}=%{email}" # PAM authentication (optional) # PAM authentication uses for the email generation the "email" pam variable diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 8532c9d9a..cd9bacf68 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -59,6 +59,8 @@ module Devise @@ldap_password = nil mattr_accessor :ldap_tls_no_verify @@ldap_tls_no_verify = false + mattr_accessor :ldap_search_filter + @@ldap_search_filter = nil class Strategies::PamAuthenticatable def valid? @@ -362,5 +364,6 @@ Devise.setup do |config| config.ldap_password = ENV.fetch('LDAP_PASSWORD') config.ldap_uid = ENV.fetch('LDAP_UID', 'cn') config.ldap_tls_no_verify = ENV['LDAP_TLS_NO_VERIFY'] == 'true' + config.ldap_search_filter = ENV.fetch('LDAP_SEARCH_FILTER', '%{uid}=%{email}') end end diff --git a/lib/devise/ldap_authenticatable.rb b/lib/devise/ldap_authenticatable.rb index ef786fbb7..534c7a851 100644 --- a/lib/devise/ldap_authenticatable.rb +++ b/lib/devise/ldap_authenticatable.rb @@ -24,7 +24,8 @@ module Devise connect_timeout: 10 ) - if (user_info = ldap.bind_as(base: Devise.ldap_base, filter: "(#{Devise.ldap_uid}=#{email})", password: password)) + filter = format(Devise.ldap_search_filter, uid: Devise.ldap_uid, email: email) + if (user_info = ldap.bind_as(base: Devise.ldap_base, filter: filter, password: password)) user = User.ldap_get_user(user_info.first) success!(user) else -- cgit