From 04ce971dcdf6ff1fd65530c302494937f9e8e037 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto <gabriel@gitlab.com> Date: Mon, 26 Feb 2024 00:57:10 +0100 Subject: [PATCH] Extract GitLab Environment data from tasks into SourceContext --- .../lib/gitlab/backup/cli/source_context.rb | 54 +++++++++++++++++++ .../lib/gitlab/backup/cli/tasks/artifacts.rb | 5 +- .../lib/gitlab/backup/cli/tasks/builds.rb | 5 +- .../backup/cli/tasks/ci_secure_files.rb | 5 +- .../lib/gitlab/backup/cli/tasks/lfs.rb | 5 +- .../lib/gitlab/backup/cli/tasks/packages.rb | 5 +- .../lib/gitlab/backup/cli/tasks/pages.rb | 5 +- .../lib/gitlab/backup/cli/tasks/registry.rb | 5 +- .../backup/cli/tasks/terraform_state.rb | 4 +- .../lib/gitlab/backup/cli/tasks/uploads.rb | 4 +- 10 files changed, 63 insertions(+), 34 deletions(-) diff --git a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/source_context.rb b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/source_context.rb index 437e4e1ec54cc..354f3068c7f46 100644 --- a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/source_context.rb +++ b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/source_context.rb @@ -17,6 +17,60 @@ def backup_basedir # TODO: decouple from Rails codebase, load from gitlab.yml file Rails.root.join('tmp/backups') end + + # CI Builds basepath + def ci_builds_path + # TODO: Use configuration solver + Settings.gitlab_ci.builds_path + end + + # Job Artifacts basepath + def ci_job_artifacts_path + # TODO: Use configuration solver + JobArtifactUploader.root + end + + # CI Secure Files basepath + def ci_secure_files_path + # TODO: Use configuration solver + Settings.ci_secure_files.storage_path + end + + # CI LFS basepath + def ci_lfs_path + # TODO: Use configuration solver + Settings.lfs.storage_path + end + + # Packages basepath + def packages_path + # TODO: Use configuration solver + Settings.packages.storage_path + end + + # GitLab Pages basepath + def pages_path + # TODO: Use configuration solver + Gitlab.config.pages.path + end + + # Registry basepath + def registry_path + # TODO: Use configuration solver + Settings.registry.path + end + + # Terraform State basepath + def terraform_state_path + # TODO: Use configuration solver + Settings.terraform_state.storage_path + end + + # Upload basepath + def upload_path + # TODO: Use configuration solver + File.join(Gitlab.config.uploads.storage_path, 'uploads') + end end end end diff --git a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/artifacts.rb b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/artifacts.rb index 80620c536d42e..c3cf3d14dc63b 100644 --- a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/artifacts.rb +++ b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/artifacts.rb @@ -17,10 +17,7 @@ def target ::Backup::Targets::Files.new(nil, storage_path, options: options, excludes: ['tmp']) end - def storage_path - # TODO: Use configuration solver - JobArtifactUploader.root - end + def storage_path = context.ci_job_artifacts_path end end end diff --git a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/builds.rb b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/builds.rb index f2f75008fa974..b94f384880719 100644 --- a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/builds.rb +++ b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/builds.rb @@ -17,10 +17,7 @@ def target ::Backup::Targets::Files.new(nil, storage_path, options: options) end - def storage_path - # TODO: Use configuration solver - Settings.gitlab_ci.builds_path - end + def storage_path = context.ci_builds_path end end end diff --git a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/ci_secure_files.rb b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/ci_secure_files.rb index 7c4b7d8a2ca6a..55b7e44bf1dad 100644 --- a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/ci_secure_files.rb +++ b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/ci_secure_files.rb @@ -17,10 +17,7 @@ def target ::Backup::Targets::Files.new(nil, storage_path, options: options, excludes: ['tmp']) end - def storage_path - # TODO: Use configuration solver - Settings.ci_secure_files.storage_path - end + def storage_path = context.ci_secure_files_path end end end diff --git a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/lfs.rb b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/lfs.rb index 3ed3d47baec5b..256c43b71a37a 100644 --- a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/lfs.rb +++ b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/lfs.rb @@ -17,10 +17,7 @@ def target ::Backup::Targets::Files.new(nil, storage_path, options: options) end - def storage_path - # TODO: Use configuration solver - Settings.lfs.storage_path - end + def storage_path = context.ci_lfs_path end end end diff --git a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/packages.rb b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/packages.rb index 398f93af0406d..227633ad90a39 100644 --- a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/packages.rb +++ b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/packages.rb @@ -17,10 +17,7 @@ def target ::Backup::Targets::Files.new(nil, storage_path, options: options, excludes: ['tmp']) end - def storage_path - # TODO: Use configuration solver - Settings.packages.storage_path - end + def storage_path = context.packages_path end end end diff --git a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/pages.rb b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/pages.rb index 4c44ab600b32e..67816414f49c1 100644 --- a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/pages.rb +++ b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/pages.rb @@ -21,10 +21,7 @@ def target ::Backup::Targets::Files.new(nil, storage_path, options: options, excludes: [LEGACY_PAGES_TMP_PATH]) end - def storage_path - # TODO: Use configuration solver - Gitlab.config.pages.path - end + def storage_path = context.pages_path end end end diff --git a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/registry.rb b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/registry.rb index ee90782ce54d4..60f77e2494cbd 100644 --- a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/registry.rb +++ b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/registry.rb @@ -19,10 +19,7 @@ def target ::Backup::Targets::Files.new(nil, storage_path, options: options) end - def storage_path - # TODO: Use configuration solver - Settings.registry.path - end + def storage_path = context.registry_path end end end diff --git a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/terraform_state.rb b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/terraform_state.rb index 8504fd19bd8ea..f2eb31cd3de93 100644 --- a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/terraform_state.rb +++ b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/terraform_state.rb @@ -17,9 +17,7 @@ def target ::Backup::Targets::Files.new(nil, storage_path, options: options, excludes: ['tmp']) end - def storage_path - Settings.terraform_state.storage_path - end + def storage_path = context.terraform_state_path end end end diff --git a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/uploads.rb b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/uploads.rb index 6ca765e3ad2d1..c081394a17b46 100644 --- a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/uploads.rb +++ b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/tasks/uploads.rb @@ -17,9 +17,7 @@ def target ::Backup::Targets::Files.new(nil, storage_path, options: options, excludes: ['tmp']) end - def storage_path - File.join(Gitlab.config.uploads.storage_path, 'uploads') - end + def storage_path = context.upload_path end end end -- GitLab