diff options
author | Tomasz Maczukin <tomasz@maczukin.pl> | 2017-01-14 14:39:53 -0500 |
---|---|---|
committer | Tomasz Maczukin <tomasz@maczukin.pl> | 2017-06-12 12:58:35 +0200 |
commit | 8c6e2bada222745c9994da42f21bad2ab43b9351 (patch) | |
tree | afd67edfeda2c7d81b51379f85b0e12dfb22e0cc /lib | |
parent | 5478ff6dc2ad59a7c7d91f61339e8acee9bbb434 (diff) | |
download | gitlab-ce-8c6e2bada222745c9994da42f21bad2ab43b9351.tar.gz |
Add support for docker image configuration in .gitlab-ci.yml
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/ci/config/entry/docker_image.rb | 31 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/image.rb | 9 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/service.rb | 35 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/services.rb | 25 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/validators.rb | 8 |
5 files changed, 106 insertions, 2 deletions
diff --git a/lib/gitlab/ci/config/entry/docker_image.rb b/lib/gitlab/ci/config/entry/docker_image.rb new file mode 100644 index 00000000000..1170e129bc0 --- /dev/null +++ b/lib/gitlab/ci/config/entry/docker_image.rb @@ -0,0 +1,31 @@ +module Gitlab + module Ci + class Config + module Entry + module DockerImage + def hash? + @config.is_a?(Hash) + end + + def string? + @config.is_a?(String) + end + + def name + value[:name] + end + + def entrypoint + value[:entrypoint] + end + + def value + return { name: @config } if string? + return @config if hash? + {} + end + end + end + end + end +end diff --git a/lib/gitlab/ci/config/entry/image.rb b/lib/gitlab/ci/config/entry/image.rb index b5050257688..10f35a2dbc1 100644 --- a/lib/gitlab/ci/config/entry/image.rb +++ b/lib/gitlab/ci/config/entry/image.rb @@ -7,9 +7,16 @@ module Gitlab # class Image < Node include Validatable + include DockerImage + + ALLOWED_KEYS = %i[name entrypoint].freeze validations do - validates :config, type: String + validates :config, hash_or_string: true + validates :config, allowed_keys: ALLOWED_KEYS + + validates :name, type: String, presence: true + validates :entrypoint, type: String, allow_nil: true end end end diff --git a/lib/gitlab/ci/config/entry/service.rb b/lib/gitlab/ci/config/entry/service.rb new file mode 100644 index 00000000000..fd0aec23803 --- /dev/null +++ b/lib/gitlab/ci/config/entry/service.rb @@ -0,0 +1,35 @@ +module Gitlab + module Ci + class Config + module Entry + ## + # Entry that represents a configuration of Docker service. + # + class Service < Node + include Validatable + include DockerImage + + ALLOWED_KEYS = %i[name entrypoint command alias].freeze + + validations do + validates :config, hash_or_string: true + validates :config, allowed_keys: ALLOWED_KEYS + + validates :name, type: String, presence: true + validates :entrypoint, type: String, allow_nil: true + validates :command, type: String, allow_nil: true + validates :alias, type: String, allow_nil: true + end + + def alias + value[:alias] + end + + def command + value[:command] + end + end + end + end + end +end diff --git a/lib/gitlab/ci/config/entry/services.rb b/lib/gitlab/ci/config/entry/services.rb index 84f8ab780f5..0066894e069 100644 --- a/lib/gitlab/ci/config/entry/services.rb +++ b/lib/gitlab/ci/config/entry/services.rb @@ -9,7 +9,30 @@ module Gitlab include Validatable validations do - validates :config, array_of_strings: true + validates :config, type: Array + end + + def compose!(deps = nil) + super do + @entries = [] + @config.each do |config| + @entries << Entry::Factory.new(Entry::Service) + .value(config || {}) + .create! + end + + @entries.each do |entry| + entry.compose!(deps) + end + end + end + + def value + @entries.map(&:value) + end + + def descendants + @entries end end end diff --git a/lib/gitlab/ci/config/entry/validators.rb b/lib/gitlab/ci/config/entry/validators.rb index bd7428b1272..b2ca3c881e4 100644 --- a/lib/gitlab/ci/config/entry/validators.rb +++ b/lib/gitlab/ci/config/entry/validators.rb @@ -44,6 +44,14 @@ module Gitlab end end + class HashOrStringValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + unless value.is_a?(Hash) || value.is_a?(String) + record.errors.add(attribute, 'should be a hash or a string') + end + end + end + class KeyValidator < ActiveModel::EachValidator include LegacyValidationHelpers |