Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ce4bcf7c
Commit
ce4bcf7c
authored
Feb 09, 2021
by
Vladimir Shushlin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move migrated? logic to PagesDeployment
* also add scope for finding migrated deployments
parent
7a57eef4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
33 deletions
+67
-33
app/models/pages/lookup_path.rb
app/models/pages/lookup_path.rb
+1
-2
app/models/pages_deployment.rb
app/models/pages_deployment.rb
+7
-0
spec/models/pages/lookup_path_spec.rb
spec/models/pages/lookup_path_spec.rb
+22
-31
spec/models/pages_deployment_spec.rb
spec/models/pages_deployment_spec.rb
+37
-0
No files found.
app/models/pages/lookup_path.rb
View file @
ce4bcf7c
...
...
@@ -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
...
...
app/models/pages_deployment.rb
View file @
ce4bcf7c
...
...
@@ -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
...
...
spec/models/pages/lookup_path_spec.rb
View file @
ce4bcf7c
...
...
@@ -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
...
...
spec/models/pages_deployment_spec.rb
View file @
ce4bcf7c
...
...
@@ -26,6 +26,43 @@ 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
)
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!"
)
end
expect
(
::
Pages
::
MigrateLegacyStorageToDeploymentService
.
new
(
project
).
execute
[
:status
]).
to
eq
(
:success
)
project
.
reload
.
pages_metadatum
.
pages_deployment
end
describe
'default for file_store'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:deployment
)
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment