Commit a0b96c07 authored by Stefano Tenuta's avatar Stefano Tenuta

Enabled variables for CI services

CI lint now validates the Services hash
even after adding a Variables hash

Variables are also returned in the Service object
when the runner requests a new Job

Changelog: added
parent 17c9a8fb
...@@ -6,6 +6,7 @@ module API ...@@ -6,6 +6,7 @@ module API
module JobRequest module JobRequest
class Service < Entities::Ci::JobRequest::Image class Service < Entities::Ci::JobRequest::Image
expose :alias, :command expose :alias, :command
expose :variables
end end
end end
end end
......
...@@ -4,7 +4,7 @@ module Gitlab ...@@ -4,7 +4,7 @@ module Gitlab
module Ci module Ci
module Build module Build
class Image class Image
attr_reader :alias, :command, :entrypoint, :name, :ports attr_reader :alias, :command, :entrypoint, :name, :ports, :variables
class << self class << self
def from_image(job) def from_image(job)
...@@ -33,6 +33,7 @@ module Gitlab ...@@ -33,6 +33,7 @@ module Gitlab
@entrypoint = image[:entrypoint] @entrypoint = image[:entrypoint]
@name = image[:name] @name = image[:name]
@ports = build_ports(image).select(&:valid?) @ports = build_ports(image).select(&:valid?)
@variables = build_variables(image)
end end
end end
...@@ -45,6 +46,12 @@ module Gitlab ...@@ -45,6 +46,12 @@ module Gitlab
def build_ports(image) def build_ports(image)
image[:ports].to_a.map { |port| ::Gitlab::Ci::Build::Port.new(port) } image[:ports].to_a.map { |port| ::Gitlab::Ci::Build::Port.new(port) }
end end
def build_variables(image)
image[:variables].to_a.map do |key, value|
{ key: key.to_s, value: value.to_s }
end
end
end end
end end
end end
......
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
include ::Gitlab::Config::Entry::Attributable include ::Gitlab::Config::Entry::Attributable
include ::Gitlab::Config::Entry::Configurable include ::Gitlab::Config::Entry::Configurable
ALLOWED_KEYS = %i[name entrypoint command alias ports].freeze ALLOWED_KEYS = %i[name entrypoint command alias ports variables].freeze
validations do validations do
validates :config, hash_or_string: true validates :config, hash_or_string: true
...@@ -32,6 +32,10 @@ module Gitlab ...@@ -32,6 +32,10 @@ module Gitlab
entry :ports, Entry::Ports, entry :ports, Entry::Ports,
description: 'Ports used to expose the service' description: 'Ports used to expose the service'
entry :variables, ::Gitlab::Ci::Config::Entry::Variables,
description: 'Environment variables available for this service.',
inherit: false
attributes :ports attributes :ports
def alias def alias
...@@ -57,6 +61,10 @@ module Gitlab ...@@ -57,6 +61,10 @@ module Gitlab
{} {}
end end
def variables
value[:variables]
end
def with_image_ports? def with_image_ports?
opt(:with_image_ports) opt(:with_image_ports)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment