Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
console
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
console
Commits
8e296906
Commit
8e296906
authored
Feb 09, 2024
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
skew ahead time for uploads
parent
43fc3693
Pipeline
#25375
passed with stages
in 4 minutes and 5 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
21 deletions
+35
-21
console-api/src/packager/packager.service.ts
console-api/src/packager/packager.service.ts
+2
-2
console-api/src/s3/s3.service.ts
console-api/src/s3/s3.service.ts
+33
-19
No files found.
console-api/src/packager/packager.service.ts
View file @
8e296906
...
...
@@ -271,7 +271,7 @@ export class PackagerService extends ConsoleLogger {
let
tmpFilename
:
string
;
try
{
if
(
files
.
length
>
2000
)
{
/*
if (files.length > 2000) {
// minio would skew the stream if it's too slow
// use a tmp file to put the stream
...
...
@@ -286,7 +286,7 @@ export class PackagerService extends ConsoleLogger {
});
// open the tmp file as a new stream
uploadStream = fs.createReadStream(tmpFilename);
}
}
*/
const
uploadPromise
=
this
.
s3
.
uploadStream
(
archiveName
,
uploadStream
,
{
ContentType
:
'
application/tar+zstd
'
,
...
...
console-api/src/s3/s3.service.ts
View file @
8e296906
import
{
ConsoleLogger
}
from
'
@nestjs/common
'
;
import
{
ConfigService
}
from
'
@nestjs/config
'
;
import
{
_Object
,
DeleteObjectsCommand
,
ListObjectsCommand
,
PutObjectCommand
,
PutObjectCommandInput
,
S3Client
}
from
'
@aws-sdk/client-s3
'
;
import
{
_Object
,
DeleteObjectsCommand
,
ListObjectsCommand
,
PutObjectCommand
,
PutObjectCommandInput
,
S3Client
,
S3ClientConfig
,
}
from
'
@aws-sdk/client-s3
'
;
import
{
createHash
}
from
'
crypto
'
;
import
internal
from
'
stream
'
;
import
{
Upload
}
from
'
@aws-sdk/lib-storage
'
;
...
...
@@ -11,11 +19,6 @@ export interface S3StreamUploadResult {
}
export
class
S3Service
extends
ConsoleLogger
{
private
readonly
bucket
:
string
;
private
readonly
prefix
:
string
;
public
readonly
cdnUrl
:
string
;
private
readonly
s3
:
S3Client
;
private
getConfig
(
field
:
string
)
{
return
this
.
config
.
get
(
`
${
this
.
servicePrefix
}
_
${
field
}
`
)
||
this
.
config
.
get
(
field
);
}
...
...
@@ -24,20 +27,31 @@ export class S3Service extends ConsoleLogger {
return
`
${
this
.
cdnUrl
}
/
${
path
}
`
;
}
private
readonly
bucket
=
this
.
getConfig
(
'
S3_BUCKET
'
);
private
readonly
prefix
=
this
.
getConfig
(
'
S3_PREFIX
'
);
public
readonly
cdnUrl
=
this
.
getConfig
(
'
S3_CDN_URL
'
)
||
`
${
this
.
getConfig
(
'
S3_ENDPOINT
'
)}
/
${
this
.
bucket
}${
this
.
prefix
?
`/
${
this
.
prefix
}
`
:
''
}
`
;
private
readonly
s3Config
:
S3ClientConfig
=
{
credentials
:
{
accessKeyId
:
this
.
getConfig
(
'
S3_KEY
'
),
secretAccessKey
:
this
.
getConfig
(
'
S3_SECRET
'
),
},
region
:
this
.
getConfig
(
'
S3_REGION
'
)
||
'
us-west-1
'
,
endpoint
:
this
.
getConfig
(
'
S3_ENDPOINT
'
),
forcePathStyle
:
true
,
};
private
readonly
s3ConfigSkewed
:
S3ClientConfig
=
{
...
this
.
s3Config
,
// skew 14 mins ahead for long upload
systemClockOffset
:
14
*
60
*
1000
,
};
private
readonly
s3
=
new
S3Client
(
this
.
s3Config
);
private
readonly
skewedS3
=
new
S3Client
(
this
.
s3ConfigSkewed
);
constructor
(
private
servicePrefix
:
string
,
private
config
:
ConfigService
)
{
super
(
`
${
servicePrefix
}
s3`
);
this
.
bucket
=
this
.
getConfig
(
'
S3_BUCKET
'
);
this
.
prefix
=
this
.
getConfig
(
'
S3_PREFIX
'
);
this
.
cdnUrl
=
this
.
getConfig
(
'
S3_CDN_URL
'
)
||
`
${
this
.
getConfig
(
'
S3_ENDPOINT
'
)}
/
${
this
.
bucket
}${
this
.
prefix
?
`/
${
this
.
prefix
}
`
:
''
}
`
;
this
.
s3
=
new
S3Client
({
credentials
:
{
accessKeyId
:
this
.
getConfig
(
'
S3_KEY
'
),
secretAccessKey
:
this
.
getConfig
(
'
S3_SECRET
'
),
},
region
:
this
.
getConfig
(
'
S3_REGION
'
)
||
'
us-west-1
'
,
endpoint
:
this
.
getConfig
(
'
S3_ENDPOINT
'
),
forcePathStyle
:
true
,
});
}
async
listObjects
(
path
:
string
)
{
...
...
@@ -115,7 +129,7 @@ export class S3Service extends ConsoleLogger {
async
uploadStream
(
path
:
string
,
stream
:
internal
.
Readable
,
extras
:
Partial
<
PutObjectCommandInput
>
=
{})
{
const
key
=
this
.
getPathWithPrefix
(
path
);
const
upload
=
new
Upload
({
client
:
this
.
s3
,
client
:
this
.
s
kewedS
3
,
params
:
{
Bucket
:
this
.
bucket
,
Key
:
key
,
...
...
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