Commit cd6a2afb authored by Grzegorz Bizon's avatar Grzegorz Bizon

Move CI image configuration entry to new CI config

parent 8b550db3
......@@ -14,7 +14,7 @@ module Ci
ALLOWED_CACHE_KEYS = [:key, :untracked, :paths]
ALLOWED_ARTIFACTS_KEYS = [:name, :untracked, :paths, :when, :expire_in]
attr_reader :after_script, :image, :services, :path, :cache
attr_reader :after_script, :services, :path, :cache
def initialize(config, path = nil)
@ci_config = Gitlab::Ci::Config.new(config)
......@@ -22,8 +22,11 @@ module Ci
@path = path
initial_parsing
unless @ci_config.valid?
raise ValidationError, @ci_config.errors.first
end
initial_parsing
validate!
rescue Gitlab::Ci::Config::Loader::FormatError => e
raise ValidationError, e.message
......@@ -60,6 +63,9 @@ module Ci
private
def initial_parsing
@before_script = @ci_config.before_script
@image = @ci_config.image
@after_script = @config[:after_script]
@image = @config[:image]
@services = @config[:services]
......@@ -87,7 +93,7 @@ module Ci
{
stage_idx: stages.index(job[:stage]),
stage: job[:stage],
commands: [job[:before_script] || [@ci_config.before_script], job[:script]].flatten.compact.join("\n"),
commands: [job[:before_script] || [@before_script], job[:script]].flatten.compact.join("\n"),
tag_list: job[:tags] || [],
name: name,
only: job[:only],
......@@ -107,10 +113,6 @@ module Ci
end
def validate!
unless @ci_config.valid?
raise ValidationError, @ci_config.errors.first
end
validate_global!
@jobs.each do |name, job|
......@@ -125,10 +127,6 @@ module Ci
raise ValidationError, "after_script should be an array of strings"
end
unless @image.nil? || @image.is_a?(String)
raise ValidationError, "image should be a string"
end
unless @services.nil? || validate_array_of_strings(@services)
raise ValidationError, "services should be an array of strings"
end
......
......@@ -7,7 +7,7 @@ module Gitlab
##
# Temporary delegations that should be removed after refactoring
#
delegate :before_script, to: :@global
delegate :before_script, :image, to: :@global
def initialize(config)
@config = Loader.new(config).load!
......
......@@ -11,6 +11,9 @@ module Gitlab
allow_node :before_script, Script,
description: 'Script that will be executed before each job.'
allow_node :image, Image,
description: 'Docker image that will be used to execute jobs.'
end
end
end
......
......@@ -979,7 +979,7 @@ EOT
config = YAML.dump({ image: ["test"], rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config, path)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "image should be a string")
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Image config should be a string")
end
it "returns errors if job name is blank" do
......
......@@ -21,7 +21,8 @@ describe Gitlab::Ci::Config::Node::Global do
context 'when hash is valid' do
let(:hash) do
{ before_script: ['ls', 'pwd'] }
{ before_script: ['ls', 'pwd'],
image: 'ruby:2.2' }
end
describe '#process!' do
......@@ -32,17 +33,21 @@ describe Gitlab::Ci::Config::Node::Global do
end
it 'creates node object for each entry' do
expect(global.nodes.count).to eq 1
expect(global.nodes.count).to eq 2
end
it 'creates node object using valid class' do
expect(global.nodes.first)
.to be_an_instance_of Gitlab::Ci::Config::Node::Script
expect(global.nodes.second)
.to be_an_instance_of Gitlab::Ci::Config::Node::Image
end
it 'sets correct description for nodes' do
expect(global.nodes.first.description)
.to eq 'Script that will be executed before each job.'
expect(global.nodes.second.description)
.to eq 'Docker image that will be used to execute jobs.'
end
end
......@@ -51,19 +56,26 @@ describe Gitlab::Ci::Config::Node::Global do
expect(global).not_to be_leaf
end
end
context 'when not processed' do
describe '#before_script' do
it 'returns nil' do
expect(global.before_script).to be nil
end
end
end
describe '#before_script' do
context 'when processed' do
before { global.process! }
context 'when processed' do
before { global.process! }
describe '#before_script' do
it 'returns correct script' do
expect(global.before_script).to eq "ls\npwd"
end
end
context 'when not processed' do
it 'returns nil' do
expect(global.before_script).to be nil
describe '#image' do
it 'returns valid image' do
expect(global.image).to eq 'ruby:2.2'
end
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