Commit 0226a822 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '320786-add-a-rake-task-for-removing-migrated-object-storage-data' into 'master'

Move migrated? to PagesDeployment and add scope for finding migrated deployments

See merge request gitlab-org/gitlab!53711
parents bc52b2dc 4c9b2c39
......@@ -5,7 +5,6 @@ module Pages
include Gitlab::Utils::StrongMemoize
LegacyStorageDisabledError = Class.new(::StandardError)
MIGRATED_FILE_NAME = "_migrated.zip"
def initialize(project, trim_prefix: nil, domain: nil)
@project = project
......@@ -55,7 +54,7 @@ module Pages
return if deployment.file.file_storage? && !Feature.enabled?(:pages_serve_with_zip_file_protocol, project)
return if deployment.file.filename == MIGRATED_FILE_NAME && !Feature.enabled?(:pages_serve_from_migrated_zip, project)
return if deployment.migrated? && !Feature.enabled?(:pages_serve_from_migrated_zip, project)
global_id = ::Gitlab::GlobalId.build(deployment, id: deployment.id).to_s
......
......@@ -4,12 +4,15 @@
class PagesDeployment < ApplicationRecord
include FileStoreMounter
MIGRATED_FILE_NAME = "_migrated.zip"
attribute :file_store, :integer, default: -> { ::Pages::DeploymentUploader.default_store }
belongs_to :project, optional: false
belongs_to :ci_build, class_name: 'Ci::Build', optional: true
scope :older_than, -> (id) { where('id < ?', id) }
scope :migrated_from_legacy_storage, -> { where(file: MIGRATED_FILE_NAME) }
validates :file, presence: true
validates :file_store, presence: true, inclusion: { in: ObjectStorage::SUPPORTED_STORES }
......@@ -25,6 +28,10 @@ class PagesDeployment < ApplicationRecord
# this is to be adressed in https://gitlab.com/groups/gitlab-org/-/epics/589
end
def migrated?
file.filename == MIGRATED_FILE_NAME
end
private
def set_size
......
......@@ -124,43 +124,34 @@ RSpec.describe Pages::LookupPath do
include_examples 'uses disk storage'
end
end
context 'when deployment were created during migration' do
before do
FileUtils.mkdir_p File.join(project.pages_path, "public")
File.open(File.join(project.pages_path, "public/index.html"), "w") do |f|
f.write("Hello!")
context 'when deployment were created during migration' do
before do
allow(deployment).to receive(:migrated?).and_return(true)
end
expect(::Pages::MigrateLegacyStorageToDeploymentService.new(project).execute[:status]).to eq(:success)
project.reload
end
let(:deployment) { project.pages_metadatum.pages_deployment }
it 'uses deployment from object storage' do
freeze_time do
expect(source).to(
eq({
type: 'zip',
path: deployment.file.url(expire_at: 1.day.from_now),
global_id: "gid://gitlab/PagesDeployment/#{deployment.id}",
sha256: deployment.file_sha256,
file_size: deployment.size,
file_count: deployment.file_count
})
)
it 'uses deployment from object storage' do
freeze_time do
expect(source).to(
eq({
type: 'zip',
path: deployment.file.url(expire_at: 1.day.from_now),
global_id: "gid://gitlab/PagesDeployment/#{deployment.id}",
sha256: deployment.file_sha256,
file_size: deployment.size,
file_count: deployment.file_count
})
)
end
end
end
context 'when pages_serve_from_migrated_zip feature flag is disabled' do
before do
stub_feature_flags(pages_serve_from_migrated_zip: false)
end
context 'when pages_serve_from_migrated_zip feature flag is disabled' do
before do
stub_feature_flags(pages_serve_from_migrated_zip: false)
end
include_examples 'uses disk storage'
include_examples 'uses disk storage'
end
end
end
end
......
......@@ -26,6 +26,46 @@ RSpec.describe PagesDeployment do
end
end
describe '.migrated_from_legacy_storage' do
it 'only returns migrated deployments' do
project = create(:project)
migrated_deployment = create_migrated_deployment(project)
# create one other deployment
create(:pages_deployment, project: project)
expect(described_class.migrated_from_legacy_storage).to eq([migrated_deployment])
end
end
describe '#migrated?' do
it 'returns false for normal deployment' do
deployment = create(:pages_deployment)
expect(deployment.migrated?).to eq(false)
end
it 'returns true for migrated deployment' do
project = create(:project)
deployment = create_migrated_deployment(project)
expect(deployment.migrated?).to eq(true)
end
end
def create_migrated_deployment(project)
public_path = File.join(project.pages_path, "public")
FileUtils.mkdir_p(public_path)
File.open(File.join(project.pages_path, "public/index.html"), "w") do |f|
f.write("Hello!")
end
expect(::Pages::MigrateLegacyStorageToDeploymentService.new(project).execute[:status]).to eq(:success)
project.reload.pages_metadatum.pages_deployment
ensure
FileUtils.rm_rf(public_path)
end
describe 'default for file_store' do
let(:project) { create(:project) }
let(:deployment) do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment