2021-02-05 07:09:31 -05:00
# frozen_string_literal: true
2020-12-23 01:10:22 -05:00
require 'logger'
namespace :gitlab do
namespace :pages do
desc " GitLab | Pages | Migrate legacy storage to zip format "
task migrate_legacy_storage : :gitlab_environment do
logger . info ( 'Starting to migrate legacy pages storage to zip deployments' )
2021-02-11 16:09:00 -05:00
result = :: Pages :: MigrateFromLegacyStorageService . new ( logger ,
2021-04-05 17:09:19 -04:00
ignore_invalid_entries : ignore_invalid_entries ,
2021-04-15 11:09:11 -04:00
mark_projects_as_not_deployed : mark_projects_as_not_deployed )
. execute_with_threads ( threads : migration_threads , batch_size : batch_size )
2021-01-12 13:11:03 -05:00
2021-01-22 13:09:10 -05:00
logger . info ( " A total of #{ result [ :migrated ] + result [ :errored ] } projects were processed. " )
logger . info ( " - The #{ result [ :migrated ] } projects migrated successfully " )
logger . info ( " - The #{ result [ :errored ] } projects failed to be migrated " )
end
2020-12-23 01:10:22 -05:00
2021-02-10 07:09:45 -05:00
desc " GitLab | Pages | DANGER: Removes data which was migrated from legacy storage on zip storage. Can be used if some bugs in migration are discovered and migration needs to be restarted from scratch. "
task clean_migrated_zip_storage : :gitlab_environment do
destroyed_deployments = 0
logger . info ( " Starting to delete migrated pages deployments " )
:: PagesDeployment . migrated_from_legacy_storage . each_batch ( of : batch_size ) do | batch |
destroyed_deployments += batch . count
# we need to destroy associated files, so can't use delete_all
batch . destroy_all # rubocop: disable Cop/DestroyAll
logger . info ( " #{ destroyed_deployments } deployments were deleted " )
end
end
def logger
2021-06-08 11:10:00 -04:00
@logger || = Logger . new ( $stdout )
2021-02-10 07:09:45 -05:00
end
2021-01-22 13:09:10 -05:00
def migration_threads
ENV . fetch ( 'PAGES_MIGRATION_THREADS' , '3' ) . to_i
end
2021-01-20 19:11:07 -05:00
2021-01-22 13:09:10 -05:00
def batch_size
ENV . fetch ( 'PAGES_MIGRATION_BATCH_SIZE' , '10' ) . to_i
2020-12-23 01:10:22 -05:00
end
2021-02-11 16:09:00 -05:00
def ignore_invalid_entries
Gitlab :: Utils . to_boolean (
ENV . fetch ( 'PAGES_MIGRATION_IGNORE_INVALID_ENTRIES' , 'false' )
)
end
2021-04-05 17:09:19 -04:00
def mark_projects_as_not_deployed
Gitlab :: Utils . to_boolean (
ENV . fetch ( 'PAGES_MIGRATION_MARK_PROJECTS_AS_NOT_DEPLOYED' , 'false' )
)
end
2021-04-15 11:09:11 -04:00
namespace :deployments do
task migrate_to_object_storage : :gitlab_environment do
2021-06-08 11:10:00 -04:00
logger = Logger . new ( $stdout )
2021-04-15 11:09:11 -04:00
2021-05-03 05:10:02 -04:00
helper = Gitlab :: LocalAndRemoteStorageMigration :: PagesDeploymentMigrater . new ( logger )
2021-04-15 11:09:11 -04:00
begin
helper . migrate_to_remote_storage
2021-04-26 08:09:44 -04:00
rescue StandardError = > e
2021-04-15 11:09:11 -04:00
logger . error ( e . message )
end
end
task migrate_to_local : :gitlab_environment do
2021-06-08 11:10:00 -04:00
logger = Logger . new ( $stdout )
2021-04-15 11:09:11 -04:00
2021-05-03 05:10:02 -04:00
helper = Gitlab :: LocalAndRemoteStorageMigration :: PagesDeploymentMigrater . new ( logger )
2021-04-15 11:09:11 -04:00
begin
helper . migrate_to_local_storage
2021-04-26 08:09:44 -04:00
rescue StandardError = > e
2021-04-15 11:09:11 -04:00
logger . error ( e . message )
end
end
end
2020-12-23 01:10:22 -05:00
end
end