Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 18:44:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 18:44:42 +0300
commit4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch)
tree5423a1c7516cffe36384133ade12572cf709398d /lib/gitlab/local_and_remote_storage_migration
parente570267f2f6b326480d284e0164a6464ba4081bc (diff)
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'lib/gitlab/local_and_remote_storage_migration')
-rw-r--r--lib/gitlab/local_and_remote_storage_migration/artifact_migrater.rb17
-rw-r--r--lib/gitlab/local_and_remote_storage_migration/base_migrater.rb57
-rw-r--r--lib/gitlab/local_and_remote_storage_migration/pages_deployment_migrater.rb17
3 files changed, 91 insertions, 0 deletions
diff --git a/lib/gitlab/local_and_remote_storage_migration/artifact_migrater.rb b/lib/gitlab/local_and_remote_storage_migration/artifact_migrater.rb
new file mode 100644
index 00000000000..b25305382b2
--- /dev/null
+++ b/lib/gitlab/local_and_remote_storage_migration/artifact_migrater.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module LocalAndRemoteStorageMigration
+ class ArtifactMigrater < Gitlab::LocalAndRemoteStorageMigration::BaseMigrater
+ private
+
+ def items_with_files_stored_locally
+ ::Ci::JobArtifact.with_files_stored_locally
+ end
+
+ def items_with_files_stored_remotely
+ ::Ci::JobArtifact.with_files_stored_remotely
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/local_and_remote_storage_migration/base_migrater.rb b/lib/gitlab/local_and_remote_storage_migration/base_migrater.rb
new file mode 100644
index 00000000000..f859d293e76
--- /dev/null
+++ b/lib/gitlab/local_and_remote_storage_migration/base_migrater.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module LocalAndRemoteStorageMigration
+ class BaseMigrater
+ def initialize(logger = nil)
+ @logger = logger
+ end
+
+ def migrate_to_remote_storage
+ logger.info('Starting transfer to remote storage')
+
+ migrate(items_with_files_stored_locally, ObjectStorage::Store::REMOTE)
+ end
+
+ def migrate_to_local_storage
+ logger.info('Starting transfer to local storage')
+
+ migrate(items_with_files_stored_remotely, ObjectStorage::Store::LOCAL)
+ end
+
+ private
+
+ attr_reader :logger
+
+ def batch_size
+ ENV.fetch('MIGRATION_BATCH_SIZE', 10).to_i
+ end
+
+ def migrate(items, store)
+ items.find_each(batch_size: batch_size) do |item| # rubocop:disable CodeReuse/ActiveRecord
+ item.file.migrate!(store)
+
+ log_success(item, store)
+ rescue StandardError => e
+ log_error(e, item)
+ end
+ end
+
+ def log_success(item, store)
+ logger.info("Transferred #{item.class.name} ID #{item.id} of type #{item.file_type} with size #{item.size} to #{storage_label(store)} storage")
+ end
+
+ def log_error(err, item)
+ logger.warn("Failed to transfer #{item.class.name} of type #{item.file_type} and ID #{item.id} with error: #{err.message}")
+ end
+
+ def storage_label(store)
+ if store == ObjectStorage::Store::LOCAL
+ 'local'
+ else
+ 'object'
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/local_and_remote_storage_migration/pages_deployment_migrater.rb b/lib/gitlab/local_and_remote_storage_migration/pages_deployment_migrater.rb
new file mode 100644
index 00000000000..70437936332
--- /dev/null
+++ b/lib/gitlab/local_and_remote_storage_migration/pages_deployment_migrater.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module LocalAndRemoteStorageMigration
+ class PagesDeploymentMigrater < Gitlab::LocalAndRemoteStorageMigration::BaseMigrater
+ private
+
+ def items_with_files_stored_locally
+ ::PagesDeployment.with_files_stored_locally
+ end
+
+ def items_with_files_stored_remotely
+ ::PagesDeployment.with_files_stored_remotely
+ end
+ end
+ end
+end