2018-10-26 00:12:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-14 14:39:53 -05:00
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
|
|
|
module Entry
|
|
|
|
##
|
|
|
|
# Entry that represents a configuration of Docker service.
|
|
|
|
#
|
2020-03-04 07:07:52 -05:00
|
|
|
# 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
|
2018-11-29 06:44:48 -05:00
|
|
|
include ::Gitlab::Config::Entry::Validatable
|
2020-03-04 07:07:52 -05:00
|
|
|
include ::Gitlab::Config::Entry::Attributable
|
|
|
|
include ::Gitlab::Config::Entry::Configurable
|
2017-01-14 14:39:53 -05:00
|
|
|
|
2019-04-03 05:50:54 -04:00
|
|
|
ALLOWED_KEYS = %i[name entrypoint command alias ports].freeze
|
2017-01-14 14:39:53 -05:00
|
|
|
|
|
|
|
validations do
|
|
|
|
validates :config, hash_or_string: true
|
|
|
|
validates :config, allowed_keys: ALLOWED_KEYS
|
2019-04-03 05:50:54 -04:00
|
|
|
validates :config, disallowed_keys: %i[ports], unless: :with_image_ports?
|
2017-01-14 14:39:53 -05:00
|
|
|
validates :name, type: String, presence: true
|
2017-06-28 15:30:38 -04:00
|
|
|
validates :entrypoint, array_of_strings: true, allow_nil: true
|
2020-03-04 07:07:52 -05:00
|
|
|
|
2017-06-28 15:30:38 -04:00
|
|
|
validates :command, array_of_strings: true, allow_nil: true
|
2017-01-14 14:39:53 -05:00
|
|
|
validates :alias, type: String, allow_nil: true
|
2019-04-03 05:50:54 -04:00
|
|
|
validates :alias, type: String, presence: true, unless: ->(record) { record.ports.blank? }
|
2017-01-14 14:39:53 -05:00
|
|
|
end
|
|
|
|
|
2019-06-01 06:37:29 -04:00
|
|
|
entry :ports, Entry::Ports,
|
|
|
|
description: 'Ports used to expose the service'
|
|
|
|
|
2020-03-04 07:07:52 -05:00
|
|
|
attributes :ports
|
|
|
|
|
2017-01-14 14:39:53 -05:00
|
|
|
def alias
|
|
|
|
value[:alias]
|
|
|
|
end
|
|
|
|
|
|
|
|
def command
|
|
|
|
value[:command]
|
|
|
|
end
|
2020-03-04 07:07:52 -05:00
|
|
|
|
|
|
|
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-01-14 14:39:53 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|