-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): multi region blob support (#3653)
Co-authored-by: Iain Sproat <[email protected]>
- Loading branch information
1 parent
510a079
commit 8d0cbad
Showing
65 changed files
with
878 additions
and
452 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,28 @@ | |
"main": { | ||
"postgres": { | ||
"connectionUri": "postgresql://speckle:[email protected]:5432/speckle2_test" | ||
}, | ||
"blobStorage": { | ||
"accessKey": "minioadmin", | ||
"secretKey": "minioadmin", | ||
"bucket": "speckle-server", | ||
"createBucketIfNotExists": true, | ||
"endpoint": "http://127.0.0.1:9000", | ||
"s3Region": "us-east-1" | ||
} | ||
}, | ||
"regions": { | ||
"region1": { | ||
"postgres": { | ||
"connectionUri": "postgresql://speckle:[email protected]:5433/speckle2_test" | ||
}, | ||
"blobStorage": { | ||
"accessKey": "minioadmin", | ||
"secretKey": "minioadmin", | ||
"bucket": "speckle-server", | ||
"createBucketIfNotExists": true, | ||
"endpoint": "http://127.0.0.1:9020", | ||
"s3Region": "us-east-1" | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/server/modules/blobstorage/clients/objectStorage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { | ||
getS3AccessKey, | ||
getS3BucketName, | ||
getS3Endpoint, | ||
getS3Region, | ||
getS3SecretKey | ||
} from '@/modules/shared/helpers/envHelper' | ||
import { S3Client, S3ClientConfig } from '@aws-sdk/client-s3' | ||
import { Optional } from '@speckle/shared' | ||
|
||
export type ObjectStorage = { | ||
client: S3Client | ||
bucket: string | ||
} | ||
|
||
export type GetObjectStorageParams = { | ||
credentials: S3ClientConfig['credentials'] | ||
endpoint: S3ClientConfig['endpoint'] | ||
region: S3ClientConfig['region'] | ||
bucket: string | ||
} | ||
|
||
/** | ||
* Get object storage client | ||
*/ | ||
export const getObjectStorage = (params: GetObjectStorageParams): ObjectStorage => { | ||
const { bucket, credentials, endpoint, region } = params | ||
|
||
const config: S3ClientConfig = { | ||
credentials, | ||
endpoint, | ||
region, | ||
forcePathStyle: true | ||
} | ||
const client = new S3Client(config) | ||
return { client, bucket } | ||
} | ||
|
||
let mainObjectStorage: Optional<ObjectStorage> = undefined | ||
|
||
/** | ||
* Get main object storage client | ||
*/ | ||
export const getMainObjectStorage = (): ObjectStorage => { | ||
if (mainObjectStorage) return mainObjectStorage | ||
|
||
const mainParams: GetObjectStorageParams = { | ||
credentials: { | ||
accessKeyId: getS3AccessKey(), | ||
secretAccessKey: getS3SecretKey() | ||
}, | ||
endpoint: getS3Endpoint(), | ||
region: getS3Region(), | ||
bucket: getS3BucketName() | ||
} | ||
|
||
mainObjectStorage = getObjectStorage(mainParams) | ||
return mainObjectStorage | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/server/modules/blobstorage/domain/storageOperations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type stream from 'stream' | ||
import type { Readable } from 'stream' | ||
|
||
export type GetObjectStream = (params: { | ||
objectKey: string | ||
}) => Promise<stream.Readable> | ||
|
||
export type GetObjectAttributes = (params: { objectKey: string }) => Promise<{ | ||
fileSize: number | ||
}> | ||
|
||
type FileStream = string | Blob | Readable | Uint8Array | Buffer | ||
|
||
export type StoreFileStream = (args: { | ||
objectKey: string | ||
fileStream: FileStream | ||
}) => Promise<{ fileHash: string }> | ||
|
||
export type DeleteObject = (params: { objectKey: string }) => Promise<void> | ||
|
||
export type EnsureStorageAccess = (params: { | ||
createBucketIfNotExists: boolean | ||
}) => Promise<void> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.