Draft: Extract instance-identity helpers into gitlab-platform-core
What does this MR do and why?
Move the instance-identity singleton methods out of lib/gitlab.rb into
gems/gitlab-platform-core, as a new Gitlab::InstanceIdentity module
at lib/gitlab/instance_identity.rb inside that gem: com?,
com_except_jh?, com, staging?, canary?, com_and_canary?,
com_but_not_canary?, org?, dev_url, community_forum_url,
doc_url, promo_host, gl_subdomain?, subdomain_regex,
root_domain, staging_com_url, com_url, org_or_com?,
dev_or_test_env?, simulate_com? and http_proxy_env?.
Gitlab::InstanceIdentity is deliberately kept in this gem even though
it is GitLab-specific, unlike everything else gitlab-platform-core
holds. It is the gem's configuration seam into the monolith, not a
generic library, and the maintainer agreed it should stay here rather
than be left in lib/gitlab.rb.
lib/gitlab.rb does extend InstanceIdentity, so these stay singleton
methods on Gitlab and no call site or spec stub changes. The methods
still dispatch through self, so stubbing Gitlab.com? still changes
what Gitlab.com_and_canary? returns. HTTP_PROXY_ENV_VARS moves with
http_proxy_env?. extend does not carry constants, so
Gitlab::HTTP_PROXY_ENV_VARS no longer resolves; it had no callers
outside lib/gitlab.rb.
Gitlab::Platform::Core::Configuration is the new seam, with three
inputs: instance_url, environment and jh. Each takes a plain value
or a callable, and callables are resolved on every read rather than once
at boot, so stub_config_setting, stub_rails_env and
allow(Gitlab).to receive(:jh?) keep working. Reading an input that was
never set raises Gitlab::Platform::Core::MissingConfigurationError,
which names the input and how to set it.
The monolith wires the inputs in
config/initializers/0_gitlab_platform_core.rb. The 0_ prefix puts it
ahead of 1_settings.rb, whose top level is the earliest boot-time
caller of a moved method, Gitlab.dev_or_test_env?.
spec/fast_spec_helper.rb loads that same file directly, because it
loads lib/gitlab.rb without running initializers.
lib/gitlab.rb reaches the gem with require_relative into
gems/gitlab-platform-core/ rather than by gem name, because
scripts/static-analysis, scripts/lib/assets_sha.rb and
scripts/cells/application-settings-analysis.rb load it as plain Ruby
with no Bundler, and a path: gem can never be resolved that way. For
the same reason instance_identity.rb parses GITLAB_SIMULATE_SAAS and
CANARY itself instead of calling Gitlab::Utils.to_boolean: requiring
gitlab/utils loads active_support/all and action_view, which plain
Ruby cannot resolve either. The regexes match to_boolean.
lib/gitlab_edition.rb stays in the monolith. GitlabEdition.root
derives the repo root from __dir__, which inside the gem would point
at the gem directory. qa/Dockerfile also copies that one file into the
QA image, .dockerignore un-ignores it by name, and qa/qa.rb requires
it by relative path from a separate bundle that does not include the
gem. lib/gitlab.rb keeps maintenance_mode?, version_info,
revision, current_milestone, pre_release?, config,
host_with_port, process_name and next_rails?.
The matching examples move to
gems/gitlab-platform-core/spec/gitlab/instance_identity_spec.rb and
run against fake inputs. That spec defines a local stub_env helper and
excludes RSpec/EnvMocking for itself, because taking stub_env from
gitlab-rspec would pull activerecord and
gitlab_quality-test_tooling into this gem's bundle.
spec/lib/gitlab_spec.rb keeps a seam test that the wiring resolves on
every call, and its now-dead RSpec/NamedSubject entry is pruned from
.rubocop_todo/.
The README documents the new "Configuration" section and widens the "Monolith state must come in through an injected seam" line to point at it.
bin/rails runner 'p Gitlab.com?, Gitlab.dev_or_test_env?' returns the
same values before and after, in both test and development, with and
without GITLAB_SIMULATE_SAAS=1.
Context
Part of #635231, which has the plan, verification and risks for this workstream. The tracking issue for the whole slice is #632651.
This MR is stacked on !260361. Until that one merges, the diff also shows the commits of the MRs below it. Review only the last 1 commit(s) on this branch.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist.