2019-06-18 06:36:07 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
|
|
|
module Entry
|
|
|
|
##
|
|
|
|
# This class represents a global entry - root Entry for entire
|
|
|
|
# GitLab CI Configuration file.
|
|
|
|
#
|
|
|
|
class Root < ::Gitlab::Config::Entry::Node
|
|
|
|
include ::Gitlab::Config::Entry::Configurable
|
|
|
|
|
|
|
|
ALLOWED_KEYS = %i[default include before_script image services
|
2019-11-17 16:06:14 -05:00
|
|
|
after_script variables stages types cache workflow].freeze
|
2019-06-18 06:36:07 -04:00
|
|
|
|
|
|
|
validations do
|
|
|
|
validates :config, allowed_keys: ALLOWED_KEYS
|
|
|
|
end
|
|
|
|
|
|
|
|
# reserved:
|
|
|
|
# defines whether the node name is reserved
|
|
|
|
# the reserved name cannot be used a job name
|
|
|
|
# reserved should not be used as it will make
|
|
|
|
# breaking change to `.gitlab-ci.yml`
|
|
|
|
|
|
|
|
entry :default, Entry::Default,
|
|
|
|
description: 'Default configuration for all jobs.',
|
|
|
|
default: {}
|
|
|
|
|
|
|
|
entry :include, Entry::Includes,
|
|
|
|
description: 'List of external YAML files to include.',
|
|
|
|
reserved: true
|
|
|
|
|
|
|
|
entry :before_script, Entry::Script,
|
|
|
|
description: 'Script that will be executed before each job.',
|
|
|
|
reserved: true
|
|
|
|
|
|
|
|
entry :image, Entry::Image,
|
|
|
|
description: 'Docker image that will be used to execute jobs.',
|
|
|
|
reserved: true
|
|
|
|
|
|
|
|
entry :services, Entry::Services,
|
|
|
|
description: 'Docker images that will be linked to the container.',
|
|
|
|
reserved: true
|
|
|
|
|
|
|
|
entry :after_script, Entry::Script,
|
|
|
|
description: 'Script that will be executed after each job.',
|
|
|
|
reserved: true
|
|
|
|
|
|
|
|
entry :variables, Entry::Variables,
|
|
|
|
description: 'Environment variables that will be used.',
|
2020-12-15 07:10:17 -05:00
|
|
|
metadata: { use_value_data: true },
|
2019-06-18 06:36:07 -04:00
|
|
|
reserved: true
|
|
|
|
|
|
|
|
entry :stages, Entry::Stages,
|
|
|
|
description: 'Configuration of stages for this pipeline.',
|
|
|
|
reserved: true
|
|
|
|
|
|
|
|
entry :types, Entry::Stages,
|
|
|
|
description: 'Deprecated: stages for this pipeline.',
|
|
|
|
reserved: true
|
|
|
|
|
2021-05-07 08:10:27 -04:00
|
|
|
entry :cache, Entry::Caches,
|
2019-06-18 06:36:07 -04:00
|
|
|
description: 'Configure caching between build jobs.',
|
|
|
|
reserved: true
|
|
|
|
|
2019-11-17 16:06:14 -05:00
|
|
|
entry :workflow, Entry::Workflow,
|
2020-03-06 10:08:05 -05:00
|
|
|
description: 'List of evaluable rules to determine Pipeline status',
|
|
|
|
default: {}
|
2019-11-17 16:06:14 -05:00
|
|
|
|
2020-03-04 07:07:52 -05:00
|
|
|
dynamic_helpers :jobs
|
2019-06-18 06:36:07 -04:00
|
|
|
|
|
|
|
delegate :before_script_value,
|
|
|
|
:image_value,
|
|
|
|
:services_value,
|
|
|
|
:after_script_value,
|
2020-03-06 10:08:05 -05:00
|
|
|
:cache_value, to: :default_entry
|
2019-06-18 06:36:07 -04:00
|
|
|
|
|
|
|
attr_reader :jobs_config
|
|
|
|
|
|
|
|
class << self
|
|
|
|
include ::Gitlab::Utils::StrongMemoize
|
|
|
|
|
|
|
|
def reserved_nodes_names
|
|
|
|
strong_memoize(:reserved_nodes_names) do
|
|
|
|
self.nodes.select do |_, node|
|
|
|
|
node.reserved?
|
|
|
|
end.keys
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(config, **metadata)
|
|
|
|
super do
|
|
|
|
filter_jobs!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def compose!(_deps = nil)
|
|
|
|
super(self) do
|
|
|
|
compose_deprecated_entries!
|
|
|
|
compose_jobs!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
def compose_jobs!
|
|
|
|
factory = ::Gitlab::Config::Entry::Factory.new(Entry::Jobs)
|
|
|
|
.value(jobs_config)
|
|
|
|
.with(key: :jobs, parent: self,
|
|
|
|
description: 'Jobs definition for this pipeline')
|
|
|
|
|
|
|
|
@entries[:jobs] = factory.create!
|
|
|
|
end
|
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
|
|
|
|
|
|
|
def compose_deprecated_entries!
|
|
|
|
##
|
|
|
|
# Deprecated `:types` key workaround - if types are defined and
|
|
|
|
# stages are not defined we use types definition as stages.
|
|
|
|
#
|
|
|
|
if types_defined? && !stages_defined?
|
|
|
|
@entries[:stages] = @entries[:types]
|
|
|
|
end
|
|
|
|
|
|
|
|
@entries.delete(:types)
|
|
|
|
end
|
|
|
|
|
|
|
|
def filter_jobs!
|
|
|
|
return unless @config.is_a?(Hash)
|
|
|
|
|
|
|
|
@jobs_config = @config
|
2019-09-18 10:02:45 -04:00
|
|
|
.except(*self.class.reserved_nodes_names)
|
2019-06-18 06:36:07 -04:00
|
|
|
.select do |name, config|
|
2020-08-26 08:10:53 -04:00
|
|
|
Entry::Jobs.find_type(name, config).present? || ALLOWED_KEYS.exclude?(name)
|
2019-06-18 06:36:07 -04:00
|
|
|
end
|
|
|
|
|
2019-09-18 10:02:45 -04:00
|
|
|
@config = @config.except(*@jobs_config.keys)
|
2019-06-18 06:36:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|