Commit f6eb5bf6 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'com-code-revert' into 'master'

Revert com code segregation

See merge request gitlab-org/gitlab!18212
parents a674a8a0 990f2779
......@@ -3,7 +3,6 @@
# Ignore all folders except qa/, config/initializers and the root of lib/ since
# the files we need to build the QA image are in these folders.
# Following are the files we need:
# - ./config/light_settings.rb
# - ./config/initializers/0_inject_enterprise_edition_module.rb
# - ./ee/app/models/license.rb
# - ./lib/gitlab.rb
......
# frozen_string_literal: true
module Com
module Gitlab
module Patch
module DrawRoute
extend ::Gitlab::Utils::Override
override :draw_com
def draw_com(routes_name)
draw_route(route_path("com/config/routes/#{routes_name}.rb"))
end
end
end
end
end
# frozen_string_literal: true
require 'fast_spec_helper'
require 'com_spec_helper'
describe Gitlab::Patch::DrawRoute do
subject do
Class.new do
include Gitlab::Patch::DrawRoute
def route_path(route_name)
File.expand_path("../../../../../#{route_name}", __dir__)
end
end.new
end
before do
allow(subject).to receive(:instance_eval)
end
it 'raises an error when nothing is drawn' do
expect { subject.draw(:non_existing) }
.to raise_error(described_class::RoutesNotFound)
end
end
......@@ -22,7 +22,6 @@ module Gitlab
require_dependency Rails.root.join('lib/gitlab/current_settings')
require_dependency Rails.root.join('lib/gitlab/middleware/read_only')
require_dependency Rails.root.join('lib/gitlab/middleware/basic_health_check')
require_dependency Rails.root.join('config/light_settings')
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
......@@ -63,15 +62,6 @@ module Gitlab
config.paths['app/views'].unshift "#{config.root}/ee/app/views"
end
if LightSettings.com?
com_paths = config.eager_load_paths.each_with_object([]) do |path, memo|
com_path = config.root.join('com', Pathname.new(path).relative_path_from(config.root))
memo << com_path.to_s
end
config.eager_load_paths.push(*com_paths)
end
# Rake tasks ignore the eager loading settings, so we need to set the
# autoload paths explicitly
config.autoload_paths = config.eager_load_paths.dup
......
# frozen_string_literal: true
require 'active_support/inflector'
module InjectComModule
def prepend_if_com(constant, with_descendants: false)
return unless Gitlab.com?
com_module = constant.constantize
prepend(com_module)
if with_descendants
descendants.each { |descendant| descendant.prepend(com_module) }
end
end
def extend_if_com(constant)
extend(constant.constantize) if Gitlab.com?
end
def include_if_com(constant)
include(constant.constantize) if Gitlab.com?
end
end
Module.prepend(InjectComModule)
# frozen_string_literal: true
class LightSettings
GL_HOST ||= 'gitlab.com'
GL_SUBDOMAIN_REGEX ||= %r{\A[a-z0-9]+\.gitlab\.com\z}.freeze
class << self
def com?
return Thread.current[:is_com] unless Thread.current[:is_com].nil?
Thread.current[:is_com] = host == GL_HOST || gl_subdomain?
end
private
def config
YAML.safe_load(File.read(settings_path), aliases: true)[Rails.env]
end
def settings_path
Rails.root.join('config', 'gitlab.yml')
end
def host
config.dig('gitlab', 'host') || ENV['GITLAB_HOST'] || 'localhost'
end
def gl_subdomain?
GL_SUBDOMAIN_REGEX === host
end
end
end
# frozen_string_literal: true
require 'pathname'
require_relative '../config/light_settings'
module Gitlab
def self.root
......@@ -38,18 +37,24 @@ module Gitlab
COM_URL = 'https://gitlab.com'
APP_DIRS_PATTERN = %r{^/?(app|config|ee|lib|spec|\(\w*\))}.freeze
SUBDOMAIN_REGEX = %r{\Ahttps://[a-z0-9]+\.gitlab\.com\z}.freeze
VERSION = File.read(root.join("VERSION")).strip.freeze
INSTALLATION_TYPE = File.read(root.join("INSTALLATION_TYPE")).strip.freeze
HTTP_PROXY_ENV_VARS = %w(http_proxy https_proxy HTTP_PROXY HTTPS_PROXY).freeze
def self.com?
LightSettings.com?
# Check `gl_subdomain?` as well to keep parity with gitlab.com
Gitlab.config.gitlab.url == COM_URL || gl_subdomain?
end
def self.org?
Gitlab.config.gitlab.url == 'https://dev.gitlab.org'
end
def self.gl_subdomain?
SUBDOMAIN_REGEX === Gitlab.config.gitlab.url
end
def self.dev_env_org_or_com?
dev_env_or_com? || org?
end
......@@ -74,10 +79,6 @@ module Gitlab
yield if ee?
end
def self.com
yield if com?
end
def self.http_proxy_env?
HTTP_PROXY_ENV_VARS.any? { |name| ENV[name] }
end
......
......@@ -6,12 +6,11 @@ module Gitlab
module Patch
module DrawRoute
prepend_if_ee('EE::Gitlab::Patch::DrawRoute') # rubocop: disable Cop/InjectEnterpriseEditionModule
prepend_if_com('Com::Gitlab::Patch::DrawRoute')
RoutesNotFound = Class.new(StandardError)
def draw(routes_name)
drawn_any = draw_ce(routes_name) | draw_ee(routes_name) | draw_com(routes_name)
drawn_any = draw_ce(routes_name) | draw_ee(routes_name)
drawn_any || raise(RoutesNotFound.new("Cannot find #{routes_name}"))
end
......@@ -24,10 +23,6 @@ module Gitlab
true
end
def draw_com(_)
false
end
def route_path(routes_name)
Rails.root.join(routes_name)
end
......
......@@ -49,12 +49,10 @@ RUN export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)" && \
WORKDIR /home/gitlab/qa
COPY ./qa/Gemfile* /home/gitlab/qa/
COPY ./config/light_settings.rb /home/gitlab/config/light_settings.rb
COPY ./config/initializers/0_inject_enterprise_edition_module.rb /home/gitlab/config/initializers/
# Copy VERSION to ensure the COPY succeeds to copy at least one file since ee/app/models/license.rb isn't present in FOSS
# The [b] part makes ./ee/app/models/license.r[b] a pattern that is allowed to return no files (which is the case in FOSS)
COPY VERSION ./ee/app/models/license.r[b] /home/gitlab/ee/app/models/
COPY ./config/light_settings.rb /home/gitlab/config/
COPY ./lib/gitlab.rb /home/gitlab/lib/
COPY ./INSTALLATION_TYPE ./VERSION /home/gitlab/
RUN cd /home/gitlab/qa/ && bundle install --jobs=$(nproc) --retry=3 --quiet
......
# frozen_string_literal: true
Settings.gitlab[:url] = "https://test.gitlab.com"
......@@ -7,12 +7,10 @@ ENV['IN_MEMORY_APPLICATION_SETTINGS'] = 'true'
require 'active_support/dependencies'
require_relative '../config/initializers/0_inject_enterprise_edition_module'
require_relative '../config/initializers/0_inject_com_module'
require_relative '../config/settings'
require_relative 'support/rspec'
require 'active_support/all'
ActiveSupport::Dependencies.autoload_paths << 'lib'
ActiveSupport::Dependencies.autoload_paths << 'ee/lib'
ActiveSupport::Dependencies.autoload_paths << 'com/lib'
ActiveSupport::XmlMini.backend = 'Nokogiri'
......@@ -71,30 +71,26 @@ describe Gitlab do
end
describe '.com?' do
before do
Thread.current[:is_com] = nil
end
it 'is true when on GitLab.com' do
allow(LightSettings).to receive(:host).and_return('gitlab.com')
stub_config_setting(url: 'https://gitlab.com')
expect(described_class.com?).to eq true
end
it 'is true when on staging' do
allow(LightSettings).to receive(:host).and_return('staging.gitlab.com')
stub_config_setting(url: 'https://staging.gitlab.com')
expect(described_class.com?).to eq true
end
it 'is true when on other gitlab subdomain' do
allow(LightSettings).to receive(:host).and_return('example.gitlab.com')
stub_config_setting(url: 'https://example.gitlab.com')
expect(described_class.com?).to eq true
end
it 'is false when not on GitLab.com' do
allow(LightSettings).to receive(:host).and_return('example.com')
stub_config_setting(url: 'http://example.com')
expect(described_class.com?).to eq false
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment