diff --git a/ee/lib/gitlab/web_ide/config/entry/global.rb b/ee/lib/gitlab/web_ide/config/entry/global.rb index 588189034427734c3120469ebfae43f98d126659..50c3f2d294f40731c4b44dbe7d024bc0baa93488 100644 --- a/ee/lib/gitlab/web_ide/config/entry/global.rb +++ b/ee/lib/gitlab/web_ide/config/entry/global.rb @@ -21,8 +21,6 @@ class Global < ::Gitlab::Config::Entry::Node entry :terminal, Entry::Terminal, description: 'Configuration of the webide terminal.' - helpers :terminal - attributes :terminal end end diff --git a/ee/lib/gitlab/web_ide/config/entry/terminal.rb b/ee/lib/gitlab/web_ide/config/entry/terminal.rb index b0121e0f6f65e46a636af6ea3bb3a519a74d313a..403e308d45b4189253d51b7201bb5ef48873db31 100644 --- a/ee/lib/gitlab/web_ide/config/entry/terminal.rb +++ b/ee/lib/gitlab/web_ide/config/entry/terminal.rb @@ -42,8 +42,6 @@ class Terminal < ::Gitlab::Config::Entry::Node entry :variables, ::Gitlab::Ci::Config::Entry::Variables, description: 'Environment variables available for this job.' - helpers :before_script, :script, :image, :variables, :services - attributes :tags def value diff --git a/lib/gitlab/ci/config/entry/artifacts.rb b/lib/gitlab/ci/config/entry/artifacts.rb index aebc1675bec92350d1b321b842af76f445097516..241c73db3bbf26a7e44bc2ea8a7adca7a316f754 100644 --- a/lib/gitlab/ci/config/entry/artifacts.rb +++ b/lib/gitlab/ci/config/entry/artifacts.rb @@ -44,8 +44,6 @@ class Artifacts < ::Gitlab::Config::Entry::Node end end - helpers :reports - def value @config[:reports] = reports_value if @config.key?(:reports) @config diff --git a/lib/gitlab/ci/config/entry/bridge.rb b/lib/gitlab/ci/config/entry/bridge.rb index 721c7c8b6d706284f8b9a9a2d72f91f50df98a7c..6fdaa3731706b2d58ba6eb58071272d98caa8b76 100644 --- a/lib/gitlab/ci/config/entry/bridge.rb +++ b/lib/gitlab/ci/config/entry/bridge.rb @@ -49,8 +49,6 @@ class Bridge < ::Gitlab::Config::Entry::Node description: 'Environment variables available for this job.', inherit: false - helpers :trigger, :needs, :variables - attributes :when, :allow_failure def self.matching?(name, config) diff --git a/lib/gitlab/ci/config/entry/cache.rb b/lib/gitlab/ci/config/entry/cache.rb index ef07c319ce4bcb375927ca1426eba9a6edc7cafc..a304d9b724f920165a291d2c4ebad83f8301a52b 100644 --- a/lib/gitlab/ci/config/entry/cache.rb +++ b/lib/gitlab/ci/config/entry/cache.rb @@ -28,8 +28,6 @@ class Cache < ::Gitlab::Config::Entry::Node entry :paths, Entry::Paths, description: 'Specify which paths should be cached across builds.' - helpers :key - attributes :policy def value diff --git a/lib/gitlab/ci/config/entry/default.rb b/lib/gitlab/ci/config/entry/default.rb index 88db17a75da7cb9249d07a9fd705c9ef37db8ebf..ab493ff7d78625aa87d25c20545c31a6a1b2c0f4 100644 --- a/lib/gitlab/ci/config/entry/default.rb +++ b/lib/gitlab/ci/config/entry/default.rb @@ -61,8 +61,6 @@ class Default < ::Gitlab::Config::Entry::Node description: 'Default artifacts.', inherit: false - helpers :before_script, :image, :services, :after_script, :cache - private def overwrite_entry(deps, key, current_entry) diff --git a/lib/gitlab/ci/config/entry/job.rb b/lib/gitlab/ci/config/entry/job.rb index 931f769e920b6bb3c2691a092e607ff9833da83e..8db21b116eb4995ad93d97c426e9a7da813277e6 100644 --- a/lib/gitlab/ci/config/entry/job.rb +++ b/lib/gitlab/ci/config/entry/job.rb @@ -128,11 +128,6 @@ class Job < ::Gitlab::Config::Entry::Node description: 'This job will produce a release.', inherit: false - helpers :before_script, :script, :type, :after_script, - :cache, :image, :services, :variables, - :artifacts, :environment, :coverage, :retry, - :needs, :interruptible, :release, :tags - attributes :script, :tags, :allow_failure, :when, :dependencies, :needs, :retry, :parallel, :start_in, :interruptible, :timeout, :resource_group, :release diff --git a/lib/gitlab/ci/config/entry/processable.rb b/lib/gitlab/ci/config/entry/processable.rb index 19e6601e31f4f702ea54c649eb8e82654b235d8a..bfa2905ed77e9db87c52044a456765cb2864b1b1 100644 --- a/lib/gitlab/ci/config/entry/processable.rb +++ b/lib/gitlab/ci/config/entry/processable.rb @@ -54,8 +54,6 @@ module Processable allowed_when: %w[on_success on_failure always never manual delayed].freeze } - helpers :stage, :only, :except, :rules - attributes :extends, :rules end diff --git a/lib/gitlab/ci/config/entry/release.rb b/lib/gitlab/ci/config/entry/release.rb index 3eceaa0ccd994b7df0c8c3ebdd259867c67d5236..b4e4c1497306b7e484647a550d5436cecbff9369 100644 --- a/lib/gitlab/ci/config/entry/release.rb +++ b/lib/gitlab/ci/config/entry/release.rb @@ -33,8 +33,6 @@ def description validates :description, type: String, presence: true end - helpers :assets - def value @config[:assets] = assets_value if @config.key?(:assets) @config diff --git a/lib/gitlab/ci/config/entry/release/assets.rb b/lib/gitlab/ci/config/entry/release/assets.rb index 82ed39f51e01b3a4e5a52c8ee262ec19f02e1267..1f7057d1bf6008f546ac23adad35436d47eaeb22 100644 --- a/lib/gitlab/ci/config/entry/release/assets.rb +++ b/lib/gitlab/ci/config/entry/release/assets.rb @@ -23,8 +23,6 @@ class Assets < ::Gitlab::Config::Entry::Node validates :links, array_of_hashes: true, presence: true end - helpers :links - def value @config[:links] = links_value if @config.key?(:links) @config diff --git a/lib/gitlab/ci/config/entry/root.rb b/lib/gitlab/ci/config/entry/root.rb index 620f6a95e9dcf72e170d548e64e7788166f4d386..caa0725c4bdbc8061df0440a87deead349c22027 100644 --- a/lib/gitlab/ci/config/entry/root.rb +++ b/lib/gitlab/ci/config/entry/root.rb @@ -67,9 +67,7 @@ class Root < ::Gitlab::Config::Entry::Node entry :workflow, Entry::Workflow, description: 'List of evaluable rules to determine Pipeline status' - helpers :default, :stages, :types, :variables, :workflow - - helpers :jobs, dynamic: true + dynamic_helpers :jobs delegate :before_script_value, :image_value, diff --git a/lib/gitlab/ci/config/entry/service.rb b/lib/gitlab/ci/config/entry/service.rb index 8d16371e857b4f6a6508aa1916003f17dcdc22f1..247bf930d3b9e890ae63602aeb5dfc5fa2f1e6da 100644 --- a/lib/gitlab/ci/config/entry/service.rb +++ b/lib/gitlab/ci/config/entry/service.rb @@ -7,8 +7,13 @@ module Entry ## # Entry that represents a configuration of Docker service. # - class Service < Image + # TODO: remove duplication with Image superclass by defining a common + # Imageable concern. + # https://gitlab.com/gitlab-org/gitlab/issues/208774 + class Service < ::Gitlab::Config::Entry::Node include ::Gitlab::Config::Entry::Validatable + include ::Gitlab::Config::Entry::Attributable + include ::Gitlab::Config::Entry::Configurable ALLOWED_KEYS = %i[name entrypoint command alias ports].freeze @@ -16,9 +21,9 @@ class Service < Image validates :config, hash_or_string: true validates :config, allowed_keys: ALLOWED_KEYS validates :config, disallowed_keys: %i[ports], unless: :with_image_ports? - validates :name, type: String, presence: true validates :entrypoint, array_of_strings: true, allow_nil: true + validates :command, array_of_strings: true, allow_nil: true validates :alias, type: String, allow_nil: true validates :alias, type: String, presence: true, unless: ->(record) { record.ports.blank? } @@ -27,6 +32,8 @@ class Service < Image entry :ports, Entry::Ports, description: 'Ports used to expose the service' + attributes :ports + def alias value[:alias] end @@ -34,6 +41,29 @@ def alias def command value[:command] end + + def name + value[:name] + end + + def entrypoint + value[:entrypoint] + end + + def value + return { name: @config } if string? + return @config if hash? + + {} + end + + def with_image_ports? + opt(:with_image_ports) + end + + def skip_config_hash_validation? + true + end end end end diff --git a/lib/gitlab/config/entry/configurable.rb b/lib/gitlab/config/entry/configurable.rb index 75e15cd8cb1d362f86e397db6c7492b77e3bee4a..3fd562c29040733fe0c1520713f53d37f771ef3e 100644 --- a/lib/gitlab/config/entry/configurable.rb +++ b/lib/gitlab/config/entry/configurable.rb @@ -75,7 +75,8 @@ def reserved_node_names # rubocop: disable CodeReuse/ActiveRecord def entry(key, entry, description: nil, default: nil, inherit: nil, reserved: nil, metadata: {}) - raise ArgumentError, "Entry #{key} already defined" if @nodes.to_h[key.to_sym] + entry_name = key.to_sym + raise ArgumentError, "Entry #{key} already defined" if @nodes.to_h[entry_name] factory = ::Gitlab::Config::Entry::Factory.new(entry) .with(description: description) @@ -84,10 +85,17 @@ def entry(key, entry, description: nil, default: nil, inherit: nil, reserved: ni .with(reserved: reserved) .metadata(metadata) - (@nodes ||= {}).merge!(key.to_sym => factory) + @nodes ||= {} + @nodes[entry_name] = factory + + helpers(entry_name) end # rubocop: enable CodeReuse/ActiveRecord + def dynamic_helpers(*nodes) + helpers(*nodes, dynamic: true) + end + def helpers(*nodes, dynamic: false) nodes.each do |symbol| if method_defined?("#{symbol}_defined?") || method_defined?("#{symbol}_value")