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 d845bd2e573f604b0555a071868bf5d7a69bac4d..c5cc9b2caec62e716cd2d79dec72d7d06ed2c5c6 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,7 @@ class SourceContext DEFAULT_PAGES = 'pages/' DEFAULT_REGISTRY_PATH = 'registry/' DEFAULT_TERRAFORM_STATE_PATH = 'terraform_state/' + DEFAULT_UPLOADS_PATH = 'public/' # based on GitLab's root folder def gitlab_version File.read(gitlab_basepath.join("VERSION")).strip.freeze @@ -94,8 +95,10 @@ def terraform_state_path # Upload basepath def upload_path - # TODO: Use configuration solver - File.join(Gitlab.config.uploads.storage_path, 'uploads') + path = gitlab_config.dig(env, 'uploads', 'storage_path') || + gitlab_basepath.join(DEFAULT_UPLOADS_PATH) + + absolute_path(path).join('uploads') end def env diff --git a/gems/gitlab-backup-cli/spec/fixtures/gitlab.yml b/gems/gitlab-backup-cli/spec/fixtures/gitlab.yml index 2581e09b3a94b23423a0749d9ce380138a6d1c5d..b72c82705cf98d5215737b74a99c27b086b91d46 100644 --- a/gems/gitlab-backup-cli/spec/fixtures/gitlab.yml +++ b/gems/gitlab-backup-cli/spec/fixtures/gitlab.yml @@ -53,7 +53,7 @@ test: aws_secret_access_key: AWS_SECRET_ACCESS_KEY region: us-east-1 uploads: - storage_path: tmp/tests/public + storage_path: /tmp/gitlab/full/public object_store: enabled: false connection: diff --git a/gems/gitlab-backup-cli/spec/gitlab/backup/cli/source_context_spec.rb b/gems/gitlab-backup-cli/spec/gitlab/backup/cli/source_context_spec.rb index 3a8fa242c286091ed969d0f0b6fcd04fdac44e4e..431b7d3606e847edbde0b2102af6c223ed30c8df 100644 --- a/gems/gitlab-backup-cli/spec/gitlab/backup/cli/source_context_spec.rb +++ b/gems/gitlab-backup-cli/spec/gitlab/backup/cli/source_context_spec.rb @@ -251,6 +251,32 @@ end end + describe '#upload_path' do + context 'with a missing configuration value' do + it 'returns the default value in full path' do + use_gitlab_config_fixture('gitlab-missingconfigs.yml') + + expect(context.upload_path).to eq(fake_gitlab_basepath.join('public/uploads')) + end + end + + context 'with a relative path configured in gitlab.yml' do + it 'returns a full path based on gitlab basepath' do + use_gitlab_config_fixture('gitlab-relativepaths.yml') + + expect(context.upload_path).to eq(fake_gitlab_basepath.join('tmp/tests/public/uploads')) + end + end + + context 'with a full path configured in gitlab.yml' do + it 'returns a full path as configured in gitlab.yml' do + use_gitlab_config_fixture('gitlab.yml') + + expect(context.upload_path).to eq(Pathname('/tmp/gitlab/full/public/uploads')) + end + end + end + describe '#gitlab_shared_path' do context 'with shared path not configured in gitlab.yml' do it 'raises an error' do