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
1b494305
Commit
1b494305
authored
Mar 07, 2018
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix tests and code to make it work properly
parent
6b3ef8d7
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
356 additions
and
64 deletions
+356
-64
app/controllers/projects/lfs_storage_controller.rb
app/controllers/projects/lfs_storage_controller.rb
+1
-1
config/gitlab.yml.example
config/gitlab.yml.example
+3
-3
config/initializers/carrierwave.rb
config/initializers/carrierwave.rb
+0
-12
ee/app/uploaders/object_storage.rb
ee/app/uploaders/object_storage.rb
+24
-16
ee/changelogs/unreleased/store-lfs-on-object-storage-by-default.yml
...ogs/unreleased/store-lfs-on-object-storage-by-default.yml
+5
-0
ee/spec/support/stub_object_storage.rb
ee/spec/support/stub_object_storage.rb
+3
-3
ee/spec/uploaders/object_storage_spec.rb
ee/spec/uploaders/object_storage_spec.rb
+309
-25
spec/lib/backup/manager_spec.rb
spec/lib/backup/manager_spec.rb
+4
-0
spec/requests/lfs_http_spec.rb
spec/requests/lfs_http_spec.rb
+5
-2
spec/uploaders/gitlab_uploader_spec.rb
spec/uploaders/gitlab_uploader_spec.rb
+2
-2
No files found.
app/controllers/projects/lfs_storage_controller.rb
View file @
1b494305
...
@@ -32,7 +32,7 @@ class Projects::LfsStorageController < Projects::GitHttpClientController
...
@@ -32,7 +32,7 @@ class Projects::LfsStorageController < Projects::GitHttpClientController
end
end
rescue
ActiveRecord
::
RecordInvalid
rescue
ActiveRecord
::
RecordInvalid
render_400
render_400
rescue
Argument
Error
rescue
ObjectStorage
::
RemoteStore
Error
render_lfs_forbidden
render_lfs_forbidden
end
end
...
...
config/gitlab.yml.example
View file @
1b494305
...
@@ -791,7 +791,7 @@ test:
...
@@ -791,7 +791,7 @@ test:
provider: AWS # Only AWS supported at the moment
provider: AWS # Only AWS supported at the moment
aws_access_key_id: AWS_ACCESS_KEY_ID
aws_access_key_id: AWS_ACCESS_KEY_ID
aws_secret_access_key: AWS_SECRET_ACCESS_KEY
aws_secret_access_key: AWS_SECRET_ACCESS_KEY
region:
eu-central
-1
region:
us-east
-1
artifacts:
artifacts:
path: tmp/tests/artifacts
path: tmp/tests/artifacts
enabled: true
enabled: true
...
@@ -805,7 +805,7 @@ test:
...
@@ -805,7 +805,7 @@ test:
provider: AWS # Only AWS supported at the moment
provider: AWS # Only AWS supported at the moment
aws_access_key_id: AWS_ACCESS_KEY_ID
aws_access_key_id: AWS_ACCESS_KEY_ID
aws_secret_access_key: AWS_SECRET_ACCESS_KEY
aws_secret_access_key: AWS_SECRET_ACCESS_KEY
region:
eu-central
-1
region:
us-east
-1
uploads:
uploads:
storage_path: tmp/tests/public
storage_path: tmp/tests/public
enabled: true
enabled: true
...
@@ -815,7 +815,7 @@ test:
...
@@ -815,7 +815,7 @@ test:
provider: AWS # Only AWS supported at the moment
provider: AWS # Only AWS supported at the moment
aws_access_key_id: AWS_ACCESS_KEY_ID
aws_access_key_id: AWS_ACCESS_KEY_ID
aws_secret_access_key: AWS_SECRET_ACCESS_KEY
aws_secret_access_key: AWS_SECRET_ACCESS_KEY
region:
eu-central
-1
region:
us-east
-1
gitlab:
gitlab:
host: localhost
host: localhost
port: 80
port: 80
...
...
config/initializers/carrierwave.rb
View file @
1b494305
...
@@ -28,16 +28,4 @@ if File.exist?(aws_file)
...
@@ -28,16 +28,4 @@ if File.exist?(aws_file)
# when fog_public is false and provider is AWS or Google, defaults to 600
# when fog_public is false and provider is AWS or Google, defaults to 600
config
.
fog_authenticated_url_expiration
=
1
<<
29
config
.
fog_authenticated_url_expiration
=
1
<<
29
end
end
# Mocking Fog requests, based on: https://github.com/carrierwaveuploader/carrierwave/wiki/How-to%3A-Test-Fog-based-uploaders
if
Rails
.
env
.
test?
Fog
.
mock!
connection
=
::
Fog
::
Storage
.
new
(
aws_access_key_id:
AWS_CONFIG
[
'access_key_id'
],
aws_secret_access_key:
AWS_CONFIG
[
'secret_access_key'
],
provider:
'AWS'
,
region:
AWS_CONFIG
[
'region'
]
)
connection
.
directories
.
create
(
key:
AWS_CONFIG
[
'bucket'
])
end
end
end
ee/app/uploaders/object_storage.rb
View file @
1b494305
...
@@ -163,8 +163,6 @@ module ObjectStorage
...
@@ -163,8 +163,6 @@ module ObjectStorage
File
.
join
(
self
.
root
,
TMP_UPLOAD_PATH
)
File
.
join
(
self
.
root
,
TMP_UPLOAD_PATH
)
end
end
private
def
workhorse_remote_upload_options
def
workhorse_remote_upload_options
return
unless
self
.
object_store_enabled?
return
unless
self
.
object_store_enabled?
return
unless
self
.
direct_upload_enabled?
return
unless
self
.
direct_upload_enabled?
...
@@ -230,10 +228,6 @@ module ObjectStorage
...
@@ -230,10 +228,6 @@ module ObjectStorage
end
end
end
end
def
filename
super
||
file
&
.
filename
end
#
#
# Move the file to another store
# Move the file to another store
#
#
...
@@ -302,7 +296,7 @@ module ObjectStorage
...
@@ -302,7 +296,7 @@ module ObjectStorage
elsif
local_path
=
params
[
"
#{
identifier
}
.path"
]
elsif
local_path
=
params
[
"
#{
identifier
}
.path"
]
store_local_file!
(
local_path
,
filename
)
store_local_file!
(
local_path
,
filename
)
else
else
raise
Argument
Error
,
'Bad file'
raise
RemoteStore
Error
,
'Bad file'
end
end
end
end
...
@@ -316,30 +310,44 @@ module ObjectStorage
...
@@ -316,30 +310,44 @@ module ObjectStorage
end
end
def
store_remote_file!
(
remote_object_id
,
filename
)
def
store_remote_file!
(
remote_object_id
,
filename
)
raise
RemoteStoreError
,
'Missing filename'
unless
filename
file_path
=
File
.
join
(
TMP_UPLOAD_PATH
,
remote_object_id
)
file_path
=
File
.
join
(
TMP_UPLOAD_PATH
,
remote_object_id
)
raise
ArgumentError
,
'Bad file path'
unless
file_path
.
start_with?
(
TMP_UPLOAD_PATH
+
'/'
)
file_path
=
Pathname
.
new
(
file_path
).
cleanpath
.
to_s
raise
RemoteStoreError
,
'Bad file path'
unless
file_path
.
start_with?
(
TMP_UPLOAD_PATH
+
'/'
)
self
.
object_store
=
Store
::
REMOTE
self
.
object_store
=
Store
::
REMOTE
self
.
original_filename
=
filename
# TODO:
# This should be changed to make use of `tmp/cache` mechanism
# instead of using custom upload directory,
# using tmp/cache makes this implementation way easier than it is today
CarrierWave
::
Storage
::
Fog
::
File
.
new
(
self
,
storage
,
file_path
).
tap
do
|
file
|
CarrierWave
::
Storage
::
Fog
::
File
.
new
(
self
,
storage
,
file_path
).
tap
do
|
file
|
raise
Argument
Error
,
'Missing file'
unless
file
.
exists?
raise
RemoteStore
Error
,
'Missing file'
unless
file
.
exists?
storage
.
store!
(
file
)
self
.
filename
=
filename
self
.
file
=
storage
.
store!
(
file
)
end
end
end
end
def
store_local_file!
(
local_path
,
filename
)
def
store_local_file!
(
local_path
,
filename
)
raise
RemoteStoreError
,
'Missing filename'
unless
filename
root_path
=
File
.
realpath
(
self
.
class
.
workhorse_local_upload_path
)
root_path
=
File
.
realpath
(
self
.
class
.
workhorse_local_upload_path
)
file_path
=
File
.
realpath
(
local_path
)
file_path
=
File
.
realpath
(
local_path
)
raise
Argument
Error
,
'Bad file path'
unless
file_path
.
start_with?
(
root_path
)
raise
RemoteStore
Error
,
'Bad file path'
unless
file_path
.
start_with?
(
root_path
)
self
.
object_store
=
Store
::
LOCAL
self
.
object_store
=
Store
::
LOCAL
self
.
original_filename
=
filename
self
.
store!
(
UploadedFile
.
new
(
file_path
,
filename
))
end
File
.
open
(
local_path
)
do
|
file
|
# allow to configure and overwrite the filename
self
.
store!
(
file
)
def
filename
end
@filename
||
super
||
file
&
.
filename
# rubocop:disable Gitlab/ModuleWithInstanceVariables
end
def
filename
=
(
filename
)
@filename
=
filename
# rubocop:disable Gitlab/ModuleWithInstanceVariables
end
end
# this is a hack around CarrierWave. The #migrate method needs to be
# this is a hack around CarrierWave. The #migrate method needs to be
...
...
ee/changelogs/unreleased/store-lfs-on-object-storage-by-default.yml
0 → 100644
View file @
1b494305
---
title
:
Add support for direct uploading of LFS artifacts
merge_request
:
author
:
type
:
added
ee/spec/support/stub_object_storage.rb
View file @
1b494305
module
StubConfiguration
module
StubConfiguration
def
stub_object_storage_uploader
(
def
stub_object_storage_uploader
(
config
:,
uploader
:,
remote_directory
:,
enabled:
true
,
licensed:
true
,
config
:,
uploader
:,
remote_directory
:,
enabled:
true
,
licensed:
true
,
background_upload:
false
,
direct_upload:
false
background_upload:
false
,
direct_upload:
false
)
)
Fog
.
mock!
allow
(
config
).
to
receive
(
:enabled
)
{
enabled
}
allow
(
config
).
to
receive
(
:enabled
)
{
enabled
}
allow
(
config
).
to
receive
(
:background_upload
)
{
background_upload
}
allow
(
config
).
to
receive
(
:background_upload
)
{
background_upload
}
allow
(
config
).
to
receive
(
:direct_upload
)
{
direct_upload
}
allow
(
config
).
to
receive
(
:direct_upload
)
{
direct_upload
}
...
@@ -13,6 +11,8 @@ module StubConfiguration
...
@@ -13,6 +11,8 @@ module StubConfiguration
return
unless
enabled
return
unless
enabled
Fog
.
mock!
::
Fog
::
Storage
.
new
(
uploader
.
object_store_credentials
).
tap
do
|
connection
|
::
Fog
::
Storage
.
new
(
uploader
.
object_store_credentials
).
tap
do
|
connection
|
begin
begin
connection
.
directories
.
create
(
key:
remote_directory
)
connection
.
directories
.
create
(
key:
remote_directory
)
...
...
ee/spec/uploaders/object_storage_spec.rb
View file @
1b494305
This diff is collapsed.
Click to expand it.
spec/lib/backup/manager_spec.rb
View file @
1b494305
...
@@ -278,6 +278,10 @@ describe Backup::Manager do
...
@@ -278,6 +278,10 @@ describe Backup::Manager do
connection
.
directories
.
create
(
key:
Gitlab
.
config
.
backup
.
upload
.
remote_directory
)
connection
.
directories
.
create
(
key:
Gitlab
.
config
.
backup
.
upload
.
remote_directory
)
end
end
after
do
Fog
.
unmock!
end
context
'target path'
do
context
'target path'
do
it
'uses the tar filename by default'
do
it
'uses the tar filename by default'
do
expect_any_instance_of
(
Fog
::
Collection
).
to
receive
(
:create
)
expect_any_instance_of
(
Fog
::
Collection
).
to
receive
(
:create
)
...
...
spec/requests/lfs_http_spec.rb
View file @
1b494305
...
@@ -1104,7 +1104,9 @@ describe 'Git LFS API and storage' do
...
@@ -1104,7 +1104,9 @@ describe 'Git LFS API and storage' do
end
end
subject
do
subject
do
put_finalize_with_args
(
'file.object_id'
=>
'12312300'
)
put_finalize_with_args
(
'file.object_id'
=>
'12312300'
,
'file.name'
=>
'name'
)
end
end
it
'responds with status 200'
do
it
'responds with status 200'
do
...
@@ -1364,7 +1366,8 @@ describe 'Git LFS API and storage' do
...
@@ -1364,7 +1366,8 @@ describe 'Git LFS API and storage' do
end
end
args
=
{
args
=
{
'file.path'
=>
file_path
'file.path'
=>
file_path
,
'file.name'
=>
File
.
basename
(
file_path
)
}.
compact
}.
compact
put_finalize_with_args
(
args
)
put_finalize_with_args
(
args
)
...
...
spec/uploaders/gitlab_uploader_spec.rb
View file @
1b494305
...
@@ -27,7 +27,7 @@ describe GitlabUploader do
...
@@ -27,7 +27,7 @@ describe GitlabUploader do
describe
'#file_cache_storage?'
do
describe
'#file_cache_storage?'
do
context
'when file storage is used'
do
context
'when file storage is used'
do
before
do
before
do
uploader_class
.
cache_storage
(
:file
)
expect
(
uploader_class
).
to
receive
(
:cache_storage
)
{
CarrierWave
::
Storage
::
File
}
end
end
it
{
is_expected
.
to
be_file_cache_storage
}
it
{
is_expected
.
to
be_file_cache_storage
}
...
@@ -35,7 +35,7 @@ describe GitlabUploader do
...
@@ -35,7 +35,7 @@ describe GitlabUploader do
context
'when is remote storage'
do
context
'when is remote storage'
do
before
do
before
do
uploader_class
.
cache_storage
(
:fog
)
expect
(
uploader_class
).
to
receive
(
:cache_storage
)
{
CarrierWave
::
Storage
::
Fog
}
end
end
it
{
is_expected
.
not_to
be_file_cache_storage
}
it
{
is_expected
.
not_to
be_file_cache_storage
}
...
...
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