debian-mirror-gitlab/lib/gitlab/ci/config/entry/service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
2.1 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
module Gitlab
module Ci
class Config
module Entry
##
# Entry that represents a configuration of Docker service.
#
2020-04-08 14:13:33 +05:30
# 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
2019-02-15 15:39:39 +05:30
include ::Gitlab::Config::Entry::Validatable
2020-04-08 14:13:33 +05:30
include ::Gitlab::Config::Entry::Attributable
include ::Gitlab::Config::Entry::Configurable
2017-09-10 17:25:29 +05:30
2021-12-11 22:18:48 +05:30
ALLOWED_KEYS = %i[name entrypoint command alias ports variables].freeze
2017-09-10 17:25:29 +05:30
validations do
validates :config, hash_or_string: true
validates :config, allowed_keys: ALLOWED_KEYS
2019-07-07 11:18:12 +05:30
validates :config, disallowed_keys: %i[ports], unless: :with_image_ports?
2017-09-10 17:25:29 +05:30
validates :name, type: String, presence: true
validates :entrypoint, array_of_strings: true, allow_nil: true
2020-04-08 14:13:33 +05:30
2017-09-10 17:25:29 +05:30
validates :command, array_of_strings: true, allow_nil: true
validates :alias, type: String, allow_nil: true
2019-07-07 11:18:12 +05:30
validates :alias, type: String, presence: true, unless: ->(record) { record.ports.blank? }
2017-09-10 17:25:29 +05:30
end
2019-09-04 21:01:54 +05:30
entry :ports, Entry::Ports,
description: 'Ports used to expose the service'
2021-12-11 22:18:48 +05:30
entry :variables, ::Gitlab::Ci::Config::Entry::Variables,
description: 'Environment variables available for this service.',
inherit: false
2020-04-08 14:13:33 +05:30
attributes :ports
2017-09-10 17:25:29 +05:30
def alias
value[:alias]
end
def command
value[:command]
end
2020-04-08 14:13:33 +05:30
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
2017-09-10 17:25:29 +05:30
end
end
end
end
end