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
c9d49656
Commit
c9d49656
authored
Dec 07, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use run_after_commit on object to schedule background upload
parent
6d50d30c
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
124 additions
and
42 deletions
+124
-42
app/models/ci/job_artifact.rb
app/models/ci/job_artifact.rb
+6
-0
app/models/lfs_object.rb
app/models/lfs_object.rb
+6
-0
app/uploaders/job_artifact_uploader.rb
app/uploaders/job_artifact_uploader.rb
+0
-1
app/uploaders/lfs_object_uploader.rb
app/uploaders/lfs_object_uploader.rb
+0
-1
ee/app/uploaders/object_store_uploader.rb
ee/app/uploaders/object_store_uploader.rb
+5
-7
spec/ee/spec/models/ee/lfs_object_spec.rb
spec/ee/spec/models/ee/lfs_object_spec.rb
+60
-0
spec/models/ci/job_artifact_spec.rb
spec/models/ci/job_artifact_spec.rb
+36
-16
spec/requests/api/runner_spec.rb
spec/requests/api/runner_spec.rb
+7
-13
spec/requests/lfs_http_spec.rb
spec/requests/lfs_http_spec.rb
+1
-1
spec/support/stub_object_storage.rb
spec/support/stub_object_storage.rb
+2
-2
spec/uploaders/lfs_object_uploader_spec.rb
spec/uploaders/lfs_object_uploader_spec.rb
+1
-1
No files found.
app/models/ci/job_artifact.rb
View file @
c9d49656
...
@@ -10,6 +10,12 @@ module Ci
...
@@ -10,6 +10,12 @@ module Ci
mount_uploader
:file
,
JobArtifactUploader
mount_uploader
:file
,
JobArtifactUploader
after_save
if: :file_changed?
,
on:
[
:create
,
:update
]
do
run_after_commit
do
file
.
schedule_migration_to_object_storage
end
end
enum
file_type:
{
enum
file_type:
{
archive:
1
,
archive:
1
,
metadata:
2
metadata:
2
...
...
app/models/lfs_object.rb
View file @
c9d49656
...
@@ -11,6 +11,12 @@ class LfsObject < ActiveRecord::Base
...
@@ -11,6 +11,12 @@ class LfsObject < ActiveRecord::Base
mount_uploader
:file
,
LfsObjectUploader
mount_uploader
:file
,
LfsObjectUploader
after_save
if: :file_changed?
,
on:
[
:create
,
:update
]
do
run_after_commit
do
file
.
schedule_migration_to_object_storage
end
end
def
project_allowed_access?
(
project
)
def
project_allowed_access?
(
project
)
projects
.
exists?
(
project
.
lfs_storage_project
.
id
)
projects
.
exists?
(
project
.
lfs_storage_project
.
id
)
end
end
...
...
app/uploaders/job_artifact_uploader.rb
View file @
c9d49656
class
JobArtifactUploader
<
ObjectStoreUploader
class
JobArtifactUploader
<
ObjectStoreUploader
storage_options
Gitlab
.
config
.
artifacts
storage_options
Gitlab
.
config
.
artifacts
after
:store
,
:schedule_migration_to_object_storage
def
self
.
local_store_path
def
self
.
local_store_path
Gitlab
.
config
.
artifacts
.
path
Gitlab
.
config
.
artifacts
.
path
...
...
app/uploaders/lfs_object_uploader.rb
View file @
c9d49656
class
LfsObjectUploader
<
ObjectStoreUploader
class
LfsObjectUploader
<
ObjectStoreUploader
storage_options
Gitlab
.
config
.
lfs
storage_options
Gitlab
.
config
.
lfs
after
:store
,
:schedule_migration_to_object_storage
def
self
.
local_store_path
def
self
.
local_store_path
Gitlab
.
config
.
lfs
.
storage_path
Gitlab
.
config
.
lfs
.
storage_path
...
...
ee/app/uploaders/object_store_uploader.rb
View file @
c9d49656
...
@@ -117,14 +117,12 @@ class ObjectStoreUploader < CarrierWave::Uploader::Base
...
@@ -117,14 +117,12 @@ class ObjectStoreUploader < CarrierWave::Uploader::Base
end
end
def
schedule_migration_to_object_storage
(
*
args
)
def
schedule_migration_to_object_storage
(
*
args
)
if
self
.
class
.
object_store_enabled?
&&
licensed?
&&
file_storage?
return
unless
self
.
class
.
object_store_enabled?
uploader
=
self
return
unless
self
.
class
.
background_upload_enabled?
mount_field
=
mounted_as
return
unless
self
.
licensed?
return
unless
self
.
file_storage?
model
.
run_after_commit
do
ObjectStorageUploadWorker
.
perform_async
(
self
.
class
.
name
,
model
.
class
.
name
,
mounted_as
,
model
.
id
)
ObjectStorageUploadWorker
.
perform_async
(
uploader
.
class
.
name
,
self
.
class
.
name
,
mount_field
,
id
)
end
end
end
end
def
fog_directory
def
fog_directory
...
...
spec/ee/spec/models/ee/lfs_object_spec.rb
View file @
c9d49656
...
@@ -33,4 +33,64 @@ describe LfsObject do
...
@@ -33,4 +33,64 @@ describe LfsObject do
end
end
end
end
end
end
describe
'#schedule_migration_to_object_storage'
do
before
do
stub_lfs_setting
(
enabled:
true
)
end
subject
{
create
(
:lfs_object
,
:with_file
)
}
context
'when object storage is disabled'
do
before
do
stub_lfs_object_storage
(
enabled:
false
)
end
it
'does not schedule the migration'
do
expect
(
ObjectStorageUploadWorker
).
not_to
receive
(
:perform_async
)
subject
end
end
context
'when object storage is enabled'
do
context
'when background upload is enabled'
do
context
'when is licensed'
do
before
do
stub_lfs_object_storage
(
background_upload:
true
)
end
it
'schedules the model for migration'
do
expect
(
ObjectStorageUploadWorker
).
to
receive
(
:perform_async
).
with
(
'LfsObjectUploader'
,
described_class
.
name
,
:file
,
kind_of
(
Numeric
))
subject
end
end
context
'when is unlicensed'
do
before
do
stub_lfs_object_storage
(
background_upload:
true
,
licensed:
false
)
end
it
'does not schedule the migration'
do
expect
(
ObjectStorageUploadWorker
).
not_to
receive
(
:perform_async
)
subject
end
end
end
context
'when background upload is disabled'
do
before
do
stub_lfs_object_storage
(
background_upload:
false
)
end
it
'schedules the model for migration'
do
expect
(
ObjectStorageUploadWorker
).
not_to
receive
(
:perform_async
)
subject
end
end
end
end
end
end
spec/models/ci/job_artifact_spec.rb
View file @
c9d49656
...
@@ -17,6 +17,10 @@ describe Ci::JobArtifact do
...
@@ -17,6 +17,10 @@ describe Ci::JobArtifact do
describe
'#schedule_migration_to_object_storage'
do
describe
'#schedule_migration_to_object_storage'
do
context
'when object storage is disabled'
do
context
'when object storage is disabled'
do
before
do
stub_artifacts_object_storage
(
enabled:
false
)
end
it
'does not schedule the migration'
do
it
'does not schedule the migration'
do
expect
(
ObjectStorageUploadWorker
).
not_to
receive
(
:perform_async
)
expect
(
ObjectStorageUploadWorker
).
not_to
receive
(
:perform_async
)
...
@@ -25,8 +29,10 @@ describe Ci::JobArtifact do
...
@@ -25,8 +29,10 @@ describe Ci::JobArtifact do
end
end
context
'when object storage is enabled'
do
context
'when object storage is enabled'
do
context
'when background upload is enabled'
do
context
'when is licensed'
do
before
do
before
do
stub_artifacts_object_storage
stub_artifacts_object_storage
(
background_upload:
true
)
end
end
it
'schedules the model for migration'
do
it
'schedules the model for migration'
do
...
@@ -36,9 +42,9 @@ describe Ci::JobArtifact do
...
@@ -36,9 +42,9 @@ describe Ci::JobArtifact do
end
end
end
end
context
'when object storage
is unlicensed'
do
context
'when
is unlicensed'
do
before
do
before
do
stub_artifacts_object_storage
(
licensed:
false
)
stub_artifacts_object_storage
(
background_upload:
true
,
licensed:
false
)
end
end
it
'does not schedule the migration'
do
it
'does not schedule the migration'
do
...
@@ -48,6 +54,20 @@ describe Ci::JobArtifact do
...
@@ -48,6 +54,20 @@ describe Ci::JobArtifact do
end
end
end
end
end
end
context
'when background upload is disabled'
do
before
do
stub_artifacts_object_storage
(
background_upload:
false
)
end
it
'schedules the model for migration'
do
expect
(
ObjectStorageUploadWorker
).
not_to
receive
(
:perform_async
)
subject
end
end
end
end
end
end
describe
'#set_size'
do
describe
'#set_size'
do
...
...
spec/requests/api/runner_spec.rb
View file @
c9d49656
...
@@ -1085,8 +1085,6 @@ describe API::Runner do
...
@@ -1085,8 +1085,6 @@ describe API::Runner do
let
(
:stored_artifacts_size
)
{
job
.
reload
.
artifacts_size
}
let
(
:stored_artifacts_size
)
{
job
.
reload
.
artifacts_size
}
before
do
before
do
stub_artifacts_object_storage
(
enabled:
false
)
post
(
api
(
"/jobs/
#{
job
.
id
}
/artifacts"
),
post_data
,
headers_with_token
)
post
(
api
(
"/jobs/
#{
job
.
id
}
/artifacts"
),
post_data
,
headers_with_token
)
end
end
...
@@ -1156,6 +1154,13 @@ describe API::Runner do
...
@@ -1156,6 +1154,13 @@ describe API::Runner do
context
'when job has artifacts'
do
context
'when job has artifacts'
do
let
(
:job
)
{
create
(
:ci_build
)
}
let
(
:job
)
{
create
(
:ci_build
)
}
let
(
:store
)
{
JobArtifactUploader
::
LOCAL_STORE
}
before
do
create
(
:ci_job_artifact
,
:archive
,
file_store:
store
,
job:
job
)
download_artifact
end
context
'when using job token'
do
context
'when using job token'
do
context
'when artifacts are stored locally'
do
context
'when artifacts are stored locally'
do
...
@@ -1165,11 +1170,6 @@ describe API::Runner do
...
@@ -1165,11 +1170,6 @@ describe API::Runner do
end
end
it
'download artifacts'
do
it
'download artifacts'
do
stub_artifacts_object_storage
(
enabled:
false
)
create
(
:ci_job_artifact
,
:archive
,
job:
job
)
download_artifact
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
.
headers
).
to
include
download_headers
expect
(
response
.
headers
).
to
include
download_headers
end
end
...
@@ -1180,10 +1180,6 @@ describe API::Runner do
...
@@ -1180,10 +1180,6 @@ describe API::Runner do
let!
(
:job
)
{
create
(
:ci_build
)
}
let!
(
:job
)
{
create
(
:ci_build
)
}
it
'download artifacts'
do
it
'download artifacts'
do
create
(
:ci_job_artifact
,
:archive
,
:remote_store
,
job:
job
)
download_artifact
expect
(
response
).
to
have_gitlab_http_status
(
302
)
expect
(
response
).
to
have_gitlab_http_status
(
302
)
end
end
end
end
...
@@ -1193,8 +1189,6 @@ describe API::Runner do
...
@@ -1193,8 +1189,6 @@ describe API::Runner do
let
(
:token
)
{
job
.
project
.
runners_token
}
let
(
:token
)
{
job
.
project
.
runners_token
}
it
'responds with forbidden'
do
it
'responds with forbidden'
do
download_artifact
expect
(
response
).
to
have_gitlab_http_status
(
403
)
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
end
end
...
...
spec/requests/lfs_http_spec.rb
View file @
c9d49656
...
@@ -1038,7 +1038,7 @@ describe 'Git LFS API and storage' do
...
@@ -1038,7 +1038,7 @@ describe 'Git LFS API and storage' do
context
'with object storage enabled'
do
context
'with object storage enabled'
do
before
do
before
do
stub_lfs_object_storage
stub_lfs_object_storage
(
background_upload:
true
)
end
end
it
'schedules migration of file to object storage'
do
it
'schedules migration of file to object storage'
do
...
...
spec/support/stub_object_storage.rb
View file @
c9d49656
module
StubConfiguration
module
StubConfiguration
def
stub_object_storage_uploader
(
config
:,
uploader
:,
remote_directory
:,
enabled:
true
,
licensed:
true
,
background_upload:
nil
)
def
stub_object_storage_uploader
(
config
:,
uploader
:,
remote_directory
:,
enabled:
true
,
licensed:
true
,
background_upload:
false
)
Fog
.
mock!
Fog
.
mock!
allow
(
config
).
to
receive
(
:enabled
)
{
enabled
}
allow
(
config
).
to
receive
(
:enabled
)
{
enabled
}
allow
(
config
).
to
receive
(
:background_upload
)
{
background_upload
}
if
background_upload
allow
(
config
).
to
receive
(
:background_upload
)
{
background_upload
}
stub_licensed_features
(
object_storage:
licensed
)
unless
licensed
==
:skip
stub_licensed_features
(
object_storage:
licensed
)
unless
licensed
==
:skip
...
...
spec/uploaders/lfs_object_uploader_spec.rb
View file @
c9d49656
...
@@ -49,7 +49,7 @@ describe LfsObjectUploader do
...
@@ -49,7 +49,7 @@ describe LfsObjectUploader do
context
'with object storage enabled'
do
context
'with object storage enabled'
do
before
do
before
do
stub_lfs_object_storage
stub_lfs_object_storage
(
background_upload:
true
)
end
end
it
'is scheduled to run after creation'
do
it
'is scheduled to run after creation'
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