Commit d2d30cff authored by Lin Jen-Shin's avatar Lin Jen-Shin

Initial implementation for default artifacts expiration

TODO: Add tests and screenshots
parent 14527293
......@@ -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,
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
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
......@@ -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
......@@ -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,
......
......@@ -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)
......
......@@ -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
......
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