Commit 6e428e2d authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'ee-38175-add-domain-field-to-auto-devops-application-setting' into 'master'

Ee 38175 add domain field to auto devops application setting

See merge request gitlab-org/gitlab-ee!4193
parents e92ad06f 03b596d4
...@@ -147,6 +147,7 @@ module ApplicationSettingsHelper ...@@ -147,6 +147,7 @@ module ApplicationSettingsHelper
:akismet_enabled, :akismet_enabled,
:authorized_keys_enabled, :authorized_keys_enabled,
:auto_devops_enabled, :auto_devops_enabled,
:auto_devops_domain,
:circuitbreaker_access_retries, :circuitbreaker_access_retries,
:circuitbreaker_check_interval, :circuitbreaker_check_interval,
:circuitbreaker_failure_count_threshold, :circuitbreaker_failure_count_threshold,
......
...@@ -9,21 +9,28 @@ module AutoDevopsHelper ...@@ -9,21 +9,28 @@ module AutoDevopsHelper
end end
def auto_devops_warning_message(project) def auto_devops_warning_message(project)
missing_domain = !project.auto_devops&.has_domain? if missing_auto_devops_service?(project)
missing_service = !project.deployment_platform&.active?
if missing_service
params = { params = {
kubernetes: link_to('Kubernetes cluster', project_clusters_path(project)) kubernetes: link_to('Kubernetes cluster', project_clusters_path(project))
} }
if missing_domain if missing_auto_devops_domain?(project)
_('Auto Review Apps and Auto Deploy need a domain name and a %{kubernetes} to work correctly.') % params _('Auto Review Apps and Auto Deploy need a domain name and a %{kubernetes} to work correctly.') % params
else else
_('Auto Review Apps and Auto Deploy need a %{kubernetes} to work correctly.') % params _('Auto Review Apps and Auto Deploy need a %{kubernetes} to work correctly.') % params
end end
elsif missing_domain elsif missing_auto_devops_domain?(project)
_('Auto Review Apps and Auto Deploy need a domain name to work correctly.') _('Auto Review Apps and Auto Deploy need a domain name to work correctly.')
end end
end end
private
def missing_auto_devops_domain?(project)
!(project.auto_devops || project.build_auto_devops)&.has_domain?
end
def missing_auto_devops_service?(project)
!project.deployment_platform&.active?
end
end end
...@@ -130,6 +130,11 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -130,6 +130,11 @@ class ApplicationSetting < ActiveRecord::Base
validates :repository_storages, presence: true validates :repository_storages, presence: true
validate :check_repository_storages validate :check_repository_storages
validates :auto_devops_domain,
allow_blank: true,
hostname: { allow_numeric_hostname: true, require_valid_tld: true },
if: :auto_devops_enabled?
validates :enabled_git_access_protocol, validates :enabled_git_access_protocol,
inclusion: { in: %w(ssh http), allow_blank: true, allow_nil: true } inclusion: { in: %w(ssh http), allow_blank: true, allow_nil: true }
......
...@@ -1612,7 +1612,7 @@ class Project < ActiveRecord::Base ...@@ -1612,7 +1612,7 @@ class Project < ActiveRecord::Base
def auto_devops_variables def auto_devops_variables
return [] unless auto_devops_enabled? return [] unless auto_devops_enabled?
auto_devops&.variables || [] (auto_devops || build_auto_devops)&.variables
end end
def append_or_update_attribute(name, value) def append_or_update_attribute(name, value)
......
...@@ -6,13 +6,17 @@ class ProjectAutoDevops < ActiveRecord::Base ...@@ -6,13 +6,17 @@ class ProjectAutoDevops < ActiveRecord::Base
validates :domain, allow_blank: true, hostname: { allow_numeric_hostname: true } validates :domain, allow_blank: true, hostname: { allow_numeric_hostname: true }
def instance_domain
Gitlab::CurrentSettings.auto_devops_domain
end
def has_domain? def has_domain?
domain.present? domain.present? || instance_domain.present?
end end
def variables def variables
variables = [] variables = []
variables << { key: 'AUTO_DEVOPS_DOMAIN', value: domain, public: true } if domain.present? variables << { key: 'AUTO_DEVOPS_DOMAIN', value: domain.presence || instance_domain, public: true } if has_domain?
variables variables
end end
end end
...@@ -284,7 +284,12 @@ ...@@ -284,7 +284,12 @@
.help-block .help-block
It will automatically build, test, and deploy applications based on a predefined CI/CD configuration It will automatically build, test, and deploy applications based on a predefined CI/CD configuration
= link_to icon('question-circle'), help_page_path('topics/autodevops/index.md') = link_to icon('question-circle'), help_page_path('topics/autodevops/index.md')
.form-group
= f.label :auto_devops_domain, class: 'control-label col-sm-2'
.col-sm-10
= f.text_field :auto_devops_domain, class: 'form-control', placeholder: 'domain.com'
.help-block
= s_("AdminSettings|Specify a domain to use by default for every project's Auto Review Apps and Auto Deploy stages.")
.form-group .form-group
.col-sm-offset-2.col-sm-10 .col-sm-offset-2.col-sm-10
.checkbox .checkbox
......
---
title: Add Auto DevOps Domain application setting
merge_request: 16604
author:
type: changed
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddAutoDevopsDomainToApplicationSettings < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
def change
add_column :application_settings, :auto_devops_domain, :string
end
end
...@@ -178,6 +178,7 @@ ActiveRecord::Schema.define(version: 20180204200836) do ...@@ -178,6 +178,7 @@ ActiveRecord::Schema.define(version: 20180204200836) do
t.integer "gitaly_timeout_medium", default: 30, null: false t.integer "gitaly_timeout_medium", default: 30, null: false
t.integer "gitaly_timeout_fast", default: 10, null: false t.integer "gitaly_timeout_fast", default: 10, null: false
t.boolean "mirror_available", default: true, null: false t.boolean "mirror_available", default: true, null: false
t.string "auto_devops_domain"
t.integer "default_project_creation", default: 2, null: false t.integer "default_project_creation", default: 2, null: false
end end
......
...@@ -70,6 +70,16 @@ feature 'Admin updates settings' do ...@@ -70,6 +70,16 @@ feature 'Admin updates settings' do
expect(page).to have_content "Application settings saved successfully" expect(page).to have_content "Application settings saved successfully"
end end
scenario 'Change AutoDevOps settings' do
check 'Enabled Auto DevOps (Beta) for projects by default'
fill_in 'Auto devops domain', with: 'domain.com'
click_button 'Save'
expect(Gitlab::CurrentSettings.auto_devops_enabled?).to be true
expect(Gitlab::CurrentSettings.auto_devops_domain).to eq('domain.com')
expect(page).to have_content "Application settings saved successfully"
end
scenario 'Change Slack Notifications Service template settings' do scenario 'Change Slack Notifications Service template settings' do
first(:link, 'Service Templates').click first(:link, 'Service Templates').click
click_link 'Slack notifications' click_link 'Slack notifications'
......
...@@ -82,4 +82,39 @@ describe AutoDevopsHelper do ...@@ -82,4 +82,39 @@ describe AutoDevopsHelper do
it { is_expected.to eq(false) } it { is_expected.to eq(false) }
end end
end end
describe '.auto_devops_warning_message' do
subject { helper.auto_devops_warning_message(project) }
context 'when the service is missing' do
before do
allow(helper).to receive(:missing_auto_devops_service?).and_return(true)
end
context 'when the domain is missing' do
before do
allow(helper).to receive(:missing_auto_devops_domain?).and_return(true)
end
it { is_expected.to match(/Auto Review Apps and Auto Deploy need a domain name and a .* to work correctly./) }
end
context 'when the domain is not missing' do
before do
allow(helper).to receive(:missing_auto_devops_domain?).and_return(false)
end
it { is_expected.to match(/Auto Review Apps and Auto Deploy need a .* to work correctly./) }
end
end
context 'when the domain is missing' do
before do
allow(helper).to receive(:missing_auto_devops_service?).and_return(false)
allow(helper).to receive(:missing_auto_devops_domain?).and_return(true)
end
it { is_expected.to eq('Auto Review Apps and Auto Deploy need a domain name to work correctly.') }
end
end
end end
...@@ -114,6 +114,40 @@ describe ApplicationSetting do ...@@ -114,6 +114,40 @@ describe ApplicationSetting do
it { expect(setting.repository_storages).to eq(['default']) } it { expect(setting.repository_storages).to eq(['default']) }
end end
context 'auto_devops_domain setting' do
context 'when auto_devops_enabled? is true' do
before do
setting.update(auto_devops_enabled: true)
end
it 'can be blank' do
setting.update(auto_devops_domain: '')
expect(setting).to be_valid
end
context 'with a valid value' do
before do
setting.update(auto_devops_domain: 'domain.com')
end
it 'is valid' do
expect(setting).to be_valid
end
end
context 'with an invalid value' do
before do
setting.update(auto_devops_domain: 'definitelynotahostname')
end
it 'is invalid' do
expect(setting).to be_invalid
end
end
end
end
context 'circuitbreaker settings' do context 'circuitbreaker settings' do
[:circuitbreaker_failure_count_threshold, [:circuitbreaker_failure_count_threshold,
:circuitbreaker_check_interval, :circuitbreaker_check_interval,
......
...@@ -18,7 +18,21 @@ describe ProjectAutoDevops do ...@@ -18,7 +18,21 @@ describe ProjectAutoDevops do
context 'when domain is empty' do context 'when domain is empty' do
let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: '') } let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: '') }
it { expect(auto_devops).not_to have_domain } context 'when there is an instance domain specified' do
before do
allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return('example.com')
end
it { expect(auto_devops).to have_domain }
end
context 'when there is no instance domain specified' do
before do
allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return(nil)
end
it { expect(auto_devops).not_to have_domain }
end
end end
end end
...@@ -29,9 +43,32 @@ describe ProjectAutoDevops do ...@@ -29,9 +43,32 @@ describe ProjectAutoDevops do
let(:domain) { 'example.com' } let(:domain) { 'example.com' }
it 'returns AUTO_DEVOPS_DOMAIN' do it 'returns AUTO_DEVOPS_DOMAIN' do
expect(auto_devops.variables).to include( expect(auto_devops.variables).to include(domain_variable)
{ key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true })
end end
end end
context 'when domain is not defined' do
let(:domain) { nil }
context 'when there is an instance domain specified' do
before do
allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return('example.com')
end
it { expect(auto_devops.variables).to include(domain_variable) }
end
context 'when there is no instance domain specified' do
before do
allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return(nil)
end
it { expect(auto_devops.variables).not_to include(domain_variable) }
end
end
def domain_variable
{ key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true }
end
end end
end end
...@@ -3420,18 +3420,40 @@ describe Project do ...@@ -3420,18 +3420,40 @@ describe Project do
subject { project.auto_devops_variables } subject { project.auto_devops_variables }
context 'when enabled in settings' do context 'when enabled in instance settings' do
before do before do
stub_application_setting(auto_devops_enabled: true) stub_application_setting(auto_devops_enabled: true)
end end
context 'when domain is empty' do
before do
stub_application_setting(auto_devops_domain: nil)
end
it 'variables does not include AUTO_DEVOPS_DOMAIN' do
is_expected.not_to include(domain_variable)
end
end
context 'when domain is configured' do
before do
stub_application_setting(auto_devops_domain: 'example.com')
end
it 'variables includes AUTO_DEVOPS_DOMAIN' do
is_expected.to include(domain_variable)
end
end
end
context 'when explicitely enabled' do
context 'when domain is empty' do context 'when domain is empty' do
before do before do
create(:project_auto_devops, project: project, domain: nil) create(:project_auto_devops, project: project, domain: nil)
end end
it 'variables are empty' do it 'variables does not include AUTO_DEVOPS_DOMAIN' do
is_expected.to be_empty is_expected.not_to include(domain_variable)
end end
end end
...@@ -3440,11 +3462,15 @@ describe Project do ...@@ -3440,11 +3462,15 @@ describe Project do
create(:project_auto_devops, project: project, domain: 'example.com') create(:project_auto_devops, project: project, domain: 'example.com')
end end
it "variables are not empty" do it 'variables includes AUTO_DEVOPS_DOMAIN' do
is_expected.not_to be_empty is_expected.to include(domain_variable)
end end
end end
end end
def domain_variable
{ key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true }
end
end end
describe '#latest_successful_builds_for' do describe '#latest_successful_builds_for' 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