mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: SKIP_DB_AND_REDIS env var (#7756)
Sometimes we would like to create a base image without any DB access, this assists in creating custom base images with custom plugins that already includes `public/assets` Following this change set you can run: ``` SPROCKETS_CONCURRENT=1 DONT_PRECOMPILE_CSS=1 SKIP_DB_AND_REDIS=1 RAILS_ENV=production bin/rake assets:precompile ``` Then it is straight forward to create a base image without needing a DB or Redis.
This commit is contained in:
@@ -89,12 +89,14 @@ class Emoji
|
|||||||
def self.load_custom
|
def self.load_custom
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
|
if !GlobalSetting.skip_db?
|
||||||
CustomEmoji.includes(:upload).order(:name).each do |emoji|
|
CustomEmoji.includes(:upload).order(:name).each do |emoji|
|
||||||
result << Emoji.new.tap do |e|
|
result << Emoji.new.tap do |e|
|
||||||
e.name = emoji.name
|
e.name = emoji.name
|
||||||
e.url = emoji.upload&.url
|
e.url = emoji.upload&.url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
Plugin::CustomEmoji.emojis.each do |name, url|
|
Plugin::CustomEmoji.emojis.each do |name, url|
|
||||||
result << Emoji.new.tap do |e|
|
result << Emoji.new.tap do |e|
|
||||||
|
|||||||
@@ -77,6 +77,22 @@ class GlobalSetting
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.skip_db=(v)
|
||||||
|
@skip_db = v
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.skip_db?
|
||||||
|
@skip_db
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.skip_redis=(v)
|
||||||
|
@skip_redis = v
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.skip_redis?
|
||||||
|
@skip_redis
|
||||||
|
end
|
||||||
|
|
||||||
def self.use_s3?
|
def self.use_s3?
|
||||||
(@use_s3 ||=
|
(@use_s3 ||=
|
||||||
begin
|
begin
|
||||||
|
|||||||
@@ -35,6 +35,11 @@ unless Rails.env.test? && ENV['LOAD_PLUGINS'] != "1"
|
|||||||
end
|
end
|
||||||
GlobalSetting.load_defaults
|
GlobalSetting.load_defaults
|
||||||
|
|
||||||
|
if ENV['SKIP_DB_AND_REDIS'] == '1'
|
||||||
|
GlobalSetting.skip_db = true
|
||||||
|
GlobalSetting.skip_redis = true
|
||||||
|
end
|
||||||
|
|
||||||
require 'pry-rails' if Rails.env.development?
|
require 'pry-rails' if Rails.env.development?
|
||||||
|
|
||||||
if defined?(Bundler)
|
if defined?(Bundler)
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
if GlobalSetting.skip_redis?
|
||||||
|
MessageBus.configure(backend: :memory)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
MessageBus.site_id_lookup do |env = nil|
|
MessageBus.site_id_lookup do |env = nil|
|
||||||
if env
|
if env
|
||||||
setup_message_bus_env(env)
|
setup_message_bus_env(env)
|
||||||
|
|||||||
@@ -5,6 +5,13 @@
|
|||||||
# the original version
|
# the original version
|
||||||
Discourse.git_version
|
Discourse.git_version
|
||||||
|
|
||||||
|
if GlobalSetting.skip_redis?
|
||||||
|
require 'site_settings/local_process_provider'
|
||||||
|
Rails.cache = Discourse.cache
|
||||||
|
SiteSetting.provider = SiteSettings::LocalProcessProvider.new
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
reload_settings = lambda {
|
reload_settings = lambda {
|
||||||
RailsMultisite::ConnectionManagement.safe_each_connection do
|
RailsMultisite::ConnectionManagement.safe_each_connection do
|
||||||
begin
|
begin
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
return if GlobalSetting.skip_db?
|
||||||
|
|
||||||
# Some sanity checking so we don't count on an unindexed column on boot
|
# Some sanity checking so we don't count on an unindexed column on boot
|
||||||
begin
|
begin
|
||||||
if ActiveRecord::Base.connection.table_exists?(:users) &&
|
if ActiveRecord::Base.connection.table_exists?(:users) &&
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
if GlobalSetting.skip_redis?
|
||||||
|
Rails.logger = Rails.logger.chained.first
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if Rails.env.development? && RUBY_VERSION.match?(/^2\.5\.[23]/)
|
if Rails.env.development? && RUBY_VERSION.match?(/^2\.5\.[23]/)
|
||||||
STDERR.puts "WARNING: Discourse development environment runs slower on Ruby 2.5.3 or below"
|
STDERR.puts "WARNING: Discourse development environment runs slower on Ruby 2.5.3 or below"
|
||||||
STDERR.puts "We recommend you upgrade to Ruby 2.6.1 for the optimal development performance"
|
STDERR.puts "We recommend you upgrade to Ruby 2.6.1 for the optimal development performance"
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
return if GlobalSetting.skip_db?
|
||||||
|
|
||||||
require_dependency 'webpush'
|
require_dependency 'webpush'
|
||||||
|
|
||||||
if SiteSetting.vapid_public_key.blank? || SiteSetting.vapid_private_key.blank? || SiteSetting.vapid_public_key_bytes.blank?
|
if SiteSetting.vapid_public_key.blank? || SiteSetting.vapid_private_key.blank? || SiteSetting.vapid_public_key_bytes.blank?
|
||||||
|
|||||||
@@ -245,7 +245,13 @@ module Discourse
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.cache
|
def self.cache
|
||||||
@cache ||= Cache.new
|
@cache ||= begin
|
||||||
|
if GlobalSetting.skip_redis?
|
||||||
|
ActiveSupport::Cache::MemoryStore.new
|
||||||
|
else
|
||||||
|
Cache.new
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the current base URL for the current site
|
# Get the current base URL for the current site
|
||||||
|
|||||||
@@ -138,6 +138,8 @@ module I18n
|
|||||||
def overrides_by_locale(locale)
|
def overrides_by_locale(locale)
|
||||||
return unless @overrides_enabled
|
return unless @overrides_enabled
|
||||||
|
|
||||||
|
return {} if GlobalSetting.skip_db?
|
||||||
|
|
||||||
site = RailsMultisite::ConnectionManagement.current_db
|
site = RailsMultisite::ConnectionManagement.current_db
|
||||||
|
|
||||||
by_site = @overrides_by_site[site]
|
by_site = @overrides_by_site[site]
|
||||||
|
|||||||
Reference in New Issue
Block a user