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
58fb23cc
Commit
58fb23cc
authored
Oct 04, 2021
by
Marius Bobin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move the archive logic back into the lib/ directory
Move the archive logic back into the lib/ directory
parent
7ee5860a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
55 deletions
+59
-55
app/services/ci/archive_build_trace_service.rb
app/services/ci/archive_build_trace_service.rb
+0
-53
lib/gitlab/ci/trace.rb
lib/gitlab/ci/trace.rb
+1
-1
lib/gitlab/ci/trace/archive.rb
lib/gitlab/ci/trace/archive.rb
+57
-0
spec/lib/gitlab/ci/trace/archive_spec.rb
spec/lib/gitlab/ci/trace/archive_spec.rb
+1
-1
No files found.
app/services/ci/archive_build_trace_service.rb
deleted
100644 → 0
View file @
7ee5860a
# frozen_string_literal: true
module
Ci
class
ArchiveBuildTraceService
include
::
Gitlab
::
Utils
::
StrongMemoize
include
Checksummable
def
initialize
(
job
,
trace_metadata
)
@job
=
job
@trace_metadata
=
trace_metadata
end
def
execute!
(
stream
)
clone_file!
(
stream
,
JobArtifactUploader
.
workhorse_upload_path
)
do
|
clone_path
|
md5_checksum
=
self
.
class
.
md5_hexdigest
(
clone_path
)
sha256_checksum
=
self
.
class
.
sha256_hexdigest
(
clone_path
)
job
.
transaction
do
trace_artifact
=
create_build_trace!
(
clone_path
,
sha256_checksum
)
trace_metadata
.
track_archival!
(
trace_artifact
.
id
,
md5_checksum
)
end
end
end
private
attr_reader
:job
,
:trace_metadata
def
clone_file!
(
src_stream
,
temp_dir
)
FileUtils
.
mkdir_p
(
temp_dir
)
Dir
.
mktmpdir
(
"tmp-trace-
#{
job
.
id
}
"
,
temp_dir
)
do
|
dir_path
|
temp_path
=
File
.
join
(
dir_path
,
"job.log"
)
FileUtils
.
touch
(
temp_path
)
size
=
IO
.
copy_stream
(
src_stream
,
temp_path
)
raise
::
Gitlab
::
Ci
::
Trace
::
ArchiveError
,
'Failed to copy stream'
unless
size
==
src_stream
.
size
yield
(
temp_path
)
end
end
def
create_build_trace!
(
path
,
file_sha256
)
File
.
open
(
path
)
do
|
stream
|
# TODO: Set `file_format: :raw` after we've cleaned up legacy traces migration
# https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/20307
job
.
create_job_artifacts_trace!
(
project:
job
.
project
,
file_type: :trace
,
file:
stream
,
file_sha256:
file_sha256
)
end
end
end
end
lib/gitlab/ci/trace.rb
View file @
58fb23cc
...
...
@@ -236,7 +236,7 @@ module Gitlab
end
def
archive_stream!
(
stream
)
::
Ci
::
ArchiveBuildTraceServic
e
.
new
(
job
,
trace_metadata
).
execute!
(
stream
)
::
Gitlab
::
Ci
::
Trace
::
Archiv
e
.
new
(
job
,
trace_metadata
).
execute!
(
stream
)
end
def
trace_metadata
...
...
lib/gitlab/ci/trace/archive.rb
0 → 100644
View file @
58fb23cc
# frozen_string_literal: true
module
Gitlab
module
Ci
class
Trace
class
Archive
include
::
Gitlab
::
Utils
::
StrongMemoize
include
Checksummable
def
initialize
(
job
,
trace_metadata
)
@job
=
job
@trace_metadata
=
trace_metadata
end
def
execute!
(
stream
)
clone_file!
(
stream
,
JobArtifactUploader
.
workhorse_upload_path
)
do
|
clone_path
|
md5_checksum
=
self
.
class
.
md5_hexdigest
(
clone_path
)
sha256_checksum
=
self
.
class
.
sha256_hexdigest
(
clone_path
)
job
.
transaction
do
trace_artifact
=
create_build_trace!
(
clone_path
,
sha256_checksum
)
trace_metadata
.
track_archival!
(
trace_artifact
.
id
,
md5_checksum
)
end
end
end
private
attr_reader
:job
,
:trace_metadata
def
clone_file!
(
src_stream
,
temp_dir
)
FileUtils
.
mkdir_p
(
temp_dir
)
Dir
.
mktmpdir
(
"tmp-trace-
#{
job
.
id
}
"
,
temp_dir
)
do
|
dir_path
|
temp_path
=
File
.
join
(
dir_path
,
"job.log"
)
FileUtils
.
touch
(
temp_path
)
size
=
IO
.
copy_stream
(
src_stream
,
temp_path
)
raise
::
Gitlab
::
Ci
::
Trace
::
ArchiveError
,
'Failed to copy stream'
unless
size
==
src_stream
.
size
yield
(
temp_path
)
end
end
def
create_build_trace!
(
path
,
file_sha256
)
File
.
open
(
path
)
do
|
stream
|
# TODO: Set `file_format: :raw` after we've cleaned up legacy traces migration
# https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/20307
job
.
create_job_artifacts_trace!
(
project:
job
.
project
,
file_type: :trace
,
file:
stream
,
file_sha256:
file_sha256
)
end
end
end
end
end
end
spec/
services/ci/archive_build_trace_servic
e_spec.rb
→
spec/
lib/gitlab/ci/trace/archiv
e_spec.rb
View file @
58fb23cc
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
RSpec
.
describe
Ci
::
ArchiveBuildTraceServic
e
do
RSpec
.
describe
Gitlab
::
Ci
::
Trace
::
Archiv
e
do
let_it_be
(
:job
)
{
create
(
:ci_build
,
:success
,
:trace_live
)
}
let_it_be
(
:trace_metadata
)
{
create
(
:ci_build_trace_metadata
,
build:
job
)
}
let_it_be
(
:src_checksum
)
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