Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ci/config')
-rw-r--r--lib/gitlab/ci/config/entry/image.rb31
-rw-r--r--lib/gitlab/ci/config/entry/pull_policy.rb34
-rw-r--r--lib/gitlab/ci/config/entry/rules/rule.rb21
-rw-r--r--lib/gitlab/ci/config/entry/rules/rule/changes.rb23
-rw-r--r--lib/gitlab/ci/config/external/file/local.rb4
-rw-r--r--lib/gitlab/ci/config/external/file/project.rb4
-rw-r--r--lib/gitlab/ci/config/external/file/remote.rb4
-rw-r--r--lib/gitlab/ci/config/external/file/template.rb4
8 files changed, 108 insertions, 17 deletions
diff --git a/lib/gitlab/ci/config/entry/image.rb b/lib/gitlab/ci/config/entry/image.rb
index 21c42857895..79443f69b03 100644
--- a/lib/gitlab/ci/config/entry/image.rb
+++ b/lib/gitlab/ci/config/entry/image.rb
@@ -12,11 +12,13 @@ module Gitlab
include ::Gitlab::Config::Entry::Attributable
include ::Gitlab::Config::Entry::Configurable
- ALLOWED_KEYS = %i[name entrypoint ports].freeze
+ ALLOWED_KEYS = %i[name entrypoint ports pull_policy].freeze
+ LEGACY_ALLOWED_KEYS = %i[name entrypoint ports].freeze
validations do
validates :config, hash_or_string: true
- validates :config, allowed_keys: ALLOWED_KEYS
+ validates :config, allowed_keys: ALLOWED_KEYS, if: :ci_docker_image_pull_policy_enabled?
+ validates :config, allowed_keys: LEGACY_ALLOWED_KEYS, unless: :ci_docker_image_pull_policy_enabled?
validates :config, disallowed_keys: %i[ports], unless: :with_image_ports?
validates :name, type: String, presence: true
@@ -26,7 +28,10 @@ module Gitlab
entry :ports, Entry::Ports,
description: 'Ports used to expose the image'
- attributes :ports
+ entry :pull_policy, Entry::PullPolicy,
+ description: 'Pull policy for the image'
+
+ attributes :ports, :pull_policy
def name
value[:name]
@@ -37,16 +42,28 @@ module Gitlab
end
def value
- return { name: @config } if string?
- return @config if hash?
-
- {}
+ if string?
+ { name: @config }
+ elsif hash?
+ {
+ name: @config[:name],
+ entrypoint: @config[:entrypoint],
+ ports: ports_value,
+ pull_policy: (ci_docker_image_pull_policy_enabled? ? pull_policy_value : nil)
+ }.compact
+ else
+ {}
+ end
end
def with_image_ports?
opt(:with_image_ports)
end
+ def ci_docker_image_pull_policy_enabled?
+ ::Feature.enabled?(:ci_docker_image_pull_policy)
+ end
+
def skip_config_hash_validation?
true
end
diff --git a/lib/gitlab/ci/config/entry/pull_policy.rb b/lib/gitlab/ci/config/entry/pull_policy.rb
new file mode 100644
index 00000000000..f597134dd2c
--- /dev/null
+++ b/lib/gitlab/ci/config/entry/pull_policy.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ class Config
+ module Entry
+ ##
+ # Entry that represents a configuration of the pull policies of an image.
+ #
+ class PullPolicy < ::Gitlab::Config::Entry::Node
+ include ::Gitlab::Config::Entry::Validatable
+
+ ALLOWED_POLICIES = %w[always never if-not-present].freeze
+
+ validations do
+ validates :config, array_of_strings_or_string: true
+ validates :config,
+ allowed_array_values: { in: ALLOWED_POLICIES },
+ presence: true,
+ if: :array?
+ validates :config,
+ inclusion: { in: ALLOWED_POLICIES },
+ if: :string?
+ end
+
+ def value
+ # We either return an array with policies or nothing
+ Array(@config).presence
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/config/entry/rules/rule.rb b/lib/gitlab/ci/config/entry/rules/rule.rb
index 4722f2e9a61..63bf1b38ac6 100644
--- a/lib/gitlab/ci/config/entry/rules/rule.rb
+++ b/lib/gitlab/ci/config/entry/rules/rule.rb
@@ -9,11 +9,13 @@ module Gitlab
include ::Gitlab::Config::Entry::Configurable
include ::Gitlab::Config::Entry::Attributable
- CLAUSES = %i[if changes exists].freeze
- ALLOWED_KEYS = %i[if changes exists when start_in allow_failure variables].freeze
- ALLOWABLE_WHEN = %w[on_success on_failure always never manual delayed].freeze
+ ALLOWED_KEYS = %i[if changes exists when start_in allow_failure variables].freeze
+ ALLOWED_WHEN = %w[on_success on_failure always never manual delayed].freeze
- attributes :if, :changes, :exists, :when, :start_in, :allow_failure
+ attributes :if, :exists, :when, :start_in, :allow_failure
+
+ entry :changes, Entry::Rules::Rule::Changes,
+ description: 'File change condition rule.'
entry :variables, Entry::Variables,
description: 'Environment variables to define for rule conditions.'
@@ -28,8 +30,8 @@ module Gitlab
with_options allow_nil: true do
validates :if, expression: true
- validates :changes, :exists, array_of_strings: true, length: { maximum: 50 }
- validates :when, allowed_values: { in: ALLOWABLE_WHEN }
+ validates :exists, array_of_strings: true, length: { maximum: 50 }
+ validates :when, allowed_values: { in: ALLOWED_WHEN }
validates :allow_failure, boolean: true
end
@@ -41,6 +43,13 @@ module Gitlab
end
end
+ def value
+ config.merge(
+ changes: (changes_value if changes_defined?),
+ variables: (variables_value if variables_defined?)
+ ).compact
+ end
+
def specifies_delay?
self.when == 'delayed'
end
diff --git a/lib/gitlab/ci/config/entry/rules/rule/changes.rb b/lib/gitlab/ci/config/entry/rules/rule/changes.rb
new file mode 100644
index 00000000000..be57e089f34
--- /dev/null
+++ b/lib/gitlab/ci/config/entry/rules/rule/changes.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ class Config
+ module Entry
+ class Rules
+ class Rule
+ class Changes < ::Gitlab::Config::Entry::Node
+ include ::Gitlab::Config::Entry::Validatable
+
+ validations do
+ validates :config,
+ array_of_strings: true,
+ length: { maximum: 50, too_long: "has too many entries (maximum %{count})" }
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/config/external/file/local.rb b/lib/gitlab/ci/config/external/file/local.rb
index feb2cbb19ad..36fc5c656fc 100644
--- a/lib/gitlab/ci/config/external/file/local.rb
+++ b/lib/gitlab/ci/config/external/file/local.rb
@@ -42,7 +42,9 @@ module Gitlab
end
def fetch_local_content
- context.project.repository.blob_data_at(context.sha, location)
+ context.logger.instrument(:config_file_fetch_local_content) do
+ context.project.repository.blob_data_at(context.sha, location)
+ end
rescue GRPC::InvalidArgument
errors.push("Sha #{context.sha} is not valid!")
diff --git a/lib/gitlab/ci/config/external/file/project.rb b/lib/gitlab/ci/config/external/file/project.rb
index 09c36a1bcb6..b7fef081269 100644
--- a/lib/gitlab/ci/config/external/file/project.rb
+++ b/lib/gitlab/ci/config/external/file/project.rb
@@ -65,7 +65,9 @@ module Gitlab
return unless can_access_local_content?
return unless sha
- project.repository.blob_data_at(sha, location)
+ context.logger.instrument(:config_file_fetch_project_content) do
+ project.repository.blob_data_at(sha, location)
+ end
rescue GRPC::NotFound, GRPC::Internal
nil
end
diff --git a/lib/gitlab/ci/config/external/file/remote.rb b/lib/gitlab/ci/config/external/file/remote.rb
index 7d3a2362246..3984bf9e4f8 100644
--- a/lib/gitlab/ci/config/external/file/remote.rb
+++ b/lib/gitlab/ci/config/external/file/remote.rb
@@ -40,7 +40,9 @@ module Gitlab
def fetch_remote_content
begin
- response = Gitlab::HTTP.get(location)
+ response = context.logger.instrument(:config_file_fetch_remote_content) do
+ Gitlab::HTTP.get(location)
+ end
rescue SocketError
errors.push("Remote file `#{masked_location}` could not be fetched because of a socket error!")
rescue Timeout::Error
diff --git a/lib/gitlab/ci/config/external/file/template.rb b/lib/gitlab/ci/config/external/file/template.rb
index 58b81b259cb..5fcf7c71bdf 100644
--- a/lib/gitlab/ci/config/external/file/template.rb
+++ b/lib/gitlab/ci/config/external/file/template.rb
@@ -52,7 +52,9 @@ module Gitlab
end
def fetch_template_content
- Gitlab::Template::GitlabCiYmlTemplate.find(template_name, context.project)&.content
+ context.logger.instrument(:config_file_fetch_template_content) do
+ Gitlab::Template::GitlabCiYmlTemplate.find(template_name, context.project)&.content
+ end
end
def masked_raw