From 770bcf71bb85c9eff13f4eb14cbd517986da9056 Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Wed, 30 Aug 2017 20:39:23 +0200 Subject: [PATCH] Form for setting project auto devops settings --- .../projects/pipelines_settings_controller.rb | 12 +++-- .../projects/settings/ci_cd_controller.rb | 5 +++ app/models/project.rb | 1 + .../application_settings/_form.html.haml | 8 +++- .../pipelines_settings/_show.html.haml | 44 ++++++++++++++++--- ...70828093725_create_project_auto_dev_ops.rb | 2 +- db/schema.rb | 5 +-- lib/gitlab/import_export/import_export.yml | 3 +- spec/lib/gitlab/import_export/all_models.yml | 1 + 9 files changed, 62 insertions(+), 19 deletions(-) diff --git a/app/controllers/projects/pipelines_settings_controller.rb b/app/controllers/projects/pipelines_settings_controller.rb index 9d24ebe2138..abab2e2f0c9 100644 --- a/app/controllers/projects/pipelines_settings_controller.rb +++ b/app/controllers/projects/pipelines_settings_controller.rb @@ -6,7 +6,7 @@ class Projects::PipelinesSettingsController < Projects::ApplicationController end def update - if @project.update_attributes(update_params) + if @project.update(update_params) flash[:notice] = "Pipelines settings for '#{@project.name}' were successfully updated." redirect_to project_settings_ci_cd_path(@project) else @@ -16,14 +16,12 @@ class Projects::PipelinesSettingsController < Projects::ApplicationController private - def create_params - params.require(:pipeline).permit(:ref) - end - def update_params params.require(:project).permit( - :runners_token, :builds_enabled, :build_allow_git_fetch, :build_timeout_in_minutes, :build_coverage_regex, - :public_builds, :auto_cancel_pending_pipelines, :ci_config_path + :runners_token, :builds_enabled, :build_allow_git_fetch, + :build_timeout_in_minutes, :build_coverage_regex, :public_builds, + :auto_cancel_pending_pipelines, :ci_config_path, + auto_devops_attributes: [:id, :domain, :enabled] ) end end diff --git a/app/controllers/projects/settings/ci_cd_controller.rb b/app/controllers/projects/settings/ci_cd_controller.rb index 15a2ff56b92..b029b31f9af 100644 --- a/app/controllers/projects/settings/ci_cd_controller.rb +++ b/app/controllers/projects/settings/ci_cd_controller.rb @@ -8,6 +8,7 @@ module Projects define_secret_variables define_triggers_variables define_badges_variables + define_auto_devops_variables end private @@ -42,6 +43,10 @@ module Projects badge.new(@project, @ref).metadata end end + + def define_auto_devops_variables + @auto_devops = @project.auto_devops || ProjectAutoDevops.new + end end end end diff --git a/app/models/project.rb b/app/models/project.rb index 56ba2620687..cc9fd215070 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -191,6 +191,7 @@ class Project < ActiveRecord::Base accepts_nested_attributes_for :variables, allow_destroy: true accepts_nested_attributes_for :project_feature accepts_nested_attributes_for :import_data + accepts_nested_attributes_for :auto_devops delegate :name, to: :owner, allow_nil: true, prefix: true delegate :members, to: :team, prefix: true diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml index a487f2b6995..a00fc978494 100644 --- a/app/views/admin/application_settings/_form.html.haml +++ b/app/views/admin/application_settings/_form.html.haml @@ -217,13 +217,17 @@ .help-block 0 for unlimited %fieldset - %legend Continuous Integration and Continuous Deployment + %legend Continuous Integration and Deployment .form-group .col-sm-offset-2.col-sm-10 .checkbox = f.label :auto_devops_enabled do = f.check_box :auto_devops_enabled - Allow projects to get automaticly configured to use GitLab CI/CD. + Enabled Auto DevOps (Beta) for projects by default + .help-block + It will automatically build, test, and deploy applications based on a predefined CI/CD configuration + - # Fix this link + = link_to icon('question-circle'), help_page_path('user/admin_area/settings/continuous_integration', anchor: 'maximum-artifacts-size') .form-group .col-sm-offset-2.col-sm-10 .checkbox diff --git a/app/views/projects/pipelines_settings/_show.html.haml b/app/views/projects/pipelines_settings/_show.html.haml index 255d7ef38e0..f4a6ecde0a4 100644 --- a/app/views/projects/pipelines_settings/_show.html.haml +++ b/app/views/projects/pipelines_settings/_show.html.haml @@ -5,11 +5,45 @@ .col-lg-8 = form_for @project, url: project_pipelines_settings_path(@project) do |f| %fieldset.builds-feature - - unless @repository.gitlab_ci_yml - .form-group - %p Pipelines need to be configured before you can begin using Continuous Integration. - = link_to 'Get started with Pipelines', help_page_path('ci/quick_start/README'), class: 'btn btn-info' - %hr + .form-group + %p Pipelines need to have AutoDevOps enabled or have a .gitlab-ci.yml configured before you can begin using Continious Integration and Delivery. + = f.label :auto_devops_enabled, 'Auto DevOps (Beta)', class: 'label-light' + %p + Auto DevOps will automatically build, test, and deploy your application based on a predefined CI/CD configuration. + = link_to 'Learn more about Auto DevOps', help_page_path('ci/quick_start/README') #TODO fix the link + = f.fields_for :auto_devops_attributes, @auto_devops do |form| + .radio + = form.radio_button :enabled, true + %strong Enable Auto DevOps + %br + %span.descr + The Auto DevOps pipeline configuration will be used when ther is no .gitlab-ci.yml + in the repository. + .radio + = form.radio_button :enabled, false + %strong Disable Auto DevOps + %br + %span.descr + A specific .gitlab-ci.yml file needs to be specified before you can begin using Continious Integration and Delivery + .radio + = form.radio_button :enabled, nil + %strong + Instance default (status: #{current_application_settings.auto_devops_enabled?}) + %br + %span.descr + Follow the instance default to either have Auto DevOps enabled or disabled when there is no .gitlab-ci.yml file specified + %br + %p + Define a domain used by Auto DevOps to deploy towards, this is required for deploys to succeed. + = link_to 'Learn more about deploying with Auto DevOps', help_page_path('ci/quick_start/README') #TODO fix the link + = form.text_field :domain, class: 'form-control', placeholder: 'domain.com' + %br + %p + %strong Project specific pipeline configuration + Define a project specific pipeline configuration by creating a .gitlab-ci.yml file. + = link_to 'Learn more about pipelines', help_page_path('ci/quick_start/README'), class: 'btn btn-info' + + %hr .form-group.append-bottom-default = f.label :runners_token, "Runner token", class: 'label-light' = f.text_field :runners_token, class: "form-control", placeholder: 'xEeFCaDAB89' diff --git a/db/migrate/20170828093725_create_project_auto_dev_ops.rb b/db/migrate/20170828093725_create_project_auto_dev_ops.rb index 818fc8ed970..a96ad644a2e 100644 --- a/db/migrate/20170828093725_create_project_auto_dev_ops.rb +++ b/db/migrate/20170828093725_create_project_auto_dev_ops.rb @@ -8,7 +8,7 @@ class CreateProjectAutoDevOps < ActiveRecord::Migration def up create_table :project_auto_devops do |t| t.belongs_to :project, index: true - t.boolean :enabled, default: true + t.boolean :enabled, default: nil, null: true t.string :domain end diff --git a/db/schema.rb b/db/schema.rb index 66ab6988649..1bc2a5eddc5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -250,7 +250,6 @@ ActiveRecord::Schema.define(version: 20170828093725) do add_index "ci_builds", ["commit_id", "status", "type"], name: "index_ci_builds_on_commit_id_and_status_and_type", using: :btree add_index "ci_builds", ["commit_id", "type", "name", "ref"], name: "index_ci_builds_on_commit_id_and_type_and_name_and_ref", using: :btree add_index "ci_builds", ["commit_id", "type", "ref"], name: "index_ci_builds_on_commit_id_and_type_and_ref", using: :btree - add_index "ci_builds", ["id"], name: "index_for_ci_builds_retried_migration", where: "(retried IS NULL)", using: :btree, opclasses: {"id)"=>"WHERE"} add_index "ci_builds", ["project_id"], name: "index_ci_builds_on_project_id", using: :btree add_index "ci_builds", ["runner_id"], name: "index_ci_builds_on_runner_id", using: :btree add_index "ci_builds", ["stage_id"], name: "index_ci_builds_on_stage_id", using: :btree @@ -1122,8 +1121,8 @@ ActiveRecord::Schema.define(version: 20170828093725) do t.integer "project_id" t.boolean "enabled", default: true t.string "domain" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime_with_timezone "created_at", null: false + t.datetime_with_timezone "updated_at", null: false end add_index "project_auto_devops", ["project_id"], name: "index_project_auto_devops_on_project_id", using: :btree diff --git a/lib/gitlab/import_export/import_export.yml b/lib/gitlab/import_export/import_export.yml index 78795dd3d92..d164a9adb2d 100644 --- a/lib/gitlab/import_export/import_export.yml +++ b/lib/gitlab/import_export/import_export.yml @@ -50,6 +50,7 @@ project_tree: - :push_event_payload - :stages - :statuses + - :project_auto_devops - :triggers - :pipeline_schedules - :services @@ -141,4 +142,4 @@ methods: events: - :action push_event_payload: - - :action \ No newline at end of file + - :action diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 8da02b0cf00..dbe042adff5 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -256,6 +256,7 @@ project: - environments - deployments - project_feature +- auto_devops - pages_domains - authorized_users - project_authorizations