Commit 682c6ad9 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '50193-feature-flag-force-enable-auto-devops' into 'master'

Resolve "Enable Auto DevOps instance-wide on GitLab.com"

Closes #50193

See merge request gitlab-org/gitlab-ce!21136
parents ce18246c 555cdade
...@@ -27,6 +27,7 @@ class Project < ActiveRecord::Base ...@@ -27,6 +27,7 @@ class Project < ActiveRecord::Base
include FastDestroyAll::Helpers include FastDestroyAll::Helpers
include WithUploads include WithUploads
include BatchDestroyDependentAssociations include BatchDestroyDependentAssociations
include FeatureGate
extend Gitlab::Cache::RequestCache extend Gitlab::Cache::RequestCache
extend Gitlab::ConfigHelper extend Gitlab::ConfigHelper
...@@ -519,18 +520,19 @@ class Project < ActiveRecord::Base ...@@ -519,18 +520,19 @@ class Project < ActiveRecord::Base
def auto_devops_enabled? def auto_devops_enabled?
if auto_devops&.enabled.nil? if auto_devops&.enabled.nil?
Gitlab::CurrentSettings.auto_devops_enabled? has_auto_devops_implicitly_enabled?
else else
auto_devops.enabled? auto_devops.enabled?
end end
end end
def has_auto_devops_implicitly_enabled? def has_auto_devops_implicitly_enabled?
auto_devops&.enabled.nil? && Gitlab::CurrentSettings.auto_devops_enabled? auto_devops&.enabled.nil? &&
(Gitlab::CurrentSettings.auto_devops_enabled? || Feature.enabled?(:force_autodevops_on_by_default, self))
end end
def has_auto_devops_implicitly_disabled? def has_auto_devops_implicitly_disabled?
auto_devops&.enabled.nil? && !Gitlab::CurrentSettings.auto_devops_enabled? auto_devops&.enabled.nil? && !(Gitlab::CurrentSettings.auto_devops_enabled? || Feature.enabled?(:force_autodevops_on_by_default, self))
end end
def empty_repo? def empty_repo?
......
...@@ -47,12 +47,8 @@ class ProjectAutoDevops < ActiveRecord::Base ...@@ -47,12 +47,8 @@ class ProjectAutoDevops < ActiveRecord::Base
end end
def needs_to_create_deploy_token? def needs_to_create_deploy_token?
auto_devops_enabled? && project.auto_devops_enabled? &&
!project.public? && !project.public? &&
!project.deploy_tokens.find_by(name: DeployToken::GITLAB_DEPLOY_TOKEN_NAME).present? !project.deploy_tokens.find_by(name: DeployToken::GITLAB_DEPLOY_TOKEN_NAME).present?
end end
def auto_devops_enabled?
Gitlab::CurrentSettings.auto_devops_enabled? || enabled?
end
end end
...@@ -30,7 +30,7 @@ module Projects ...@@ -30,7 +30,7 @@ module Projects
def run_auto_devops_pipeline? def run_auto_devops_pipeline?
return false if project.repository.gitlab_ci_yml || !project.auto_devops&.previous_changes&.include?('enabled') return false if project.repository.gitlab_ci_yml || !project.auto_devops&.previous_changes&.include?('enabled')
project.auto_devops.enabled? || (project.auto_devops.enabled.nil? && Gitlab::CurrentSettings.auto_devops_enabled?) project.auto_devops_enabled?
end end
private private
......
...@@ -233,6 +233,11 @@ in **Admin Area > Settings > Continuous Integration and Deployment**. Doing that ...@@ -233,6 +233,11 @@ in **Admin Area > Settings > Continuous Integration and Deployment**. Doing that
all the projects that haven't explicitly set an option will have Auto DevOps all the projects that haven't explicitly set an option will have Auto DevOps
enabled by default. enabled by default.
NOTE: **Note:**
There is also a feature flag to enable Auto DevOps to a percentage of projects
which can be enabled from the console with
`Feature.get(:force_autodevops_on_by_default).enable_percentage_of_actors(10)`.
### Deployment strategy ### Deployment strategy
> [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/issues/38542) in GitLab 11.0. > [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/issues/38542) in GitLab 11.0.
......
...@@ -100,7 +100,7 @@ describe ProjectAutoDevops do ...@@ -100,7 +100,7 @@ describe ProjectAutoDevops do
end end
end end
describe '#set_gitlab_deploy_token' do describe '#create_gitlab_deploy_token' do
let(:auto_devops) { build(:project_auto_devops, project: project) } let(:auto_devops) { build(:project_auto_devops, project: project) }
context 'when the project is public' do context 'when the project is public' do
...@@ -144,9 +144,9 @@ describe ProjectAutoDevops do ...@@ -144,9 +144,9 @@ describe ProjectAutoDevops do
end end
end end
context 'when autodevops is enabled at instancel level' do context 'when autodevops is enabled at instance level' do
let(:project) { create(:project, :repository, :internal) } let(:project) { create(:project, :repository, :internal) }
let(:auto_devops) { build(:project_auto_devops, :disabled, project: project) } let(:auto_devops) { build(:project_auto_devops, enabled: nil, project: project) }
it 'should create a deploy token' do it 'should create a deploy token' do
allow(Gitlab::CurrentSettings).to receive(:auto_devops_enabled?).and_return(true) allow(Gitlab::CurrentSettings).to receive(:auto_devops_enabled?).and_return(true)
......
...@@ -3259,6 +3259,11 @@ describe Project do ...@@ -3259,6 +3259,11 @@ describe Project do
end end
describe '#auto_devops_enabled?' do describe '#auto_devops_enabled?' do
before do
allow(Feature).to receive(:enabled?).and_call_original
Feature.get(:force_autodevops_on_by_default).enable_percentage_of_actors(0)
end
set(:project) { create(:project) } set(:project) { create(:project) }
subject { project.auto_devops_enabled? } subject { project.auto_devops_enabled? }
...@@ -3268,19 +3273,14 @@ describe Project do ...@@ -3268,19 +3273,14 @@ describe Project do
stub_application_setting(auto_devops_enabled: true) stub_application_setting(auto_devops_enabled: true)
end end
it 'auto devops is implicitly enabled' do it { is_expected.to be_truthy }
expect(project.auto_devops).to be_nil
expect(project).to be_auto_devops_enabled
end
context 'when explicitly enabled' do context 'when explicitly enabled' do
before do before do
create(:project_auto_devops, project: project) create(:project_auto_devops, project: project)
end end
it "auto devops is enabled" do it { is_expected.to be_truthy }
expect(project).to be_auto_devops_enabled
end
end end
context 'when explicitly disabled' do context 'when explicitly disabled' do
...@@ -3288,9 +3288,7 @@ describe Project do ...@@ -3288,9 +3288,7 @@ describe Project do
create(:project_auto_devops, project: project, enabled: false) create(:project_auto_devops, project: project, enabled: false)
end end
it "auto devops is disabled" do it { is_expected.to be_falsey }
expect(project).not_to be_auto_devops_enabled
end
end end
end end
...@@ -3299,19 +3297,22 @@ describe Project do ...@@ -3299,19 +3297,22 @@ describe Project do
stub_application_setting(auto_devops_enabled: false) stub_application_setting(auto_devops_enabled: false)
end end
it 'auto devops is implicitly disabled' do it { is_expected.to be_falsey }
expect(project.auto_devops).to be_nil
expect(project).not_to be_auto_devops_enabled
end
context 'when explicitly enabled' do context 'when explicitly enabled' do
before do before do
create(:project_auto_devops, project: project) create(:project_auto_devops, project: project)
end end
it "auto devops is enabled" do it { is_expected.to be_truthy }
expect(project).to be_auto_devops_enabled end
context 'when force_autodevops_on_by_default is enabled for the project' do
before do
Feature.get(:force_autodevops_on_by_default).enable_percentage_of_actors(100)
end end
it { is_expected.to be_truthy }
end end
end end
end end
...@@ -3361,6 +3362,11 @@ describe Project do ...@@ -3361,6 +3362,11 @@ describe Project do
end end
describe '#has_auto_devops_implicitly_disabled?' do describe '#has_auto_devops_implicitly_disabled?' do
before do
allow(Feature).to receive(:enabled?).and_call_original
Feature.get(:force_autodevops_on_by_default).enable_percentage_of_actors(0)
end
set(:project) { create(:project) } set(:project) { create(:project) }
context 'when enabled in settings' do context 'when enabled in settings' do
...@@ -3382,6 +3388,16 @@ describe Project do ...@@ -3382,6 +3388,16 @@ describe Project do
expect(project).to have_auto_devops_implicitly_disabled expect(project).to have_auto_devops_implicitly_disabled
end end
context 'when force_autodevops_on_by_default is enabled for the project' do
before do
Feature.get(:force_autodevops_on_by_default).enable_percentage_of_actors(100)
end
it 'does not have auto devops implicitly disabled' do
expect(project).not_to have_auto_devops_implicitly_disabled
end
end
context 'when explicitly disabled' do context 'when explicitly disabled' do
before do before do
create(:project_auto_devops, project: project, enabled: false) create(:project_auto_devops, project: project, enabled: false)
......
...@@ -111,6 +111,13 @@ RSpec.configure do |config| ...@@ -111,6 +111,13 @@ RSpec.configure do |config|
config.before(:example) do config.before(:example) do
# Enable all features by default for testing # Enable all features by default for testing
allow(Feature).to receive(:enabled?) { true } allow(Feature).to receive(:enabled?) { true }
# The following can be removed when we remove the staged rollout strategy
# and we can just enable it using instance wide settings
# (ie. ApplicationSetting#auto_devops_enabled)
allow(Feature).to receive(:enabled?)
.with(:force_autodevops_on_by_default, anything)
.and_return(false)
end end
config.before(:example, :request_store) do config.before(:example, :request_store) do
......
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