Fix sitemap for self host, including memory leak (#14036)
* Only load Rake tasks once * Use local sitemap if AWS credentials are not set * Leave generated sitemaps out of git
This commit is contained in:
parent
d448abae19
commit
f17d808cec
3 changed files with 30 additions and 24 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -59,6 +59,7 @@ package-lock.json
|
|||
|
||||
#sitemap
|
||||
/public/sitemap.xml.gz
|
||||
/public/sitemaps/
|
||||
|
||||
# Development Docker storage location
|
||||
_docker-storage/
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
Rails.application.load_tasks
|
||||
|
||||
class SitemapRefreshWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options queue: :low_priority, retry: 10
|
||||
|
||||
def perform
|
||||
Rails.application.load_tasks
|
||||
|
||||
sitemap_task = ForemInstance.local? ? "sitemap:refresh:no_ping" : "sitemap:refresh"
|
||||
|
||||
Rake::Task[sitemap_task].invoke
|
||||
|
|
|
|||
|
|
@ -4,29 +4,34 @@ require "sitemap_generator/s3_adapter"
|
|||
|
||||
if Rails.env.production?
|
||||
region = ApplicationConfig["AWS_UPLOAD_REGION"].presence || ApplicationConfig["AWS_DEFAULT_REGION"]
|
||||
config_hash = if ENV["FOREM_CONTEXT"] == "forem_cloud" # @forem/systems jdoss's special sauce.
|
||||
# Excluding the aws_access_key_id and aws_secret_access_key causes use_iam_profile
|
||||
# to be set to true by the S3Adapter
|
||||
# https://github.com/kjvarga/sitemap_generator/blob/0b847f1e7a544ea8ef87bb643a732e30a07a14c9/lib/sitemap_generator/adapters/s3_adapter.rb#L39
|
||||
{
|
||||
fog_provider: "AWS",
|
||||
fog_directory: ApplicationConfig["AWS_BUCKET_NAME"],
|
||||
fog_region: "us-east-2",
|
||||
fog_public: false
|
||||
}
|
||||
else
|
||||
{
|
||||
fog_provider: "AWS",
|
||||
aws_access_key_id: ApplicationConfig["AWS_ID"],
|
||||
aws_secret_access_key: ApplicationConfig["AWS_SECRET"],
|
||||
fog_directory: ApplicationConfig["AWS_BUCKET_NAME"],
|
||||
fog_region: region
|
||||
}
|
||||
end
|
||||
s3_config_hash = if ENV["FOREM_CONTEXT"] == "forem_cloud" # @forem/systems jdoss's special sauce.
|
||||
# Excluding the aws_access_key_id and aws_secret_access_key causes use_iam_profile
|
||||
# to be set to true by the S3Adapter
|
||||
# https://github.com/kjvarga/sitemap_generator/blob/0b847f1e7a544ea8ef87bb643a732e30a07a14c9/lib/sitemap_generator/adapters/s3_adapter.rb#L39
|
||||
{
|
||||
fog_provider: "AWS",
|
||||
fog_directory: ApplicationConfig["AWS_BUCKET_NAME"],
|
||||
fog_region: "us-east-2",
|
||||
fog_public: false
|
||||
}
|
||||
elsif %w[AWS_ID AWS_SECRET AWS_BUCKET_NAME].all? { |key| ApplicationConfig[key] }
|
||||
{
|
||||
fog_provider: "AWS",
|
||||
aws_access_key_id: ApplicationConfig["AWS_ID"],
|
||||
aws_secret_access_key: ApplicationConfig["AWS_SECRET"],
|
||||
fog_directory: ApplicationConfig["AWS_BUCKET_NAME"],
|
||||
fog_region: region
|
||||
}
|
||||
end
|
||||
|
||||
SitemapGenerator::Sitemap.adapter = SitemapGenerator::S3Adapter.new(config_hash)
|
||||
SitemapGenerator::Sitemap.sitemaps_host = "https://#{ApplicationConfig['AWS_BUCKET_NAME']}.s3.amazonaws.com/"
|
||||
SitemapGenerator::Sitemap.public_path = "tmp/"
|
||||
if s3_config_hash
|
||||
SitemapGenerator::Sitemap.adapter = SitemapGenerator::S3Adapter.new(config_hash)
|
||||
SitemapGenerator::Sitemap.sitemaps_host = "https://#{ApplicationConfig['AWS_BUCKET_NAME']}.s3.amazonaws.com/"
|
||||
SitemapGenerator::Sitemap.public_path = "tmp/"
|
||||
else
|
||||
SitemapGenerator::Sitemap.adapter = SitemapGenerator::FileAdapter.new
|
||||
SitemapGenerator::Sitemap.public_path = "public/"
|
||||
end
|
||||
SitemapGenerator::Sitemap.sitemaps_path = "sitemaps/"
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue