2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
module Build
|
|
|
|
class Image
|
2019-05-18 00:54:41 +05:30
|
|
|
attr_reader :alias, :command, :entrypoint, :name, :ports
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
class << self
|
|
|
|
def from_image(job)
|
|
|
|
image = Gitlab::Ci::Build::Image.new(job.options[:image])
|
|
|
|
return unless image.valid?
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
image
|
|
|
|
end
|
|
|
|
|
|
|
|
def from_services(job)
|
|
|
|
services = job.options[:services].to_a.map do |service|
|
|
|
|
Gitlab::Ci::Build::Image.new(service)
|
|
|
|
end
|
|
|
|
|
|
|
|
services.select(&:valid?).compact
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(image)
|
2017-09-10 17:25:29 +05:30
|
|
|
if image.is_a?(String)
|
|
|
|
@name = image
|
2019-05-18 00:54:41 +05:30
|
|
|
@ports = []
|
2017-09-10 17:25:29 +05:30
|
|
|
elsif image.is_a?(Hash)
|
|
|
|
@alias = image[:alias]
|
|
|
|
@command = image[:command]
|
|
|
|
@entrypoint = image[:entrypoint]
|
|
|
|
@name = image[:name]
|
2019-05-18 00:54:41 +05:30
|
|
|
@ports = build_ports(image).select(&:valid?)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def valid?
|
|
|
|
@name.present?
|
|
|
|
end
|
2019-05-18 00:54:41 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def build_ports(image)
|
|
|
|
image[:ports].to_a.map { |port| ::Gitlab::Ci::Build::Port.new(port) }
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|