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

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

75 lines
2.1 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2016-08-24 12:49:21 +05:30
module Gitlab
module Ci
class Config
2017-08-17 22:00:37 +05:30
module Entry
2016-08-24 12:49:21 +05:30
##
# Entry that represents a Docker image.
#
2019-02-15 15:39:39 +05:30
class Image < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Validatable
2019-07-07 11:18:12 +05:30
include ::Gitlab::Config::Entry::Attributable
include ::Gitlab::Config::Entry::Configurable
2016-08-24 12:49:21 +05:30
2022-07-23 23:45:48 +05:30
ALLOWED_KEYS = %i[name entrypoint ports pull_policy].freeze
LEGACY_ALLOWED_KEYS = %i[name entrypoint ports].freeze
2017-09-10 17:25:29 +05:30
2016-08-24 12:49:21 +05:30
validations do
2017-09-10 17:25:29 +05:30
validates :config, hash_or_string: true
2022-07-23 23:45:48 +05:30
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?
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
end
2019-07-07 11:18:12 +05:30
entry :ports, Entry::Ports,
2019-09-04 21:01:54 +05:30
description: 'Ports used to expose the image'
2017-09-10 17:25:29 +05:30
2022-07-23 23:45:48 +05:30
entry :pull_policy, Entry::PullPolicy,
description: 'Pull policy for the image'
attributes :ports, :pull_policy
2017-09-10 17:25:29 +05:30
def name
value[:name]
end
def entrypoint
value[:entrypoint]
end
def value
2022-07-23 23:45:48 +05:30
if string?
{ name: @config }
elsif hash?
{
name: @config[:name],
entrypoint: @config[:entrypoint],
2022-08-13 15:12:31 +05:30
ports: (ports_value if ports_defined?),
2022-07-23 23:45:48 +05:30
pull_policy: (ci_docker_image_pull_policy_enabled? ? pull_policy_value : nil)
}.compact
else
{}
end
2016-08-24 12:49:21 +05:30
end
2019-07-07 11:18:12 +05:30
def with_image_ports?
opt(:with_image_ports)
end
2022-07-23 23:45:48 +05:30
def ci_docker_image_pull_policy_enabled?
::Feature.enabled?(:ci_docker_image_pull_policy)
end
2019-07-07 11:18:12 +05:30
def skip_config_hash_validation?
true
end
2016-08-24 12:49:21 +05:30
end
end
end
end
end