summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-05 06:09:26 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-05 06:09:26 +0000
commit5092e9b37cf208ec604470afd4ebb62b1b58673e (patch)
tree63791ca37fcf888cadfcd24ce2708d745d5fcf44 /lib
parent4b4d338d32fa30c7dcbf0ed54e99c00a56d66ff3 (diff)
downloadgitlab-ce-5092e9b37cf208ec604470afd4ebb62b1b58673e.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/ci/config/entry/cache.rb112
-rw-r--r--lib/gitlab/ci/features.rb4
-rw-r--r--lib/gitlab/ci/pipeline/seed/build.rb28
-rw-r--r--lib/gitlab/ci/pipeline/seed/build/cache.rb22
-rw-r--r--lib/gitlab/graphql/docs/helper.rb2
5 files changed, 116 insertions, 52 deletions
diff --git a/lib/gitlab/ci/config/entry/cache.rb b/lib/gitlab/ci/config/entry/cache.rb
index 6b036182706..cf599ce5294 100644
--- a/lib/gitlab/ci/config/entry/cache.rb
+++ b/lib/gitlab/ci/config/entry/cache.rb
@@ -7,52 +7,90 @@ module Gitlab
##
# Entry that represents a cache configuration
#
- class Cache < ::Gitlab::Config::Entry::Node
- include ::Gitlab::Config::Entry::Configurable
- include ::Gitlab::Config::Entry::Validatable
- include ::Gitlab::Config::Entry::Attributable
-
- ALLOWED_KEYS = %i[key untracked paths when policy].freeze
- ALLOWED_POLICY = %w[pull-push push pull].freeze
- DEFAULT_POLICY = 'pull-push'
- ALLOWED_WHEN = %w[on_success on_failure always].freeze
- DEFAULT_WHEN = 'on_success'
-
- validations do
- validates :config, type: Hash, allowed_keys: ALLOWED_KEYS
- validates :policy,
- inclusion: { in: ALLOWED_POLICY, message: 'should be pull-push, push, or pull' },
- allow_blank: true
-
- with_options allow_nil: true do
- validates :when,
- inclusion: {
- in: ALLOWED_WHEN,
- message: 'should be on_success, on_failure or always'
- }
+ class Cache < ::Gitlab::Config::Entry::Simplifiable
+ strategy :Caches, if: -> (config) { Feature.enabled?(:multiple_cache_per_job) }
+ strategy :Cache, if: -> (config) { Feature.disabled?(:multiple_cache_per_job) }
+
+ class Caches < ::Gitlab::Config::Entry::ComposableArray
+ include ::Gitlab::Config::Entry::Validatable
+
+ MULTIPLE_CACHE_LIMIT = 4
+
+ validations do
+ validates :config, presence: true
+
+ validate do
+ unless config.is_a?(Hash) || config.is_a?(Array)
+ errors.add(:config, 'can only be a Hash or an Array')
+ end
+
+ if config.is_a?(Array) && config.count > MULTIPLE_CACHE_LIMIT
+ errors.add(:config, "no more than #{MULTIPLE_CACHE_LIMIT} caches can be created")
+ end
+ end
+ end
+
+ def initialize(*args)
+ super
+
+ @key = nil
+ end
+
+ def composable_class
+ Entry::Cache::Cache
end
end
- entry :key, Entry::Key,
- description: 'Cache key used to define a cache affinity.'
+ class Cache < ::Gitlab::Config::Entry::Node
+ include ::Gitlab::Config::Entry::Configurable
+ include ::Gitlab::Config::Entry::Validatable
+ include ::Gitlab::Config::Entry::Attributable
+
+ ALLOWED_KEYS = %i[key untracked paths when policy].freeze
+ ALLOWED_POLICY = %w[pull-push push pull].freeze
+ DEFAULT_POLICY = 'pull-push'
+ ALLOWED_WHEN = %w[on_success on_failure always].freeze
+ DEFAULT_WHEN = 'on_success'
+
+ validations do
+ validates :config, type: Hash, allowed_keys: ALLOWED_KEYS
+ validates :policy,
+ inclusion: { in: ALLOWED_POLICY, message: 'should be pull-push, push, or pull' },
+ allow_blank: true
+
+ with_options allow_nil: true do
+ validates :when,
+ inclusion: {
+ in: ALLOWED_WHEN,
+ message: 'should be on_success, on_failure or always'
+ }
+ end
+ end
- entry :untracked, ::Gitlab::Config::Entry::Boolean,
- description: 'Cache all untracked files.'
+ entry :key, Entry::Key,
+ description: 'Cache key used to define a cache affinity.'
- entry :paths, Entry::Paths,
- description: 'Specify which paths should be cached across builds.'
+ entry :untracked, ::Gitlab::Config::Entry::Boolean,
+ description: 'Cache all untracked files.'
- attributes :policy, :when
+ entry :paths, Entry::Paths,
+ description: 'Specify which paths should be cached across builds.'
- def value
- result = super
+ attributes :policy, :when
- result[:key] = key_value
- result[:policy] = policy || DEFAULT_POLICY
- # Use self.when to avoid conflict with reserved word
- result[:when] = self.when || DEFAULT_WHEN
+ def value
+ result = super
+
+ result[:key] = key_value
+ result[:policy] = policy || DEFAULT_POLICY
+ # Use self.when to avoid conflict with reserved word
+ result[:when] = self.when || DEFAULT_WHEN
+
+ result
+ end
+ end
- result
+ class UnknownStrategy < ::Gitlab::Config::Entry::Node
end
end
end
diff --git a/lib/gitlab/ci/features.rb b/lib/gitlab/ci/features.rb
index 2e89aa7bc31..021ec02fb84 100644
--- a/lib/gitlab/ci/features.rb
+++ b/lib/gitlab/ci/features.rb
@@ -67,6 +67,10 @@ module Gitlab
def self.display_codequality_backend_comparison?(project)
::Feature.enabled?(:codequality_backend_comparison, project, default_enabled: :yaml)
end
+
+ def self.multiple_cache_per_job?
+ ::Feature.enabled?(:multiple_cache_per_job, default_enabled: :yaml)
+ end
end
end
end
diff --git a/lib/gitlab/ci/pipeline/seed/build.rb b/lib/gitlab/ci/pipeline/seed/build.rb
index 2333e8b9d5b..896dba9f117 100644
--- a/lib/gitlab/ci/pipeline/seed/build.rb
+++ b/lib/gitlab/ci/pipeline/seed/build.rb
@@ -28,8 +28,16 @@ module Gitlab
.fabricate(attributes.delete(:except))
@rules = Gitlab::Ci::Build::Rules
.new(attributes.delete(:rules), default_when: 'on_success')
- @cache = Seed::Build::Cache
- .new(pipeline, attributes.delete(:cache))
+
+ if multiple_cache_per_job?
+ cache = Array.wrap(attributes.delete(:cache))
+ @cache = cache.map do |cache|
+ Seed::Build::Cache.new(pipeline, cache)
+ end
+ else
+ @cache = Seed::Build::Cache
+ .new(pipeline, attributes.delete(:cache))
+ end
end
def name
@@ -197,7 +205,21 @@ module Gitlab
def cache_attributes
strong_memoize(:cache_attributes) do
- @cache.build_attributes
+ if multiple_cache_per_job?
+ if @cache.empty?
+ {}
+ else
+ { options: { cache: @cache.map(&:attributes) } }
+ end
+ else
+ @cache.build_attributes
+ end
+ end
+ end
+
+ def multiple_cache_per_job?
+ strong_memoize(:multiple_cache_per_job) do
+ ::Gitlab::Ci::Features.multiple_cache_per_job?
end
end
diff --git a/lib/gitlab/ci/pipeline/seed/build/cache.rb b/lib/gitlab/ci/pipeline/seed/build/cache.rb
index 8d6fe13c3b9..78ffaaa7e81 100644
--- a/lib/gitlab/ci/pipeline/seed/build/cache.rb
+++ b/lib/gitlab/ci/pipeline/seed/build/cache.rb
@@ -18,18 +18,18 @@ module Gitlab
raise ArgumentError, "unknown cache keys: #{local_cache.keys}" if local_cache.any?
end
- def build_attributes
+ def attributes
{
- options: {
- cache: {
- key: key_string,
- paths: @paths,
- policy: @policy,
- untracked: @untracked,
- when: @when
- }.compact.presence
- }.compact
- }
+ key: key_string,
+ paths: @paths,
+ policy: @policy,
+ untracked: @untracked,
+ when: @when
+ }.compact
+ end
+
+ def build_attributes
+ { options: { cache: attributes.presence }.compact }
end
private
diff --git a/lib/gitlab/graphql/docs/helper.rb b/lib/gitlab/graphql/docs/helper.rb
index 6f891ad678a..68a2a78d0d4 100644
--- a/lib/gitlab/graphql/docs/helper.rb
+++ b/lib/gitlab/graphql/docs/helper.rb
@@ -28,7 +28,7 @@ module Gitlab
end
def render_name_and_description(object)
- content = "### #{object[:name]}\n"
+ content = "### `#{object[:name]}`\n"
if object[:description].present?
content += "\n#{object[:description]}"