mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 10:24:49 +08:00
cf42466dea
This commit adds some system specs to test uploads with direct to S3 single and multipart uploads via uppy. This is done with minio as a local S3 replacement. We are doing this to catch regressions when uppy dependencies need to be upgraded or we change uppy upload code, since before this there was no way to know outside manual testing whether these changes would cause regressions. Minio's server lifecycle and the installed binaries are managed by the https://github.com/discourse/minio_runner gem, though the binaries are already installed on the discourse_test image we run GitHub CI from. These tests will only run in CI unless you specifically use the CI=1 or RUN_S3_SYSTEM_SPECS=1 env vars. For a history of experimentation here see https://github.com/discourse/discourse/pull/22381 Related PRs: * https://github.com/discourse/minio_runner/pull/1 * https://github.com/discourse/minio_runner/pull/2 * https://github.com/discourse/minio_runner/pull/3
93 lines
2.8 KiB
Ruby
Executable File
93 lines
2.8 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
# frozen_string_literal: true
|
|
|
|
require "minio_runner"
|
|
|
|
class ExecuteLocalMinioS3
|
|
def run
|
|
begin
|
|
start_minio
|
|
save_old_config
|
|
change_to_minio_settings
|
|
puts "Press any key when done..."
|
|
gets
|
|
restore_old
|
|
rescue SystemExit, Interrupt
|
|
restore_old
|
|
raise
|
|
end
|
|
end
|
|
|
|
def start_minio
|
|
MinioRunner.config do |minio_runner_config|
|
|
minio_runner_config.minio_domain = ENV["MINIO_RUNNER_MINIO_DOMAIN"] || "minio.local"
|
|
minio_runner_config.buckets =
|
|
(
|
|
if ENV["MINIO_RUNNER_BUCKETS"]
|
|
ENV["MINIO_RUNNER_BUCKETS"].split(",")
|
|
else
|
|
["discoursetest"]
|
|
end
|
|
)
|
|
minio_runner_config.public_buckets =
|
|
(
|
|
if ENV["MINIO_RUNNER_PUBLIC_BUCKETS"]
|
|
ENV["MINIO_RUNNER_PUBLIC_BUCKETS"].split(",")
|
|
else
|
|
["discoursetest"]
|
|
end
|
|
)
|
|
end
|
|
puts "Starting minio..."
|
|
MinioRunner.start
|
|
end
|
|
|
|
def save_old_config
|
|
puts "Temporarily using minio config for S3. Current settings:"
|
|
@current_s3_endpoint = puts_current(:s3_endpoint)
|
|
@current_s3_upload_bucket = puts_current(:s3_upload_bucket)
|
|
@current_s3_access_key_id = puts_current(:s3_access_key_id)
|
|
@current_s3_secret_access_key = puts_current(:s3_secret_access_key)
|
|
@current_allowed_internal_hosts = puts_current(:allowed_internal_hosts)
|
|
end
|
|
|
|
def change_to_minio_settings
|
|
puts "Changing to minio settings..."
|
|
SiteSetting.s3_upload_bucket = "discoursetest"
|
|
SiteSetting.s3_access_key_id = MinioRunner.config.minio_root_user
|
|
SiteSetting.s3_secret_access_key = MinioRunner.config.minio_root_password
|
|
SiteSetting.s3_endpoint = MinioRunner.config.minio_server_url
|
|
SiteSetting.allowed_internal_hosts =
|
|
MinioRunner.config.minio_urls.map { |url| URI.parse(url).host }.join("|")
|
|
|
|
puts_current(:s3_endpoint)
|
|
puts_current(:s3_upload_bucket)
|
|
puts_current(:s3_access_key_id)
|
|
puts_current(:s3_secret_access_key)
|
|
puts_current(:allowed_internal_hosts)
|
|
end
|
|
|
|
def restore_old
|
|
puts "Restoring old S3 settings..."
|
|
SiteSetting.s3_upload_bucket = @current_s3_upload_bucket
|
|
SiteSetting.s3_access_key_id = @current_s3_access_key_id
|
|
SiteSetting.s3_secret_access_key = @current_s3_secret_access_key
|
|
SiteSetting.s3_endpoint = @current_s3_endpoint
|
|
SiteSetting.allowed_internal_hosts = @current_allowed_internal_hosts
|
|
|
|
puts_current(:s3_endpoint)
|
|
puts_current(:s3_upload_bucket)
|
|
puts_current(:s3_access_key_id)
|
|
puts_current(:s3_secret_access_key)
|
|
puts_current(:allowed_internal_hosts)
|
|
puts "Done!"
|
|
end
|
|
|
|
def puts_current(setting)
|
|
printf "%-40s %s\n", " > Current #{setting}:", SiteSetting.send(setting)
|
|
SiteSetting.send(setting)
|
|
end
|
|
end
|
|
|
|
ExecuteLocalMinioS3.new.run
|