diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-02-14 13:00:37 +0300 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-02-15 10:31:51 +0300 |
commit | d2d30cff552e08c4b7ec2b5e23acced8eb29cbcb (patch) | |
tree | 7d7c8055b57aee85426cd150c6f42dc1b7c0a675 | |
parent | 1452729304393978ec93b712130dff6687db01b9 (diff) |
Initial implementation for default artifacts expiration
TODO: Add tests and screenshots
-rw-r--r-- | app/controllers/admin/application_settings_controller.rb | 1 | ||||
-rw-r--r-- | app/models/application_setting.rb | 19 | ||||
-rw-r--r-- | app/models/ci/build.rb | 11 | ||||
-rw-r--r-- | app/views/admin/application_settings/_form.html.haml | 9 | ||||
-rw-r--r-- | db/migrate/20170214084746_add_default_artifacts_expiration_to_application_settings.rb | 11 | ||||
-rw-r--r-- | doc/user/admin_area/settings/continuous_integration.md | 26 | ||||
-rw-r--r-- | lib/api/settings.rb | 7 | ||||
-rw-r--r-- | lib/ci/api/builds.rb | 2 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 2 |
9 files changed, 77 insertions, 11 deletions
diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb index b0f5d4a9933..0559b5fa1bd 100644 --- a/app/controllers/admin/application_settings_controller.rb +++ b/app/controllers/admin/application_settings_controller.rb @@ -83,6 +83,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController :akismet_api_key, :akismet_enabled, :container_registry_token_expire_delay, + :default_artifacts_expiration, :default_branch_protection, :default_group_visibility, :default_project_visibility, diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index 74b358d8c40..a871dc9e5b9 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -76,6 +76,14 @@ class ApplicationSetting < ActiveRecord::Base presence: true, numericality: { only_integer: true, greater_than: 0 } + validates :max_artifacts_size, + presence: true, + numericality: { only_integer: true, greater_than: 0 } + + validates :default_artifacts_expiration, + presence: true, + numericality: { only_integer: true, greater_than_or_equal_to: 0 } + validates :container_registry_token_expire_delay, presence: true, numericality: { only_integer: true, greater_than: 0 } @@ -168,6 +176,7 @@ class ApplicationSetting < ActiveRecord::Base after_sign_up_text: nil, akismet_enabled: false, container_registry_token_expire_delay: 5, + default_artifacts_expiration: 30, default_branch_protection: Settings.gitlab['default_branch_protection'], default_project_visibility: Settings.gitlab.default_projects_features['visibility_level'], default_projects_limit: Settings.gitlab['default_projects_limit'], @@ -201,9 +210,9 @@ class ApplicationSetting < ActiveRecord::Base sign_in_text: nil, signin_enabled: Settings.gitlab['signin_enabled'], signup_enabled: Settings.gitlab['signup_enabled'], + terminal_max_session_time: 0, two_factor_grace_period: 48, - user_default_external: false, - terminal_max_session_time: 0 + user_default_external: false } end @@ -282,6 +291,12 @@ class ApplicationSetting < ActiveRecord::Base sidekiq_throttling_enabled end + def default_artifacts_expire_in + if default_artifacts_expiration.nonzero? + "#{default_artifacts_expiration} days" + end + end + private def check_repository_storages diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 8c1b076c2d7..77f027d17b6 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -513,6 +513,17 @@ module Ci end end + def set_artifacts_expire_in(expire_in) + value = + if expire_in + expire_in + else + ApplicationSetting.current.default_artifacts_expire_in + end + + self.artifacts_expire_in = value + end + def has_expiring_artifacts? artifacts_expire_at.present? end diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml index 816035ec442..86ce534ea18 100644 --- a/app/views/admin/application_settings/_form.html.haml +++ b/app/views/admin/application_settings/_form.html.haml @@ -212,8 +212,15 @@ .col-sm-10 = f.number_field :max_artifacts_size, class: 'form-control' .help-block - Set the maximum file size each jobs's artifacts can have + Set the maximum file size for each job's artifacts = link_to "(?)", help_page_path("user/admin_area/settings/continuous_integration", anchor: "maximum-artifacts-size") + .form-group + = f.label :default_artifacts_expiration, 'Default artifacts expiration (days)', class: 'control-label col-sm-2' + .col-sm-10 + = f.number_field :default_artifacts_expiration, class: 'form-control' + .help-block + Set the default expiration time for each job's artifacts (0 as never expired) + = link_to "(?)", help_page_path("user/admin_area/settings/continuous_integration", anchor: "default-artifacts-expiration") - if Gitlab.config.registry.enabled %fieldset diff --git a/db/migrate/20170214084746_add_default_artifacts_expiration_to_application_settings.rb b/db/migrate/20170214084746_add_default_artifacts_expiration_to_application_settings.rb new file mode 100644 index 00000000000..728d581251c --- /dev/null +++ b/db/migrate/20170214084746_add_default_artifacts_expiration_to_application_settings.rb @@ -0,0 +1,11 @@ +class AddDefaultArtifactsExpirationToApplicationSettings < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def change + add_column :application_settings, + :default_artifacts_expiration, + :integer, default: 0, null: false + end +end diff --git a/doc/user/admin_area/settings/continuous_integration.md b/doc/user/admin_area/settings/continuous_integration.md index 34e2e557f89..0455881ebf2 100644 --- a/doc/user/admin_area/settings/continuous_integration.md +++ b/doc/user/admin_area/settings/continuous_integration.md @@ -2,19 +2,37 @@ ## Maximum artifacts size -The maximum size of the [build artifacts][art-yml] can be set in the Admin area -of your GitLab instance. The value is in MB and the default is 100MB. Note that -this setting is set for each build. +The maximum size of the [build artifacts][art-yml] can be set in the Admin +area of your GitLab instance. The value is in *MB* and the default is 100MB. +Note that this setting is set for each job. 1. Go to **Admin area > Settings** (`/admin/application_settings`). ![Admin area settings button](img/admin_area_settings_button.png) -1. Change the value of the maximum artifacts size (in MB): +1. Change the value of maximum artifacts size (in MB): ![Admin area maximum artifacts size](img/admin_area_maximum_artifacts_size.png) 1. Hit **Save** for the changes to take effect. +[art-yml]: ../../../administration/build_artifacts.md + +## Default artifacts expiration time + +The default expiration time of the [build artifacts][art-yml] can be set in +the Admin area of your GitLab instance. The value is in *days* and the +default is 30 days. Note that this setting is set for each job. Set it to +0 as never expired by default. + +1. Go to **Admin area > Settings** (`/admin/application_settings`). + + ![Admin area settings button](img/admin_area_settings_button.png) + +1. Change the value of default expiration time (in days): + + ![Admin area default artifacts expiration](img/admin_area_default_artifacts_expiration.png) + +1. Hit **Save** for the changes to take effect. [art-yml]: ../../../administration/build_artifacts.md diff --git a/lib/api/settings.rb b/lib/api/settings.rb index 747ceb4e3e0..dabe6281755 100644 --- a/lib/api/settings.rb +++ b/lib/api/settings.rb @@ -56,7 +56,8 @@ module API given shared_runners_enabled: ->(val) { val } do requires :shared_runners_text, type: String, desc: 'Shared runners text ' end - optional :max_artifacts_size, type: Integer, desc: "Set the maximum file size each build's artifacts can have" + optional :max_artifacts_size, type: Integer, desc: "Set the maximum file size for each job's artifacts" + optional :default_artifacts_expiration, type: Integer, desc: "Set the default expiration time for each job's artifacts" optional :max_pages_size, type: Integer, desc: 'Maximum size of pages in MB' optional :container_registry_token_expire_delay, type: Integer, desc: 'Authorization token duration (minutes)' optional :metrics_enabled, type: Boolean, desc: 'Enable the InfluxDB metrics' @@ -117,7 +118,9 @@ module API :send_user_confirmation_email, :domain_whitelist, :domain_blacklist_enabled, :after_sign_up_text, :signin_enabled, :require_two_factor_authentication, :home_page_url, :after_sign_out_path, :sign_in_text, :help_page_text, - :shared_runners_enabled, :max_artifacts_size, :max_pages_size, :container_registry_token_expire_delay, + :shared_runners_enabled, :max_artifacts_size, + :default_artifacts_expiration, :max_pages_size, + :container_registry_token_expire_delay, :metrics_enabled, :sidekiq_throttling_enabled, :recaptcha_enabled, :akismet_enabled, :admin_notification_email, :sentry_enabled, :repository_storage, :repository_checks_enabled, :koding_enabled, :plantuml_enabled, diff --git a/lib/ci/api/builds.rb b/lib/ci/api/builds.rb index 8b939663ffd..7aad6c50b7b 100644 --- a/lib/ci/api/builds.rb +++ b/lib/ci/api/builds.rb @@ -167,7 +167,7 @@ module Ci build.artifacts_file = artifacts build.artifacts_metadata = metadata - build.artifacts_expire_in = params['expire_in'] + build.set_artifacts_expire_in(params['expire_in']) if build.save present(build, with: Entities::BuildDetails) diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 4080092405d..1e88dc9d468 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -161,7 +161,7 @@ describe Ci::Build, :models do is_expected.to be_nil end - it 'when resseting value' do + it 'when resetting value' do build.artifacts_expire_in = nil is_expected.to be_nil |