mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FEATURE: Add custom S3 Endpoint and DigitalOcean Spaces/Minio support for Backups (#6045)
- Add custom S3 Endpoints and DigitalOcean Spaces support - Add Minio support using 'force_path_style' option and fix uploads to custom endpoint
This commit is contained in:
parent
767395449f
commit
a6c589d882
5 changed files with 32 additions and 7 deletions
|
@ -128,6 +128,14 @@ class SiteSetting < ActiveRecord::Base
|
||||||
SiteSetting.enable_s3_uploads ? SiteSetting.s3_upload_bucket : GlobalSetting.s3_bucket
|
SiteSetting.enable_s3_uploads ? SiteSetting.s3_upload_bucket : GlobalSetting.s3_bucket
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.s3_endpoint
|
||||||
|
SiteSetting.enable_s3_uploads ? SiteSetting.s3_endpoint : GlobalSetting.s3_endpoint
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.s3_force_path_style
|
||||||
|
SiteSetting.enable_s3_uploads ? SiteSetting.s3_force_path_style : GlobalSetting.s3_force_path_style
|
||||||
|
end
|
||||||
|
|
||||||
def self.enable_s3_uploads
|
def self.enable_s3_uploads
|
||||||
SiteSetting.enable_s3_uploads || GlobalSetting.use_s3?
|
SiteSetting.enable_s3_uploads || GlobalSetting.use_s3?
|
||||||
end
|
end
|
||||||
|
@ -138,9 +146,11 @@ class SiteSetting < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.absolute_base_url
|
def self.absolute_base_url
|
||||||
|
url_basename = SiteSetting.s3_endpoint.split('/')[-1]
|
||||||
bucket = SiteSetting.enable_s3_uploads ? Discourse.store.s3_bucket_name : GlobalSetting.s3_bucket_name
|
bucket = SiteSetting.enable_s3_uploads ? Discourse.store.s3_bucket_name : GlobalSetting.s3_bucket_name
|
||||||
|
|
||||||
# cf. http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
|
# cf. http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
|
||||||
|
if SiteSetting.s3_endpoint == "https://s3.amazonaws.com"
|
||||||
if SiteSetting.Upload.s3_region == "us-east-1"
|
if SiteSetting.Upload.s3_region == "us-east-1"
|
||||||
"//#{bucket}.s3.amazonaws.com"
|
"//#{bucket}.s3.amazonaws.com"
|
||||||
elsif SiteSetting.Upload.s3_region == 'cn-north-1'
|
elsif SiteSetting.Upload.s3_region == 'cn-north-1'
|
||||||
|
@ -148,6 +158,11 @@ class SiteSetting < ActiveRecord::Base
|
||||||
else
|
else
|
||||||
"//#{bucket}.s3-#{SiteSetting.Upload.s3_region}.amazonaws.com"
|
"//#{bucket}.s3-#{SiteSetting.Upload.s3_region}.amazonaws.com"
|
||||||
end
|
end
|
||||||
|
elsif SiteSetting.s3_force_path_style
|
||||||
|
"//#{url_basename}/#{bucket}"
|
||||||
|
else
|
||||||
|
"//#{bucket}.#{url_basename}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -174,7 +174,8 @@ s3_access_key_id =
|
||||||
s3_secret_access_key =
|
s3_secret_access_key =
|
||||||
s3_use_iam_profile = false
|
s3_use_iam_profile = false
|
||||||
s3_cdn_url =
|
s3_cdn_url =
|
||||||
|
s3_endpoint =
|
||||||
|
s3_force_path_style =
|
||||||
|
|
||||||
### rate limits apply to all sites
|
### rate limits apply to all sites
|
||||||
max_user_api_reqs_per_minute = 20
|
max_user_api_reqs_per_minute = 20
|
||||||
|
|
|
@ -1277,6 +1277,8 @@ en:
|
||||||
backup_frequency: "The number of days between backups."
|
backup_frequency: "The number of days between backups."
|
||||||
enable_s3_backups: "Upload backups to S3 when complete. IMPORTANT: requires valid S3 credentials entered in Files settings."
|
enable_s3_backups: "Upload backups to S3 when complete. IMPORTANT: requires valid S3 credentials entered in Files settings."
|
||||||
s3_backup_bucket: "The remote bucket to hold backups. WARNING: Make sure it is a private bucket."
|
s3_backup_bucket: "The remote bucket to hold backups. WARNING: Make sure it is a private bucket."
|
||||||
|
s3_endpoint: "The endpoint can be modified to backup to an S3 compatible service like DigitalOcean Spaces or Minio. WARNING: Use default if using AWS S3"
|
||||||
|
s3_force_path_style: "Enforce path-style addressing for your custom endpoint. IMPORTANT: Required for using Minio uploads and backups."
|
||||||
s3_disable_cleanup: "Disable the removal of backups from S3 when removed locally."
|
s3_disable_cleanup: "Disable the removal of backups from S3 when removed locally."
|
||||||
backup_time_of_day: "Time of day UTC when the backup should occur."
|
backup_time_of_day: "Time of day UTC when the backup should occur."
|
||||||
backup_with_uploads: "Include uploads in scheduled backups. Disabling this will only backup the database."
|
backup_with_uploads: "Include uploads in scheduled backups. Disabling this will only backup the database."
|
||||||
|
|
|
@ -924,9 +924,14 @@ files:
|
||||||
s3_upload_bucket:
|
s3_upload_bucket:
|
||||||
default: ''
|
default: ''
|
||||||
regex: '^[a-z0-9\-\/]+$' # can't use '.' when using HTTPS
|
regex: '^[a-z0-9\-\/]+$' # can't use '.' when using HTTPS
|
||||||
|
s3_endpoint:
|
||||||
|
default: 'https://s3.amazonaws.com'
|
||||||
|
regex: '^https?:\/\/.+[^\/]$'
|
||||||
s3_cdn_url:
|
s3_cdn_url:
|
||||||
default: ''
|
default: ''
|
||||||
regex: '^https?:\/\/.+[^\/]$'
|
regex: '^https?:\/\/.+[^\/]$'
|
||||||
|
s3_force_path_style:
|
||||||
|
default: false
|
||||||
allow_profile_backgrounds:
|
allow_profile_backgrounds:
|
||||||
client: true
|
client: true
|
||||||
default: true
|
default: true
|
||||||
|
|
|
@ -150,7 +150,9 @@ class S3Helper
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.s3_options(obj)
|
def self.s3_options(obj)
|
||||||
opts = { region: obj.s3_region }
|
opts = { region: obj.s3_region,
|
||||||
|
endpoint: SiteSetting.s3_endpoint,
|
||||||
|
force_path_style: SiteSetting.s3_force_path_style }
|
||||||
|
|
||||||
unless obj.s3_use_iam_profile
|
unless obj.s3_use_iam_profile
|
||||||
opts[:access_key_id] = obj.s3_access_key_id
|
opts[:access_key_id] = obj.s3_access_key_id
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue