2018-10-06 23:10:08 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-07-22 15:11:50 +00:00
|
|
|
require 'pathname'
|
2015-07-15 13:59:38 +00:00
|
|
|
|
|
|
|
module Gitlab
|
2018-04-10 14:07:47 +00:00
|
|
|
def self.root
|
|
|
|
Pathname.new(File.expand_path('..', __dir__))
|
|
|
|
end
|
|
|
|
|
2019-01-29 20:45:47 +00:00
|
|
|
def self.version_info
|
|
|
|
Gitlab::VersionInfo.parse(Gitlab::VERSION)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.pre_release?
|
|
|
|
VERSION.include?('pre')
|
|
|
|
end
|
|
|
|
|
2018-04-23 14:12:19 +00:00
|
|
|
def self.config
|
|
|
|
Settings
|
|
|
|
end
|
|
|
|
|
2018-05-24 07:57:54 +00:00
|
|
|
def self.revision
|
|
|
|
@_revision ||= begin
|
|
|
|
if File.exist?(root.join("REVISION"))
|
|
|
|
File.read(root.join("REVISION")).strip.freeze
|
|
|
|
else
|
2019-03-28 11:05:03 +00:00
|
|
|
result = Gitlab::Popen.popen_with_detail(%W[#{config.git.bin_path} log --pretty=format:%h --abbrev=11 -n 1])
|
2018-05-24 07:57:54 +00:00
|
|
|
|
|
|
|
if result.status.success?
|
|
|
|
result.stdout.chomp.freeze
|
|
|
|
else
|
2019-09-10 08:11:43 +00:00
|
|
|
"Unknown"
|
2018-05-24 07:57:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-10 08:11:43 +00:00
|
|
|
COM_URL = 'https://gitlab.com'
|
2020-05-28 03:08:08 +00:00
|
|
|
STAGING_COM_URL = 'https://staging.gitlab.com'
|
2019-05-05 10:19:14 +00:00
|
|
|
APP_DIRS_PATTERN = %r{^/?(app|config|ee|lib|spec|\(\w*\))}.freeze
|
2019-10-08 18:05:56 +00:00
|
|
|
SUBDOMAIN_REGEX = %r{\Ahttps://[a-z0-9]+\.gitlab\.com\z}.freeze
|
2018-04-23 11:02:07 +00:00
|
|
|
VERSION = File.read(root.join("VERSION")).strip.freeze
|
2018-06-07 15:01:20 +00:00
|
|
|
INSTALLATION_TYPE = File.read(root.join("INSTALLATION_TYPE")).strip.freeze
|
2019-05-29 16:43:07 +00:00
|
|
|
HTTP_PROXY_ENV_VARS = %w(http_proxy https_proxy HTTP_PROXY HTTPS_PROXY).freeze
|
2018-04-23 11:02:07 +00:00
|
|
|
|
2016-04-12 18:39:08 +00:00
|
|
|
def self.com?
|
2019-10-08 18:05:56 +00:00
|
|
|
# Check `gl_subdomain?` as well to keep parity with gitlab.com
|
|
|
|
Gitlab.config.gitlab.url == COM_URL || gl_subdomain?
|
2016-06-13 21:43:29 +00:00
|
|
|
end
|
|
|
|
|
2021-02-02 00:09:14 +00:00
|
|
|
def self.com
|
|
|
|
yield if com?
|
|
|
|
end
|
|
|
|
|
2020-05-28 03:08:08 +00:00
|
|
|
def self.staging?
|
|
|
|
Gitlab.config.gitlab.url == STAGING_COM_URL
|
|
|
|
end
|
|
|
|
|
2019-11-07 12:06:21 +00:00
|
|
|
def self.canary?
|
|
|
|
Gitlab::Utils.to_boolean(ENV['CANARY'])
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.com_and_canary?
|
|
|
|
com? && canary?
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.com_but_not_canary?
|
|
|
|
com? && !canary?
|
|
|
|
end
|
|
|
|
|
2018-04-17 14:21:03 +00:00
|
|
|
def self.org?
|
|
|
|
Gitlab.config.gitlab.url == 'https://dev.gitlab.org'
|
|
|
|
end
|
|
|
|
|
2019-10-08 18:05:56 +00:00
|
|
|
def self.gl_subdomain?
|
|
|
|
SUBDOMAIN_REGEX === Gitlab.config.gitlab.url
|
|
|
|
end
|
|
|
|
|
2019-08-28 01:29:52 +00:00
|
|
|
def self.dev_env_org_or_com?
|
2019-09-13 13:26:31 +00:00
|
|
|
dev_env_or_com? || org?
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.dev_env_or_com?
|
|
|
|
Rails.env.development? || com?
|
2018-04-12 07:12:21 +00:00
|
|
|
end
|
2019-01-16 13:29:05 +00:00
|
|
|
|
2020-05-28 03:08:08 +00:00
|
|
|
def self.dev_or_test_env?
|
|
|
|
Rails.env.development? || Rails.env.test?
|
|
|
|
end
|
|
|
|
|
2019-03-04 08:20:37 +00:00
|
|
|
def self.ee?
|
2019-06-13 12:18:01 +00:00
|
|
|
@is_ee ||=
|
2019-10-15 09:06:09 +00:00
|
|
|
# We use this method when the Rails environment is not loaded. This
|
|
|
|
# means that checking the presence of the License class could result in
|
|
|
|
# this method returning `false`, even for an EE installation.
|
|
|
|
#
|
2019-10-16 18:08:01 +00:00
|
|
|
# The `FOSS_ONLY` is always `string` or `nil`
|
2019-10-15 09:06:09 +00:00
|
|
|
# Thus the nil or empty string will result
|
2019-10-16 18:08:01 +00:00
|
|
|
# in using default value: false
|
2019-10-15 09:06:09 +00:00
|
|
|
#
|
|
|
|
# The behavior needs to be synchronised with
|
|
|
|
# config/helpers/is_ee_env.js
|
|
|
|
root.join('ee/app/models/license.rb').exist? &&
|
2019-10-16 18:08:01 +00:00
|
|
|
!%w[true 1].include?(ENV['FOSS_ONLY'].to_s)
|
2019-03-04 08:20:37 +00:00
|
|
|
end
|
|
|
|
|
2019-06-24 16:36:32 +00:00
|
|
|
def self.ee
|
|
|
|
yield if ee?
|
|
|
|
end
|
|
|
|
|
2019-05-29 16:43:07 +00:00
|
|
|
def self.http_proxy_env?
|
|
|
|
HTTP_PROXY_ENV_VARS.any? { |name| ENV[name] }
|
|
|
|
end
|
|
|
|
|
2019-01-16 13:29:05 +00:00
|
|
|
def self.process_name
|
2019-12-22 09:07:51 +00:00
|
|
|
return 'sidekiq' if Gitlab::Runtime.sidekiq?
|
|
|
|
return 'console' if Gitlab::Runtime.console?
|
2019-01-16 13:29:05 +00:00
|
|
|
return 'test' if Rails.env.test?
|
|
|
|
|
|
|
|
'web'
|
|
|
|
end
|
2020-12-08 21:10:06 +00:00
|
|
|
|
|
|
|
def self.maintenance_mode?
|
|
|
|
return false unless ::Feature.enabled?(:maintenance_mode)
|
2021-02-02 00:09:14 +00:00
|
|
|
return false unless ::Gitlab::CurrentSettings.current_application_settings?
|
2020-12-08 21:10:06 +00:00
|
|
|
|
|
|
|
::Gitlab::CurrentSettings.maintenance_mode
|
|
|
|
end
|
2015-07-15 13:59:38 +00:00
|
|
|
end
|