From b28fdb2ca464ef83c976acb0de04a2e4905dc951 Mon Sep 17 00:00:00 2001 From: YOCKOW Date: Tue, 31 Oct 2023 08:27:36 +0900 Subject: [PATCH] PDS: Allow configuring non-AWS S3 blob storage. (#1729) * PDS: Allow configuring non-AWS S3 blob storage. See https://github.com/bluesky-social/atproto/issues/1583 * tidy --------- Co-authored-by: devin ivy --- packages/pds/src/config/config.ts | 12 ++++++++++++ packages/pds/src/config/env.ts | 8 ++++++++ packages/pds/src/context.ts | 7 ++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/pds/src/config/config.ts b/packages/pds/src/config/config.ts index 58040abd781..ab43773dd8e 100644 --- a/packages/pds/src/config/config.ts +++ b/packages/pds/src/config/config.ts @@ -55,6 +55,15 @@ export const envToCfg = (env: ServerEnvironment): ServerConfig => { } if (env.blobstoreS3Bucket) { blobstoreCfg = { provider: 's3', bucket: env.blobstoreS3Bucket } + if (env.blobstoreS3Region) { + blobstoreCfg.region = env.blobstoreS3Region + } + if (env.blobstoreS3Endpoint) { + blobstoreCfg.endpoint = env.blobstoreS3Endpoint + } + if (env.blobstoreS3ForcePathStyle !== undefined) { + blobstoreCfg.forcePathStyle = env.blobstoreS3ForcePathStyle + } } else if (env.blobstoreDiskLocation) { blobstoreCfg = { provider: 'disk', @@ -238,6 +247,9 @@ export type PostgresConfig = { export type S3BlobstoreConfig = { provider: 's3' bucket: string + region?: string + endpoint?: string + forcePathStyle?: boolean } export type DiskBlobstoreConfig = { diff --git a/packages/pds/src/config/env.ts b/packages/pds/src/config/env.ts index 2c13124b4c9..3948d633883 100644 --- a/packages/pds/src/config/env.ts +++ b/packages/pds/src/config/env.ts @@ -24,6 +24,9 @@ export const readEnv = (): ServerEnvironment => { // blobstore: one required // s3 blobstoreS3Bucket: envStr('PDS_BLOBSTORE_S3_BUCKET'), + blobstoreS3Region: envStr('PDS_BLOBSTORE_S3_REGION'), + blobstoreS3Endpoint: envStr('PDS_BLOBSTORE_S3_ENDPOINT'), + blobstoreS3ForcePathStyle: envBool('PDS_BLOBSTORE_S3_FORCE_PATH_STYLE'), // disk blobstoreDiskLocation: envStr('PDS_BLOBSTORE_DISK_LOCATION'), blobstoreDiskTmpLocation: envStr('PDS_BLOBSTORE_DISK_TMP_LOCATION'), @@ -118,6 +121,11 @@ export type ServerEnvironment = { blobstoreDiskLocation?: string blobstoreDiskTmpLocation?: string + // -- optional s3 parameters + blobstoreS3Region?: string + blobstoreS3Endpoint?: string + blobstoreS3ForcePathStyle?: boolean + // identity didPlcUrl?: string didCacheStaleTTL?: number diff --git a/packages/pds/src/context.ts b/packages/pds/src/context.ts index b181ea8b3ad..dfa969e84f7 100644 --- a/packages/pds/src/context.ts +++ b/packages/pds/src/context.ts @@ -103,7 +103,12 @@ export class AppContext { }) const blobstore = cfg.blobstore.provider === 's3' - ? new S3BlobStore({ bucket: cfg.blobstore.bucket }) + ? new S3BlobStore({ + bucket: cfg.blobstore.bucket, + region: cfg.blobstore.region, + endpoint: cfg.blobstore.endpoint, + forcePathStyle: cfg.blobstore.forcePathStyle, + }) : await DiskBlobStore.create( cfg.blobstore.location, cfg.blobstore.tempLocation,