feat: option to skip s3 bucket creation (#852)

This commit is contained in:
Khor Shu Heng 2024-10-02 09:54:46 +08:00 committed by GitHub
parent f19e9b0498
commit 03fdcf4621
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 18 additions and 3 deletions

View File

@ -78,8 +78,12 @@ GOTRUE_EXTERNAL_APPLE_SECRET=
GOTRUE_EXTERNAL_APPLE_REDIRECT_URI=http://your-host/gotrue/callback
# File Storage
# This is where storage like images, files, etc. will be stored
# By default, Minio is used as the default file storage which uses host's file system
# Create the bucket if not exists on AppFlowy Cloud start up.
# Set this to false if the bucket has been created externally.
APPFLOWY_S3_CREATE_BUCKET=true
# This is where storage like images, files, etc. will be stored.
# By default, Minio is used as the default file storage which uses host's file system.
# Keep this as true if you are using other S3 compatible storage provider other than AWS.
APPFLOWY_S3_USE_MINIO=true
APPFLOWY_S3_MINIO_URL=http://minio:9000 # change this if you are using a different address for minio
APPFLOWY_S3_ACCESS_KEY=minioadmin

View File

@ -76,6 +76,7 @@ GOTRUE_EXTERNAL_APPLE_SECRET=
GOTRUE_EXTERNAL_APPLE_REDIRECT_URI=http://localhost:9999/callback
# File Storage
APPFLOWY_S3_CREATE_BUCKET=true
APPFLOWY_S3_USE_MINIO=true
APPFLOWY_S3_MINIO_URL=http://localhost:9000 # change this if you are using a different address for minio
APPFLOWY_S3_ACCESS_KEY=minioadmin

View File

@ -98,6 +98,7 @@ services:
- APPFLOWY_GOTRUE_EXT_URL=${API_EXTERNAL_URL}
- APPFLOWY_GOTRUE_ADMIN_EMAIL=${GOTRUE_ADMIN_EMAIL}
- APPFLOWY_GOTRUE_ADMIN_PASSWORD=${GOTRUE_ADMIN_PASSWORD}
- APPFLOWY_S3_CREATE_BUCKET=${APPFLOWY_S3_CREATE_BUCKET}
- APPFLOWY_S3_USE_MINIO=${APPFLOWY_S3_USE_MINIO}
- APPFLOWY_S3_MINIO_URL=${APPFLOWY_S3_MINIO_URL}
- APPFLOWY_S3_ACCESS_KEY=${APPFLOWY_S3_ACCESS_KEY}

View File

@ -461,7 +461,11 @@ pub async fn get_aws_s3_client(s3_setting: &S3Setting) -> Result<aws_sdk_s3::Cli
config_builder.build()
};
let client = aws_sdk_s3::Client::from_conf(config);
create_bucket_if_not_exists(&client, s3_setting).await?;
if s3_setting.create_bucket {
create_bucket_if_not_exists(&client, s3_setting).await?;
} else {
info!("Skipping bucket creation, assumed to be created externally");
}
Ok(client)
}

View File

@ -48,6 +48,7 @@ pub struct CasbinSetting {
#[derive(serde::Deserialize, Clone, Debug)]
pub struct S3Setting {
pub create_bucket: bool,
pub use_minio: bool,
pub minio_url: String,
pub access_key: String,
@ -205,6 +206,9 @@ pub fn get_configuration() -> Result<Config, anyhow::Error> {
},
redis_uri: get_env_var("APPFLOWY_REDIS_URI", "redis://localhost:6379").into(),
s3: S3Setting {
create_bucket: get_env_var("APPFLOWY_S3_CREATE_BUCKET", "true")
.parse()
.context("fail to get APPFLOWY_S3_CREATE_BUCKET")?,
use_minio: get_env_var("APPFLOWY_S3_USE_MINIO", "true")
.parse()
.context("fail to get APPFLOWY_S3_USE_MINIO")?,

View File

@ -37,6 +37,7 @@ impl Deref for TestBucket {
impl TestBucket {
pub async fn new() -> Self {
let setting = S3Setting {
create_bucket: true,
use_minio: true,
minio_url: LOCALHOST_MINIO_URL.to_string(),
access_key: LOCALHOST_MINIO_ACCESS_KEY.to_string(),