ddsl 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b07b6c315e69c2af20ad368cbcf4825675490c3c
4
- data.tar.gz: 939717c286543d4dc4b1ab9d5360341fc7998aa1
3
+ metadata.gz: cc50eec07295a16c3ecd6a8be51092c807574804
4
+ data.tar.gz: 5d752cc123531436e14ac1697638826a6dc38e9e
5
5
  SHA512:
6
- metadata.gz: 95daea93b2c47753e9d54c0504a3fba3312a632e04738abb9564fd85c3365c840b86e10d79e3be62e7094a3a562729d8bc7b690bed4c96a52daf90e8ce4f828a
7
- data.tar.gz: dbc8baf5444dd9d21e3104c045dadae3cd0be3abd5fb1438e7d988947b3f672ad62bf783f1c4ce559e47b904b658c615fc06459ab2b2fb16b3ebe6ada1f74303
6
+ metadata.gz: a37dc864649a554971209c92280934618c8140fc8f9b8dbe67153078aaccf6d889c55de6a04f11808835f6d5ca30a65ded1c5de026b4df651ca1e76a0c064e01
7
+ data.tar.gz: eda8481c21285581092ccafba56b4c8d0bb18143fb3940ced1931b3dcf01630218b78252b84bf21bd1b209096f1fa192baa27b0a33e7011232cef36009de93e7
data/.travis.yml CHANGED
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
+ rvm:
3
+ - 2.4.5
2
4
 
3
5
  services:
4
6
  - docker
@@ -17,15 +19,16 @@ before_install:
17
19
  - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
18
20
  - chmod +x docker-compose
19
21
  - sudo mv docker-compose /usr/local/bin
20
- - gem install ddsl --version=$DDSL_VERSION
21
- - echo "$TRAVIS_COMMIT"
22
22
  - docker login -u "$DOCKER_REGISTRY_USERNAME" -p "$DOCKER_REGISTRY_PASSWORD"
23
23
  - export CI_SHA1=travis-$TRAVIS_COMMIT
24
24
 
25
+ install: gem install ddsl --version=$DDSL_VERSION
26
+
25
27
  jobs:
26
28
  include:
27
29
  - stage: build
28
- script: ddsl build feature-branch
30
+ script: |
31
+ ddsl build feature-branch
29
32
  - stage: checks
30
33
  script: |
31
34
  ddsl run test-ci
data/README.md CHANGED
@@ -57,11 +57,11 @@ runs:
57
57
 
58
58
  ## Contnious Integration
59
59
 
60
- | Provider | Status |
61
- |-----------|---------------------------------------------------------------------------------------------------------------------------------|
62
- | GitLab CI | |
63
- | Circle CI | [![CircleCI](https://circleci.com/gh/bilby91/ddsl/tree/master.svg?style=svg)](https://circleci.com/gh/bilby91/ddsl/tree/master) |
64
- | Travis CI | [![Build Status](https://travis-ci.com/bilby91/ddsl.svg?branch=master)](https://travis-ci.com/bilby91/ddsl) |
60
+ | Provider | Status |
61
+ |-----------|------------------------------------------------------------------------------------------------------------------------------------------|
62
+ | GitLab CI | [![Gitlab CI](https://img.shields.io/gitlab/pipeline/bilby91/ddsl/master.svg)](https://gitlab.com/bilby91/ddsl) |
63
+ | Circle CI | [![Circle CI](https://img.shields.io/circleci/project/github/bilby91/ddsl/master.svg)](https://circleci.com/gh/bilby91/ddsl/tree/master) |
64
+ | Travis CI | [![Travis CI](https://img.shields.io/travis/bilby91/ddsl/master.svg)](https://travis-ci.com/bilby91/ddsl) |
65
65
 
66
66
  ## Dependencies
67
67
 
@@ -76,7 +76,7 @@ runs:
76
76
  - [X] Add CircleCI
77
77
  - [X] Add GitLabCI
78
78
  - [X] Add TravisCI
79
- - [ ] Registries?
79
+ - [X] Registries?
80
80
  - [ ] Variable sharing/reusing
81
81
  - [ ] External secret proviers ? (KMS, Google?)
82
82
 
data/docker/Dockerfile CHANGED
@@ -43,4 +43,4 @@ RUN gem build ddsl.gemspec
43
43
 
44
44
  # Install binary
45
45
  # FIXME: We need to load the version dynamically
46
- RUN gem install --no-rdoc --no-ri --local ddsl-0.0.2.gem
46
+ RUN gem install --no-rdoc --no-ri --local ddsl-0.0.3.gem
data/lib/ddsl/cli.rb CHANGED
@@ -15,9 +15,9 @@ module DDSL
15
15
  parameter 'NAME ...', 'name of the build', required: true, attribute_name: :names
16
16
 
17
17
  def execute
18
- with_builder(search_targets!('builds')) do |runner, spec|
18
+ with_command('builds') do |command, spec|
19
19
  begin
20
- runner.run(spec)
20
+ command.run(spec)
21
21
  rescue DDSL::Shell::ExitStatusError
22
22
  $stdout.puts 'Build failed.'
23
23
  exit(-1)
@@ -30,9 +30,9 @@ module DDSL
30
30
  parameter 'NAME ...', 'name of the run', required: true, attribute_name: :names
31
31
 
32
32
  def execute
33
- with_runner(search_targets!('runs')) do |runner, spec|
33
+ with_command('runs') do |command, spec|
34
34
  begin
35
- runner.run(spec)
35
+ command.run(spec)
36
36
  rescue DDSL::Shell::ExitStatusError
37
37
  $stdout.puts 'Run failed.'
38
38
  exit(-1)
@@ -41,15 +41,22 @@ module DDSL
41
41
  end
42
42
  end
43
43
 
44
- private def with_builder(builds)
45
- builds.map do |b|
46
- yield(builder_for_type(b['type']), b)
44
+ private def with_command(command_type)
45
+ collection = search_targets!(command_type)
46
+
47
+ login_if_needed
48
+
49
+ collection.map do |x|
50
+ yield(command_class(command_type, x['type']), x)
47
51
  end
48
52
  end
49
53
 
50
- private def with_runner(runs)
51
- runs.map do |r|
52
- yield(runner_for_type(r['type']), r)
54
+ private def command_class(command, type)
55
+ case command
56
+ when 'builds'
57
+ builder_for_type(type)
58
+ when 'runs'
59
+ runner_for_type(type)
53
60
  end
54
61
  end
55
62
 
@@ -71,6 +78,22 @@ module DDSL
71
78
  end
72
79
  end
73
80
 
81
+ private def login_if_needed
82
+ parsed_config['registries'].each do |r|
83
+ Command::Docker::Login.new.run(r) if need_login?(r)
84
+ end
85
+ end
86
+
87
+ private def need_login?(registry)
88
+ !registry['use_cache'] || (registry['use_cache'] && !cached_docker_auth?(registry['url']))
89
+ end
90
+
91
+ private def cached_docker_auth?(host)
92
+ parsed_docker_config['auths'].any? do |url, _|
93
+ URI.parse(url).host == URI.parse(host).host
94
+ end
95
+ end
96
+
74
97
  private def search_targets!(type)
75
98
  command_targets = targets(type)
76
99
  raise Clamp::UsageError.new('invalid NAME given', type) unless command_targets.count == names.count
@@ -82,14 +105,30 @@ module DDSL
82
105
  parsed_config[type].select { |item| names.include? item['name'] }
83
106
  end
84
107
 
85
- private def config_path
86
- @config_path ||= config || '.ddsl.yml'
87
- end
88
-
89
108
  private def parsed_config
90
109
  @parsed_config ||= DDSL::VariableInjector.new(ENV).inject(
91
110
  DDSL::Parser.new.parse(config_path)
92
111
  )
93
112
  end
113
+
114
+ private def parsed_docker_config
115
+ return { 'auths' => [] } unless File.exist?(docker_config_path)
116
+
117
+ @parsed_docker_config ||= JSON.parse(
118
+ File.read(docker_config_path)
119
+ )
120
+ end
121
+
122
+ private def config_path
123
+ @config_path ||= config || '.ddsl.yml'
124
+ end
125
+
126
+ private def docker_config_path
127
+ @docker_config_path ||= File.join(home_path, '.docker', 'config.json')
128
+ end
129
+
130
+ private def home_path
131
+ %w[HOME HOMEPATH].map { |e| ENV[e] }.compact.first
132
+ end
94
133
  end
95
134
  end
data/lib/ddsl/command.rb CHANGED
@@ -3,5 +3,6 @@
3
3
  require_relative './command/docker/build'
4
4
  require_relative './command/docker/push'
5
5
  require_relative './command/docker/run'
6
+ require_relative './command/docker/login'
6
7
  require_relative './command/docker_compose/run'
7
8
  require_relative './command/docker_compose/build'
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../base'
4
+
5
+ module DDSL
6
+ module Command
7
+ module Docker
8
+ class Login < Base
9
+ executable 'docker'
10
+ command 'login'
11
+
12
+ options do
13
+ accept_keys(%w[username password])
14
+
15
+ optionize_keys
16
+ expand_options
17
+ end
18
+
19
+ arguments do
20
+ accept_keys(%w[url])
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -47,18 +47,19 @@ module DDSL
47
47
  end
48
48
 
49
49
  module InstanceMethods
50
- DEFAULT_TRANSFORMER = ->(_x) { [] }
50
+ DEFAULT_OPTIONS_TRANSFORMER = ->(_x) { [] }
51
+ DEFAULT_ARGUMENTS_TRANSFORMER = ->(_x) { {} }
51
52
 
52
53
  def executable_options
53
- search_ancestor_tree_variable(:@executable_options) || DEFAULT_TRANSFORMER
54
+ search_ancestor_tree_variable(:@executable_options) || DEFAULT_OPTIONS_TRANSFORMER
54
55
  end
55
56
 
56
57
  def options
57
- search_ancestor_tree_variable(:@options) || DEFAULT_TRANSFORMER
58
+ search_ancestor_tree_variable(:@options) || DEFAULT_OPTIONS_TRANSFORMER
58
59
  end
59
60
 
60
61
  def arguments
61
- search_ancestor_tree_variable(:@arguments) || DEFAULT_TRANSFORMER
62
+ search_ancestor_tree_variable(:@arguments) || DEFAULT_ARGUMENTS_TRANSFORMER
62
63
  end
63
64
 
64
65
  def after_block
data/lib/ddsl/schema.rb CHANGED
@@ -12,6 +12,11 @@ module DDSL
12
12
  type: :integer,
13
13
  enum: [1]
14
14
  },
15
+ registries: {
16
+ type: :array,
17
+ items: { '$ref': '#/definitions/registry' },
18
+ default: []
19
+ },
15
20
  builds: {
16
21
  type: :array,
17
22
  items: { '$ref': '#/definitions/build' }
@@ -22,6 +27,16 @@ module DDSL
22
27
  }
23
28
  },
24
29
  definitions: {
30
+ registry: {
31
+ type: :object,
32
+ required: %i[url username password],
33
+ properties: {
34
+ url: { type: :string },
35
+ username: { type: :string },
36
+ password: { type: :string },
37
+ use_cache: { type: :boolean }
38
+ }
39
+ },
25
40
  build: {
26
41
  type: :object,
27
42
  required: [:name],
@@ -8,15 +8,18 @@ module DDSL
8
8
  class InvalidError < StandardError; end
9
9
 
10
10
  #
11
- # Validate given data against DDSL schema. If data is not compliant with the schema,
12
- # InvalidError will be raised
11
+ # Validate given data against DDSL schema. Will add any defaults if nil values are found
12
+ #
13
+ # @raise [InvalidError] if data is not compliant with the schema,
13
14
  #
14
15
  # @param [Hash] data
15
16
  #
16
- # @return [Hash] same data that was given
17
+ # @return [Hash] data with defaults if appropiate
17
18
  #
18
19
  def validate!(data)
19
- errors = JSON::Validator.fully_validate(DDSL::SCHEMA, data, version: DDSL::SCHEMA_VERSION)
20
+ errors = JSON::Validator.fully_validate(DDSL::SCHEMA, data,
21
+ version: DDSL::SCHEMA_VERSION,
22
+ insert_defaults: true)
20
23
 
21
24
  raise InvalidError, errors.join('\n') if errors.count.positive?
22
25
 
data/lib/ddsl/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DDSL
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fernandez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-30 00:00:00.000000000 Z
11
+ date: 2018-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -137,6 +137,7 @@ files:
137
137
  - lib/ddsl/command.rb
138
138
  - lib/ddsl/command/base.rb
139
139
  - lib/ddsl/command/docker/build.rb
140
+ - lib/ddsl/command/docker/login.rb
140
141
  - lib/ddsl/command/docker/push.rb
141
142
  - lib/ddsl/command/docker/run.rb
142
143
  - lib/ddsl/command/docker_compose/build.rb