Commit 38645a34 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '38542-application-control-panel-in-settings-page' into 'master'

Resolve "Add deploy strategies to Auto DevOps settings"

Closes #38542

See merge request gitlab-org/gitlab-ce!19172
parents f3cf5fc6 b780efab
...@@ -22,4 +22,18 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -22,4 +22,18 @@ document.addEventListener('DOMContentLoaded', () => {
errorBox: variableListEl.querySelector('.js-ci-variable-error-box'), errorBox: variableListEl.querySelector('.js-ci-variable-error-box'),
saveEndpoint: variableListEl.dataset.saveEndpoint, saveEndpoint: variableListEl.dataset.saveEndpoint,
}); });
// hide extra auto devops settings based on data-attributes
const autoDevOpsSettings = document.querySelector('.js-auto-devops-settings');
const autoDevOpsExtraSettings = document.querySelector('.js-extra-settings');
autoDevOpsSettings.addEventListener('click', event => {
const target = event.target;
if (target.classList.contains('js-toggle-extra-settings')) {
autoDevOpsExtraSettings.classList.toggle(
'hidden',
!!(target.dataset && target.dataset.hideExtraSettings),
);
}
});
}); });
...@@ -16,3 +16,12 @@ ...@@ -16,3 +16,12 @@
.registry-placeholder { .registry-placeholder {
min-height: 60px; min-height: 60px;
} }
.auto-devops-card {
margin-bottom: $gl-vert-padding;
> .card-body {
border-radius: $card-border-radius;
padding: $gl-padding $gl-padding-24;
}
}
...@@ -41,7 +41,7 @@ module Projects ...@@ -41,7 +41,7 @@ module Projects
:runners_token, :builds_enabled, :build_allow_git_fetch, :runners_token, :builds_enabled, :build_allow_git_fetch,
:build_timeout_human_readable, :build_coverage_regex, :public_builds, :build_timeout_human_readable, :build_coverage_regex, :public_builds,
:auto_cancel_pending_pipelines, :ci_config_path, :auto_cancel_pending_pipelines, :ci_config_path,
auto_devops_attributes: [:id, :domain, :enabled] auto_devops_attributes: [:id, :domain, :enabled, :deploy_strategy]
) )
end end
......
class ProjectAutoDevops < ActiveRecord::Base class ProjectAutoDevops < ActiveRecord::Base
belongs_to :project belongs_to :project
enum deploy_strategy: {
continuous: 0,
manual: 1
}
scope :enabled, -> { where(enabled: true) } scope :enabled, -> { where(enabled: true) }
scope :disabled, -> { where(enabled: false) } scope :disabled, -> { where(enabled: false) }
...@@ -22,6 +27,11 @@ class ProjectAutoDevops < ActiveRecord::Base ...@@ -22,6 +27,11 @@ class ProjectAutoDevops < ActiveRecord::Base
variables.append(key: 'AUTO_DEVOPS_DOMAIN', variables.append(key: 'AUTO_DEVOPS_DOMAIN',
value: domain.presence || instance_domain) value: domain.presence || instance_domain)
end end
if manual?
variables.append(key: 'STAGING_ENABLED', value: 1)
variables.append(key: 'INCREMENTAL_ROLLOUT_ENABLED', value: 1)
end
end end
end end
......
.row.prepend-top-default .row
.col-lg-12 .col-lg-12
= form_for @project, url: project_settings_ci_cd_path(@project) do |f| = form_for @project, url: project_settings_ci_cd_path(@project) do |f|
= form_errors(@project) = form_errors(@project)
%fieldset.builds-feature %fieldset.builds-feature.js-auto-devops-settings
.form-group .form-group
- message = auto_devops_warning_message(@project) - message = auto_devops_warning_message(@project)
- ci_file_formatted = '<code>.gitlab-ci.yml</code>'.html_safe - ci_file_formatted = '<code>.gitlab-ci.yml</code>'.html_safe
- if message - if message
%p.settings-message.text-center %p.auto-devops-warning-message.settings-message.text-center
= message.html_safe = message.html_safe
= f.fields_for :auto_devops_attributes, @auto_devops do |form| = f.fields_for :auto_devops_attributes, @auto_devops do |form|
.card.auto-devops-card
.card-body
.form-check .form-check
= form.radio_button :enabled, 'true', class: 'form-check-input' = form.radio_button :enabled, 'true', class: 'form-check-input js-toggle-extra-settings'
= form.label :enabled_true, class: 'form-check-label' do = form.label :enabled_true, class: 'form-check-label' do
%strong= s_('CICD|Enable Auto DevOps') %strong= s_('CICD|Enable Auto DevOps')
%br .form-text.text-muted
= s_('CICD|The Auto DevOps pipeline configuration will be used when there is no %{ci_file} in the project.').html_safe % { ci_file: ci_file_formatted } = s_('CICD|The Auto DevOps pipeline configuration will be used when there is no %{ci_file} in the project.').html_safe % { ci_file: ci_file_formatted }
.card.auto-devops-card
.card-body
.form-check .form-check
= form.radio_button :enabled, 'false', class: 'form-check-input' = form.radio_button :enabled, '', class: 'form-check-input js-toggle-extra-settings'
= form.label :enabled_false, class: 'form-check-label' do
%strong= s_('CICD|Disable Auto DevOps')
%br
= s_('CICD|An explicit %{ci_file} needs to be specified before you can begin using Continuous Integration and Delivery.').html_safe % { ci_file: ci_file_formatted }
.form-check
= form.radio_button :enabled, '', class: 'form-check-input'
= form.label :enabled_, class: 'form-check-label' do = form.label :enabled_, class: 'form-check-label' do
%strong= s_('CICD|Instance default (%{state})') % { state: "#{Gitlab::CurrentSettings.auto_devops_enabled? ? _('enabled') : _('disabled')}" } %strong= s_('CICD|Instance default (%{state})') % { state: "#{Gitlab::CurrentSettings.auto_devops_enabled? ? _('enabled') : _('disabled')}" }
%br .form-text.text-muted
= s_('CICD|Follow the instance default to either have Auto DevOps enabled or disabled when there is no project specific %{ci_file}.').html_safe % { ci_file: ci_file_formatted } = s_('CICD|Follow the instance default to either have Auto DevOps enabled or disabled when there is no project specific %{ci_file}.').html_safe % { ci_file: ci_file_formatted }
= form.label :domain, class:"prepend-top-10" do .card.auto-devops-card.js-extra-settings{ class: form.object&.enabled == false ? 'hidden' : nil }
= _('Domain') .card-body.bg-light
= form.label :domain do
%strong= _('Domain')
= form.text_field :domain, class: 'form-control', placeholder: 'domain.com' = form.text_field :domain, class: 'form-control', placeholder: 'domain.com'
.form-text.text-muted .form-text.text-muted
= s_('CICD|A domain is required to use Auto Review Apps and Auto Deploy Stages.') = s_('CICD|You need to specify a domain if you want to use Auto Review Apps and Auto Deploy stages.')
- if cluster_ingress_ip = cluster_ingress_ip(@project) - if cluster_ingress_ip = cluster_ingress_ip(@project)
= s_('%{nip_domain} can be used as an alternative to a custom domain.').html_safe % { nip_domain: "<code>#{cluster_ingress_ip}.nip.io</code>".html_safe } = s_('%{nip_domain} can be used as an alternative to a custom domain.').html_safe % { nip_domain: "<code>#{cluster_ingress_ip}.nip.io</code>".html_safe }
= link_to icon('question-circle'), help_page_path('topics/autodevops/index.md', anchor: 'auto-devops-base-domain'), target: '_blank' = link_to icon('question-circle'), help_page_path('topics/autodevops/index.md', anchor: 'auto-devops-base-domain'), target: '_blank'
%label.prepend-top-10
%strong= s_('CICD|Deployment strategy')
%p.settings-message.text-center
= s_('CICD|Deployment strategy needs a domain name to work correctly.')
.form-check
= form.radio_button :deploy_strategy, 'continuous', class: 'form-check-input'
= form.label :deploy_strategy_continuous, class: 'form-check-label' do
%strong= s_('CICD|Continuous deployment to production')
= link_to icon('question-circle'), help_page_path('topics/autodevops/index.md', anchor: 'auto-deploy'), target: '_blank'
.form-check
= form.radio_button :deploy_strategy, 'manual', class: 'form-check-input'
= form.label :deploy_strategy_manual, class: 'form-check-label' do
%strong= s_('CICD|Automatic deployment to staging, manual deployment to production')
= link_to icon('question-circle'), help_page_path('ci/environments.md', anchor: 'manually-deploying-to-environments'), target: '_blank'
.card.auto-devops-card
.card-body
.form-check
= form.radio_button :enabled, 'false', class: 'form-check-input js-toggle-extra-settings', data: { hide_extra_settings: true }
= form.label :enabled_false, class: 'form-check-label' do
%strong= s_('CICD|Disable Auto DevOps')
.form-text.text-muted
= s_('CICD|An explicit %{ci_file} needs to be specified before you can begin using Continuous Integration and Delivery.').html_safe % { ci_file: ci_file_formatted }
= f.submit 'Save changes', class: "btn btn-success prepend-top-15" = f.submit 'Save changes', class: "btn btn-success prepend-top-15"
---
title: Add deploy strategies to the Auto DevOps settings
merge_request: 19172
author:
type: added
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddDeployStrategyToProjectAutoDevops < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
disable_ddl_transaction!
def up
add_column_with_default :project_auto_devops, :deploy_strategy, :integer, default: 0, allow_null: false
end
def down
remove_column :project_auto_devops, :deploy_strategy
end
end
...@@ -1494,6 +1494,7 @@ ActiveRecord::Schema.define(version: 20180603190921) do ...@@ -1494,6 +1494,7 @@ ActiveRecord::Schema.define(version: 20180603190921) do
t.datetime_with_timezone "updated_at", null: false t.datetime_with_timezone "updated_at", null: false
t.boolean "enabled" t.boolean "enabled"
t.string "domain" t.string "domain"
t.integer "deploy_strategy", default: 0, null: false
end end
add_index "project_auto_devops", ["project_id"], name: "index_project_auto_devops_on_project_id", unique: true, using: :btree add_index "project_auto_devops", ["project_id"], name: "index_project_auto_devops_on_project_id", unique: true, using: :btree
......
...@@ -3,6 +3,11 @@ FactoryBot.define do ...@@ -3,6 +3,11 @@ FactoryBot.define do
project project
enabled true enabled true
domain "example.com" domain "example.com"
deploy_strategy :continuous
trait :manual do
deploy_strategy :manual
end
trait :disabled do trait :disabled do
enabled false enabled false
......
...@@ -540,6 +540,7 @@ ProjectAutoDevops: ...@@ -540,6 +540,7 @@ ProjectAutoDevops:
- id - id
- enabled - enabled
- domain - domain
- deploy_strategy
- project_id - project_id
- created_at - created_at
- updated_at - updated_at
......
...@@ -5,6 +5,8 @@ describe ProjectAutoDevops do ...@@ -5,6 +5,8 @@ describe ProjectAutoDevops do
it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:project) }
it { is_expected.to define_enum_for(:deploy_strategy) }
it { is_expected.to respond_to(:created_at) } it { is_expected.to respond_to(:created_at) }
it { is_expected.to respond_to(:updated_at) } it { is_expected.to respond_to(:updated_at) }
...@@ -67,6 +69,32 @@ describe ProjectAutoDevops do ...@@ -67,6 +69,32 @@ describe ProjectAutoDevops do
end end
end end
context 'when deploy_strategy is manual' do
let(:domain) { 'example.com' }
before do
auto_devops.deploy_strategy = 'manual'
end
it do
expect(auto_devops.predefined_variables.map { |var| var[:key] })
.to include("STAGING_ENABLED", "INCREMENTAL_ROLLOUT_ENABLED")
end
end
context 'when deploy_strategy is continuous' do
let(:domain) { 'example.com' }
before do
auto_devops.deploy_strategy = 'continuous'
end
it do
expect(auto_devops.predefined_variables.map { |var| var[:key] })
.not_to include("STAGING_ENABLED", "INCREMENTAL_ROLLOUT_ENABLED")
end
end
def domain_variable def domain_variable
{ key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true } { key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true }
end end
......
...@@ -12,7 +12,7 @@ describe 'projects/settings/ci_cd/_autodevops_form' do ...@@ -12,7 +12,7 @@ describe 'projects/settings/ci_cd/_autodevops_form' do
it 'shows warning message' do it 'shows warning message' do
render render
expect(rendered).to have_css('.settings-message') expect(rendered).to have_css('.auto-devops-warning-message')
expect(rendered).to have_text('Auto Review Apps and Auto Deploy need a domain name and a') expect(rendered).to have_text('Auto Review Apps and Auto Deploy need a domain name and a')
expect(rendered).to have_link('Kubernetes cluster') expect(rendered).to have_link('Kubernetes cluster')
end end
...@@ -26,7 +26,7 @@ describe 'projects/settings/ci_cd/_autodevops_form' do ...@@ -26,7 +26,7 @@ describe 'projects/settings/ci_cd/_autodevops_form' do
it 'shows warning message' do it 'shows warning message' do
render render
expect(rendered).to have_css('.settings-message') expect(rendered).to have_css('.auto-devops-warning-message')
expect(rendered).to have_text('Auto Review Apps and Auto Deploy need a') expect(rendered).to have_text('Auto Review Apps and Auto Deploy need a')
expect(rendered).to have_link('Kubernetes cluster') expect(rendered).to have_link('Kubernetes cluster')
end end
...@@ -42,7 +42,7 @@ describe 'projects/settings/ci_cd/_autodevops_form' do ...@@ -42,7 +42,7 @@ describe 'projects/settings/ci_cd/_autodevops_form' do
it 'shows warning message' do it 'shows warning message' do
render render
expect(rendered).to have_css('.settings-message') expect(rendered).to have_css('.auto-devops-warning-message')
expect(rendered).to have_text('Auto Review Apps and Auto Deploy need a domain name to work correctly.') expect(rendered).to have_text('Auto Review Apps and Auto Deploy need a domain name to work correctly.')
end end
end end
...@@ -55,7 +55,7 @@ describe 'projects/settings/ci_cd/_autodevops_form' do ...@@ -55,7 +55,7 @@ describe 'projects/settings/ci_cd/_autodevops_form' do
it 'does not show warning message' do it 'does not show warning message' do
render render
expect(rendered).not_to have_css('.settings-message') expect(rendered).not_to have_css('.auto-devops-warning-message')
end end
end end
end 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