summaryrefslogtreecommitdiff
path: root/lib/tasks/gitlab/artifacts/migrate.rake
blob: 94867e1a16a982c61893888872379afc58e512bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

require 'logger'
require 'resolv-replace'

desc 'GitLab | Artifacts | Migrate files for artifacts to comply with new storage format'
namespace :gitlab do
  namespace :artifacts do
    task migrate: :environment do
      logger = Logger.new(STDOUT)
      logger.info('Starting transfer of artifacts to remote storage')

      helper = Gitlab::Artifacts::MigrationHelper.new

      begin
        helper.migrate_to_remote_storage do |artifact|
          logger.info("Transferred artifact ID #{artifact.id} of type #{artifact.file_type} with size #{artifact.size} to object storage")
        end
      rescue => e
        logger.error(e.message)
      end
    end

    task migrate_to_local: :environment do
      logger = Logger.new(STDOUT)
      logger.info('Starting transfer of artifacts to local storage')

      helper = Gitlab::Artifacts::MigrationHelper.new

      begin
        helper.migrate_to_local_storage do |artifact|
          logger.info("Transferred artifact ID #{artifact.id} of type #{artifact.file_type} with size #{artifact.size} to local storage")
        end
      rescue => e
        logger.error(e.message)
      end
    end
  end
end