docker_rack 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5091e82378e3045eda7fb36313e9b701ab4fad4
4
- data.tar.gz: afbf2b2d7c55033a42c307bf0753bf1a1aa64fd3
3
+ metadata.gz: ea65c176d2cfb82e154297fe668c4473c2c9af26
4
+ data.tar.gz: cf8c6de8e2163233ff8a7d41d8460f993ee9e482
5
5
  SHA512:
6
- metadata.gz: f3e0ad2b9da8cb5358b0e6054287622f404206f55ec83efc4b62c0952a574cbc7a5776874b25b287c9cdaede352c4ce7fd2cd32c77d8648c6e859a1fdaa89d0d
7
- data.tar.gz: a0db638f1bb5d5734de443c9dd617ea6c4adc9c9f3bf6d77bda5936ff33bc91c412ba99894d0d89bbb1bc91b7449dbaf5876221b3c1c18b73d16aaeb2de8e451
6
+ metadata.gz: fec22a282babc91291bec9be6f2042cef5500fc3ed6565a9c8b3ab937505fd4de5debfb96420aa9363a0ee21b3f1792bace6b015657471554154985d656a0a6d
7
+ data.tar.gz: 3aa4405e349873862a16d8a8e7e3feef743a7d4e6c91ca13e5d7b73f8c9025933052dcd5925bf1aeb7dbd0e2d33c6262ac074bd95e141722ba82447352824285
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --tty --format documentation
data/.rubocop.yml CHANGED
@@ -1,3 +1,5 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
1
3
  #######
2
4
  # WIP These should all go back to defaults at some point
3
5
  Metrics/AbcSize:
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,276 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-02-07 13:41:07 -0500 using RuboCop version 0.37.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 2
10
+ Lint/HandleExceptions:
11
+ Exclude:
12
+ - 'lib/docker_rack/docker_utils.rb'
13
+
14
+ # Offense count: 1
15
+ Lint/LiteralInCondition:
16
+ Exclude:
17
+ - 'lib/docker_rack/docker_utils.rb'
18
+
19
+ # Offense count: 4
20
+ Lint/ParenthesesAsGroupedExpression:
21
+ Exclude:
22
+ - 'lib/docker_rack/container_template.rb'
23
+
24
+ # Offense count: 2
25
+ # Cop supports --auto-correct.
26
+ Lint/StringConversionInInterpolation:
27
+ Exclude:
28
+ - 'lib/docker_rack/docker_utils.rb'
29
+
30
+ # Offense count: 2
31
+ Lint/UselessAssignment:
32
+ Exclude:
33
+ - 'lib/docker_rack/container_template.rb'
34
+ - 'lib/docker_rack/dev_environment.rb'
35
+
36
+ # Offense count: 3
37
+ Metrics/AbcSize:
38
+ Max: 59
39
+
40
+ # Offense count: 3
41
+ Metrics/CyclomaticComplexity:
42
+ Max: 18
43
+
44
+ # Offense count: 24
45
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
46
+ # URISchemes: http, https
47
+ Metrics/LineLength:
48
+ Max: 121
49
+
50
+ # Offense count: 3
51
+ # Configuration parameters: CountComments.
52
+ Metrics/MethodLength:
53
+ Max: 35
54
+
55
+ # Offense count: 3
56
+ Metrics/PerceivedComplexity:
57
+ Max: 17
58
+
59
+ # Offense count: 3
60
+ # Cop supports --auto-correct.
61
+ # Configuration parameters: IndentWhenRelativeTo, SupportedStyles, IndentOneStep, IndentationWidth.
62
+ # SupportedStyles: case, end
63
+ Style/CaseIndentation:
64
+ Enabled: false
65
+
66
+ # Offense count: 1
67
+ # Cop supports --auto-correct.
68
+ Style/ColonMethodCall:
69
+ Exclude:
70
+ - 'lib/docker_rack/docker_utils.rb'
71
+
72
+ # Offense count: 2
73
+ # Cop supports --auto-correct.
74
+ Style/CommentIndentation:
75
+ Exclude:
76
+ - 'lib/docker_rack/docker_utils.rb'
77
+
78
+ # Offense count: 6
79
+ Style/Documentation:
80
+ Exclude:
81
+ - 'spec/**/*'
82
+ - 'test/**/*'
83
+ - 'lib/docker_rack.rb'
84
+ - 'lib/docker_rack/cli/base.rb'
85
+ - 'lib/docker_rack/container_template.rb'
86
+ - 'lib/docker_rack/dev_environment.rb'
87
+ - 'lib/docker_rack/docker_utils.rb'
88
+ - 'lib/docker_rack/task_mngr1.rb'
89
+
90
+ # Offense count: 1
91
+ # Cop supports --auto-correct.
92
+ Style/EmptyLines:
93
+ Exclude:
94
+ - 'lib/docker_rack/container_template.rb'
95
+
96
+ # Offense count: 2
97
+ # Cop supports --auto-correct.
98
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
99
+ # SupportedStyles: empty_lines, no_empty_lines
100
+ Style/EmptyLinesAroundClassBody:
101
+ Exclude:
102
+ - 'lib/docker_rack/docker_utils.rb'
103
+
104
+ # Offense count: 1
105
+ # Cop supports --auto-correct.
106
+ Style/EmptyLinesAroundMethodBody:
107
+ Exclude:
108
+ - 'lib/docker_rack/docker_utils.rb'
109
+
110
+ # Offense count: 3
111
+ # Cop supports --auto-correct.
112
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
113
+ # SupportedStyles: empty_lines, no_empty_lines
114
+ Style/EmptyLinesAroundModuleBody:
115
+ Exclude:
116
+ - 'lib/docker_rack/container_template.rb'
117
+ - 'lib/docker_rack/dev_environment.rb'
118
+
119
+ # Offense count: 1
120
+ # Cop supports --auto-correct.
121
+ # Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
122
+ Style/ExtraSpacing:
123
+ Exclude:
124
+ - 'lib/docker_rack/container_template.rb'
125
+
126
+ # Offense count: 2
127
+ # Cop supports --auto-correct.
128
+ # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
129
+ # SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets
130
+ Style/HashSyntax:
131
+ Enabled: false
132
+
133
+ # Offense count: 1
134
+ Style/IfInsideElse:
135
+ Exclude:
136
+ - 'lib/docker_rack/dev_environment.rb'
137
+
138
+ # Offense count: 1
139
+ # Cop supports --auto-correct.
140
+ # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
141
+ # SupportedStyles: special_inside_parentheses, consistent, align_braces
142
+ Style/IndentHash:
143
+ Enabled: false
144
+
145
+ # Offense count: 1
146
+ # Cop supports --auto-correct.
147
+ Style/InfiniteLoop:
148
+ Exclude:
149
+ - 'lib/docker_rack/docker_utils.rb'
150
+
151
+ # Offense count: 3
152
+ # Cop supports --auto-correct.
153
+ Style/LeadingCommentSpace:
154
+ Exclude:
155
+ - 'lib/docker_rack/dev_environment.rb'
156
+
157
+ # Offense count: 1
158
+ # Cop supports --auto-correct.
159
+ Style/MethodCallParentheses:
160
+ Exclude:
161
+ - 'lib/docker_rack/container_template.rb'
162
+
163
+ # Offense count: 2
164
+ # Cop supports --auto-correct.
165
+ # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
166
+ # SupportedStyles: aligned, indented
167
+ Style/MultilineMethodCallIndentation:
168
+ Enabled: false
169
+
170
+ # Offense count: 2
171
+ # Cop supports --auto-correct.
172
+ Style/MutableConstant:
173
+ Exclude:
174
+ - 'lib/docker_rack/container_template.rb'
175
+
176
+ # Offense count: 2
177
+ # Cop supports --auto-correct.
178
+ # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
179
+ # SupportedStyles: skip_modifier_ifs, always
180
+ Style/Next:
181
+ Exclude:
182
+ - 'lib/docker_rack/docker_utils.rb'
183
+
184
+ # Offense count: 2
185
+ # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
186
+ # NamePrefix: is_, has_, have_
187
+ # NamePrefixBlacklist: is_, has_, have_
188
+ # NameWhitelist: is_a?
189
+ Style/PredicateName:
190
+ Exclude:
191
+ - 'lib/docker_rack/docker_utils.rb'
192
+
193
+ # Offense count: 1
194
+ # Cop supports --auto-correct.
195
+ Style/RedundantParentheses:
196
+ Exclude:
197
+ - 'lib/docker_rack/cli/base.rb'
198
+
199
+ # Offense count: 6
200
+ # Cop supports --auto-correct.
201
+ # Configuration parameters: AllowMultipleReturnValues.
202
+ Style/RedundantReturn:
203
+ Exclude:
204
+ - 'lib/docker_rack/container_template.rb'
205
+ - 'lib/docker_rack/dev_environment.rb'
206
+ - 'lib/docker_rack/docker_utils.rb'
207
+
208
+ # Offense count: 1
209
+ # Cop supports --auto-correct.
210
+ # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
211
+ # SupportedStyles: slashes, percent_r, mixed
212
+ Style/RegexpLiteral:
213
+ Exclude:
214
+ - 'lib/docker_rack/docker_utils.rb'
215
+
216
+ # Offense count: 1
217
+ # Cop supports --auto-correct.
218
+ Style/SpaceAfterComma:
219
+ Exclude:
220
+ - 'lib/docker_rack/docker_utils.rb'
221
+
222
+ # Offense count: 1
223
+ # Cop supports --auto-correct.
224
+ Style/SpaceAfterNot:
225
+ Exclude:
226
+ - 'lib/docker_rack/docker_utils.rb'
227
+
228
+ # Offense count: 1
229
+ # Cop supports --auto-correct.
230
+ # Configuration parameters: AllowForAlignment.
231
+ Style/SpaceAroundOperators:
232
+ Exclude:
233
+ - 'lib/docker_rack/container_template.rb'
234
+
235
+ # Offense count: 3
236
+ # Cop supports --auto-correct.
237
+ # Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
238
+ # SupportedStyles: space, no_space
239
+ Style/SpaceInsideBlockBraces:
240
+ Enabled: false
241
+
242
+ # Offense count: 4
243
+ # Cop supports --auto-correct.
244
+ Style/SpaceInsideBrackets:
245
+ Exclude:
246
+ - 'container_templates/scripts/settings.rake'
247
+
248
+ # Offense count: 2
249
+ # Cop supports --auto-correct.
250
+ # Configuration parameters: EnforcedStyleForEmptyBraces, SupportedStyles.
251
+ # SupportedStyles: space, no_space
252
+ Style/SpaceInsideHashLiteralBraces:
253
+ EnforcedStyle: no_space
254
+
255
+ # Offense count: 2
256
+ # Cop supports --auto-correct.
257
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
258
+ # SupportedStyles: use_perl_names, use_english_names
259
+ Style/SpecialGlobalVars:
260
+ Enabled: false
261
+
262
+ # Offense count: 8
263
+ # Cop supports --auto-correct.
264
+ # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
265
+ # SupportedStyles: single_quotes, double_quotes
266
+ Style/StringLiterals:
267
+ Enabled: false
268
+
269
+ # Offense count: 2
270
+ # Cop supports --auto-correct.
271
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
272
+ # SupportedStyles: final_newline, final_blank_line
273
+ Style/TrailingBlankLines:
274
+ Exclude:
275
+ - 'bin/docker_rack'
276
+ - 'lib/docker_rack/cli/base.rb'
data/Gemfile.lock ADDED
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ docker_rack (0.0.4)
5
+ rake (~> 0)
6
+ thor (~> 0.18, >= 0.18.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.2.0)
12
+ bump (0.5.3)
13
+ diff-lcs (1.2.5)
14
+ docile (1.1.5)
15
+ gem-release (0.7.4)
16
+ json (1.8.3)
17
+ parser (2.3.0.3)
18
+ ast (~> 2.2)
19
+ powerpack (0.1.1)
20
+ rainbow (2.1.0)
21
+ rake (0.9.6)
22
+ rspec (3.4.0)
23
+ rspec-core (~> 3.4.0)
24
+ rspec-expectations (~> 3.4.0)
25
+ rspec-mocks (~> 3.4.0)
26
+ rspec-core (3.4.2)
27
+ rspec-support (~> 3.4.0)
28
+ rspec-expectations (3.4.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.4.0)
31
+ rspec-mocks (3.4.1)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.4.0)
34
+ rspec-support (3.4.1)
35
+ rubocop (0.37.0)
36
+ parser (>= 2.3.0.2, < 3.0)
37
+ powerpack (~> 0.1)
38
+ rainbow (>= 1.99.1, < 3.0)
39
+ ruby-progressbar (~> 1.7)
40
+ unicode-display_width (~> 0.3)
41
+ ruby-progressbar (1.7.5)
42
+ simplecov (0.11.2)
43
+ docile (~> 1.1.0)
44
+ json (~> 1.8)
45
+ simplecov-html (~> 0.10.0)
46
+ simplecov-html (0.10.0)
47
+ simplecov-rcov (0.2.3)
48
+ simplecov (>= 0.4.1)
49
+ thor (0.19.1)
50
+ unicode-display_width (0.3.1)
51
+ yard (0.8.7.6)
52
+ yard-thor (0.0.1)
53
+ thor
54
+ yard
55
+
56
+ PLATFORMS
57
+ x86-mingw32
58
+
59
+ DEPENDENCIES
60
+ bump
61
+ bundler (~> 1.3)
62
+ docker_rack!
63
+ gem-release
64
+ json
65
+ rspec (~> 3.0)
66
+ rubocop
67
+ simplecov
68
+ simplecov-rcov
69
+ yard
70
+ yard-thor
71
+
72
+ BUNDLED WITH
73
+ 1.10.6
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'yard'
3
+ require 'rubocop/rake_task'
4
+
5
+ RuboCop::RakeTask.new
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ YARD::Config.load_plugin 'thor'
10
+ YARD::Rake::YardocTask.new do |t|
11
+ t.files = ['lib/**/*.rb', 'lib/**/**/*.rb']
12
+ end
13
+
14
+ namespace :doc do
15
+ # This task requires that graphviz is installed locally. For more info:
16
+ # http://www.graphviz.org/
17
+ desc 'Generates the class diagram using the yard generated dot file'
18
+ task :generate_class_diagram do
19
+ puts 'Generating the dot file...'
20
+ `yard graph --file jenkins_api_client.dot`
21
+ puts 'Generating class diagram from the dot file...'
22
+ `dot jenkins_api_client.dot -Tpng -o jenkins_api_client_class_diagram.png`
23
+ end
24
+ end
25
+
26
+ task default: [:spec, :rubocop]
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'docker_rack/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'docker_rack'
8
+ spec.version = DockerRack::VERSION
9
+ spec.authors = ['Igor Moochnick']
10
+ spec.email = %w(igor.moochnick@gmail.com)
11
+ spec.description = 'Simple Docker Orchestration'
12
+ spec.summary = 'This gem will orchestrate local Docker containers'
13
+ spec.homepage = 'https://github.com/igorshare/docker_rack'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($RS)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ ENV['NOKOGIRI_USE_SYSTEM_LIBRARIES'] = 'true'
22
+
23
+ # spec.add_dependency 'nokogiri', '~> 1.6.0'
24
+ spec.add_dependency 'rake', '~> 0'
25
+ spec.add_dependency 'thor', '~> 0.18', '>= 0.18.0'
26
+ # spec.add_dependency 'activesupport'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.3'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ spec.add_development_dependency 'bump'
31
+ spec.add_development_dependency 'json'
32
+ spec.add_development_dependency 'gem-release'
33
+ # spec.add_development_dependency 'byebug'
34
+ spec.add_development_dependency 'simplecov'
35
+ spec.add_development_dependency 'simplecov-rcov'
36
+ # spec.add_development_dependency 'kwalify'
37
+ # spec.add_development_dependency 'equivalent-xml'
38
+ spec.add_development_dependency 'yard-thor'
39
+ spec.add_development_dependency 'yard'
40
+ # spec.add_development_dependency 'rspec_junit_formatter'
41
+ spec.add_development_dependency 'rubocop'
42
+ end
@@ -1,35 +1,53 @@
1
1
  require 'thor'
2
2
 
3
+ LOG_LEVEL = ENV['LOG_LEVEL'] || 'INFO'
4
+
3
5
  module DockerRack
4
6
  module CLI
5
7
  class Base < Thor
6
- # class_option :username, aliases: '-u', desc: 'Name of Jenkins user'
7
- # class_option :password, aliases: '-p', desc: 'Password of Jenkins user'
8
- # class_option :password_base64, aliases: '-b', desc: 'Base 64 encoded password of Jenkins user'
9
- # class_option :server, aliases: '-s', desc: 'Jenkins server IP address or URL'
10
- # class_option :server_port, aliases: '-o', desc: 'Jenkins port'
11
- # class_option :creds_file, aliases: '-c', desc: 'Credentials file for communicating with Jenkins server'
12
- # class_option :debug, type: :boolean, aliases: '-d', desc: 'Run in debug mode (no Jenkins changes)', default: false
13
-
14
8
  map '-v' => :version
15
9
 
10
+ class_option :container_templates, aliases: :p, banner: '<path>', type: :string, default: 'container_templates'
11
+
16
12
  desc 'version', 'Shows current version'
17
- # CLI command that returns the version of Jenkins API Client
13
+ # CLI command that returns the version of Docker Rack
18
14
  def version
19
15
  puts DockerRack::VERSION
20
16
  end
21
17
 
22
- # desc 'pipeline [subcommand]', 'Provides functions to access pipeline functions of the Jenkins CI server'
23
- # subcommand 'pipeline', CLI::Pipeline
24
- #
25
- # desc 'view [subcommand]', 'Provides functions to access view interface of Jenkins CI server'
26
- # subcommand 'view', CLI::View
27
- #
28
- # desc 'list [type]', 'Lists all registered modules of a type'
29
- # subcommand 'list', List
30
- #
31
- # desc 'describe [type]', 'Describe a module'
32
- # subcommand 'describe', Describe
18
+ desc 'list [all]', 'List tasks'
19
+ def list(all = nil)
20
+ ct = init_runner
21
+
22
+ ct.tasks.map do |task|
23
+ comment = task.comment
24
+ next if all != 'all' && comment.nil?
25
+ comment = (comment.nil?) ? '' : '# ' + comment
26
+ printf("%-40s %-40s\n\r", task.name, comment)
27
+ end
28
+ end
29
+
30
+ desc 'exec TASK_NAME', 'Run task by NAME'
31
+ def exec(name)
32
+ ct = init_runner
33
+
34
+ unless ct.contains?(name)
35
+ puts "Task with name '#{name}' doesn't exist."
36
+ abort
37
+ end
38
+
39
+ puts "Executing '#{name}'"
40
+ ct.invoke(name)
41
+ end
42
+
43
+ private
44
+
45
+ def init_runner
46
+ ct = Container::Templates::RakeTask.new
47
+ ct.process(path: options[:container_templates])
48
+
49
+ ct
50
+ end
33
51
  end
34
52
  end
35
53
  end
@@ -0,0 +1,167 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require 'pathname'
4
+ require 'erb'
5
+ require 'ostruct'
6
+ require 'yaml'
7
+ require_relative 'docker_utils'
8
+ require_relative 'dev_environment'
9
+
10
+ module Container
11
+ module Templates
12
+
13
+ class RakeTask # < ::Rake::TaskLib
14
+ # include Rake::TaskManager
15
+ include ::Rake::DSL if defined?(::Rake::DSL)
16
+
17
+ # Default pattern for template files.
18
+ # DEFAULT_PATTERN = 'container_templates/**{,/*/**}/*.{yml,yaml}'
19
+ DEFAULT_PATTERN = '**/*.{yml,yaml}'
20
+
21
+ DEFAULT_PATH = 'container_templates'
22
+
23
+ # Name of task. Defaults to `:container_templates`.
24
+ attr_accessor :name
25
+
26
+ # Path to Container templates. Defaults to the absolute path to the
27
+ # relative location of container templates.
28
+ attr_accessor :templates_path
29
+
30
+ # Files matching this pattern will be loaded.
31
+ # Defaults to `'**/*.{yml,yaml}'`.
32
+ attr_accessor :pattern
33
+
34
+ def initialize
35
+ options = Rake.application.options
36
+ options.trace = false
37
+ options.dryrun = false
38
+
39
+ Rake::TaskManager.record_task_metadata = true
40
+ end
41
+
42
+ def process(params)
43
+ @templates_path = params[:path] || DEFAULT_PATH
44
+ @pattern = params[:pattern] || DEFAULT_PATTERN
45
+
46
+ load_templates @templates_path, @pattern
47
+
48
+ scripts_path = File.join(@templates_path, 'scripts/*.rake')
49
+ puts "Loading scripts from '#{scripts_path}'" if LOG_LEVEL == 'DEBUG'
50
+
51
+ Dir.glob(scripts_path).each do |r|
52
+ load r
53
+ end
54
+ end
55
+
56
+ def options
57
+ options = OpenStruct.new
58
+ options.trace = false
59
+ options.dryrun = false
60
+ options
61
+ end
62
+
63
+ def tasks
64
+ Rake.application.tasks()
65
+ end
66
+
67
+ def contains?(task_name)
68
+ tasks.any? { |task| task.name == task_name }
69
+ end
70
+
71
+
72
+ def invoke(name)
73
+ Rake.application[name].invoke
74
+ end
75
+
76
+ private
77
+
78
+ def load_templates(path, pattern)
79
+ curr = Pathname.new(Dir.pwd) + path
80
+ # puts "Current: #{curr}"
81
+
82
+ FileList[File.join(path, pattern)].each do |f|
83
+ full_path = File.expand_path(f)
84
+ template_name = Pathname(strip_extension(full_path)).relative_path_from(curr)
85
+ # puts "Found #{template_name}: #{friendly_name(template_name.to_s)}"
86
+
87
+ load_template ('container:' + friendly_name(template_name.to_s)), full_path, template_name.to_s
88
+ end
89
+ end
90
+
91
+ def strip_extension(filename)
92
+ filename.gsub(/(\.yml|\.yaml|\.erb)/, '')
93
+ end
94
+
95
+ def friendly_name(filename)
96
+ filename.gsub(/[^\w\s_-]+/, '_')
97
+ .gsub(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2')
98
+ .gsub(/\s+/, '_')
99
+ end
100
+
101
+ def load_template(name, path, template_name, *args)
102
+ args || args = []
103
+
104
+ # desc "Starting #{template_name}"
105
+ task (name + ":start").to_sym do
106
+ puts "Starting: #{path}"
107
+ Docker::Utils.start_container load_container_template(path)
108
+ end
109
+
110
+ # # desc "Stopping #{template_name}"
111
+ task (name + ":stop").to_sym do
112
+ puts "Stopping: #{path}"
113
+ container_template = load_template_file(path)
114
+ Docker::Utils.stop_container container_template
115
+ end
116
+
117
+ # # desc "Restarting #{template_name}"
118
+ task (name + ":restart").to_sym do
119
+ puts "Restarting: #{path}"
120
+ Rake::Task[name + ":stop"].invoke
121
+ Rake::Task[name + ":start"].invoke
122
+ end
123
+
124
+ desc "Tasks help for #{template_name}"
125
+ task (name + ":help").to_sym do
126
+ puts "Tasks for: #{path}"
127
+ puts "rake #{name}:start\t\t# Starting #{template_name}"
128
+ puts "rake #{name}:stop\t\t# Stopping #{template_name}"
129
+ puts "rake #{name}:restart\t\t# Restarting #{template_name}"
130
+ end
131
+ end
132
+
133
+ def load_template_file(file_path)
134
+ puts "Loading #{file_path}" if LOG_LEVEL == 'DEBUG'
135
+
136
+ vars = {
137
+ dockerhost: Docker::Utils.dockerhost,
138
+ work_dir: Environment.work_dir
139
+ }
140
+
141
+ container_template = YAML.load_file(file_path)
142
+ if Pathname.new(file_path).basename.to_s.include? '.erb'
143
+ template = ERB.new(container_template.to_yaml).result(OpenStruct.new(vars).instance_eval { binding })
144
+ puts template if LOG_LEVEL == 'DEBUG'
145
+ container_template = YAML.load(template)
146
+ end
147
+
148
+ return container_template
149
+ end
150
+
151
+ def load_container_template(file_path)
152
+ container_template = load_template_file(file_path)
153
+
154
+ container_template.each do |template_id, template|
155
+ template['name'] = template_id
156
+ if template.key? 'environment'
157
+ environment = template['environment']
158
+ # TODO: simplify this
159
+ environment['LOG_LEVEL'] = LOG_LEVEL unless environment.key? 'LOG_LEVEL'
160
+ end
161
+ return template
162
+ end
163
+ end
164
+ end
165
+
166
+ end
167
+ end
@@ -0,0 +1,74 @@
1
+ require 'net/http'
2
+
3
+ module Environment
4
+ def self.work_dir
5
+ @work_dir = @work_dir || ENV['WORK_DIR'] || Dir.pwd
6
+ end
7
+
8
+ # def self.docker_host
9
+ # host_ip = ENV['HOST_IP']
10
+ # return host_ip unless host_ip.nil?
11
+ # host_ip = ENV['DOCKER_HOST']
12
+ # return nil if host_ip.nil?
13
+ # host_ip[/tcp:\/\/([^:]+)/,1]
14
+ # end
15
+ #
16
+ # def self.hostip
17
+ # @host_ip = @host_ip || docker_host || (`ifconfig docker0 | grep inet | grep 'inet\s' | awk '{print $2}'`).strip
18
+ # puts "#{@host_ip}."
19
+ # @host_ip
20
+ # end
21
+
22
+ def self.get_env(environment)
23
+ env = environment || 'development'
24
+ env.to_sym
25
+ end
26
+
27
+ def self.get_data(url)
28
+ command = "curl #{url}"
29
+ command += " 2> /dev/null" unless LOG_LEVEL == 'DEBUG'
30
+ puts command if LOG_LEVEL == 'DEBUG'
31
+ if Gem.win_platform?
32
+ uri = URI(url)
33
+ result = Net::HTTP.get(uri)
34
+ else
35
+ result = `#{command}`
36
+ end
37
+ puts result
38
+ validate!
39
+ puts "Result: #{result}" if LOG_LEVEL == 'DEBUG'
40
+ return result
41
+ end
42
+
43
+ def self.post_data(url, payload)
44
+ command = "curl -X PUT -d '#{payload}' #{url}"
45
+ command += " 2> /dev/null" unless LOG_LEVEL == 'DEBUG'
46
+ puts command if LOG_LEVEL == 'DEBUG'
47
+ if Gem.win_platform?
48
+ uri = URI(url)
49
+ http = Net::HTTP.new(uri.host, uri.port)
50
+ # http.set_debug_output($stdout)
51
+ header = {'Content-Type' => 'text/json'}
52
+ request = Net::HTTP::Put.new(uri.request_uri, initheader = header)
53
+ #request.add_field('Content-Type', 'application/json')
54
+ #request.add_field('Content-Type', 'text/plain; charset=utf-8')
55
+ request.body = payload #.to_json
56
+ response = http.request(request)
57
+ result = response.body
58
+ else
59
+ result = `#{command}`
60
+ end
61
+ validate!
62
+ puts "Result: #{result}" if LOG_LEVEL == 'DEBUG'
63
+ return result
64
+ end
65
+
66
+ def self.validate!
67
+ if $?.to_i == 0
68
+ puts 'OK' if LOG_LEVEL == 'DEBUG'
69
+ else
70
+ puts 'Failed' if LOG_LEVEL == 'DEBUG'
71
+ end
72
+ end
73
+
74
+ end
@@ -0,0 +1,165 @@
1
+ module Docker
2
+ class Utils
3
+
4
+ def self.dockerhost
5
+ @dockerhost = ENV['DOCKER_HOST']
6
+ return nil if @dockerhost.nil?
7
+ @dockerhost[/tcp:\/\/([^:]+)/,1]
8
+ end
9
+
10
+ def self.create_docker_command(info)
11
+ docker_cmd = ['docker']
12
+ docker_cmd.push info['action'] || 'run -d'
13
+ docker_cmd.push "--name=\"#{info['name']}\""
14
+ docker_cmd.push "--add-host=\"dockerhost:#{dockerhost}\"" unless info.key? 'net'
15
+ docker_cmd.push "--hostname=\"#{info['hostname']}\"" if info.key? 'hostname'
16
+ docker_cmd.push info['environment'].map { |k, v| "-e #{k.to_s}=\"#{v}\"" } if info.key? 'environment'
17
+ docker_cmd.push info['ports'].map { |port| "-p #{mirror_if_single(port)}" } if info.key? 'ports'
18
+ docker_cmd.push info['expose'].map { |port| "--expose=#{port}" } if info.key? 'expose'
19
+ docker_cmd.push info['links'].map { |link| "--link #{link}" } if info.key? 'links'
20
+ docker_cmd.push info['volumes_from'].map { |volume| "--volumes-from \"#{volume}\"" } if info.key? 'volumes_from'
21
+ docker_cmd.push info['volumes'].map { |volume| "-v #{quote_parts(volume)}" } if info.key? 'volumes'
22
+ docker_cmd.push "--net=\"#{info['net']}\"" if info.key? 'net'
23
+ docker_cmd.push '--privileged' if info['privileged'] == true
24
+ docker_cmd.push "--log-driver=\"#{info['log-driver']}\"" if info.key? 'log-driver'
25
+ docker_cmd.push info['log-opt'].map { |k, v| "--log-opt #{k.to_s}=\"#{v}\"" } if info.key? 'log-opt'
26
+ docker_cmd.push info['image']
27
+ docker_cmd.push info['command'] if info.key? 'command'
28
+ return docker_cmd.join(' ')
29
+ end
30
+
31
+ def self.quote_parts(text)
32
+ text.split(':').map { |s| "\"#{s}\""}.join(':')
33
+ end
34
+
35
+ def self.mirror_if_single(text)
36
+ parts = text.to_s.split(':')
37
+ parts.count == 1 ? "#{text}:#{text}" : text
38
+ end
39
+
40
+ def self.stop_container(container_template)
41
+
42
+ container_template.each do |template_id, _|
43
+ name = template_id
44
+ # containers = `docker ps`
45
+ ps = containers_by_name(name)
46
+ ps.each do |line|
47
+ if line != ''
48
+ cmd = "docker inspect -f {{.State.Running}} #{line}"
49
+ puts cmd if LOG_LEVEL == 'DEBUG'
50
+ is_running = `#{cmd}`.strip
51
+ if is_running == 'true'
52
+ cmd = "docker kill #{line}"
53
+ puts cmd if LOG_LEVEL == 'DEBUG'
54
+ `#{cmd}`
55
+ else
56
+ puts 'Container not running. Nothing to kill. Skipping...'
57
+ end
58
+ end
59
+ end
60
+
61
+ ps = containers_by_name(name)
62
+ ps.each do |line|
63
+ if line != ''
64
+ cmd = "docker rm #{line}"
65
+ puts cmd if LOG_LEVEL == 'DEBUG'
66
+ `#{cmd}`
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ def self.start_container(info)
73
+ command = create_docker_command(info)
74
+ puts command if LOG_LEVEL == 'DEBUG'
75
+ if present?(info['name'])
76
+ puts 'Detected as running. Skipping ....' # if LOG_LEVEL == 'DEBUG'
77
+ else
78
+ `#{command}`
79
+ end
80
+ Array(info['checks']).each do |check|
81
+ try = (check['retry'] || 3).to_i
82
+ interval = (check['interval'] || 2).to_i
83
+ while true
84
+ sleep interval
85
+ put_char '.' if LOG_LEVEL != 'DEBUG'
86
+ case check['type']
87
+ when 'port'
88
+ puts "Checking port #{check['ip']}:#{check['port']} availability." if LOG_LEVEL == 'DEBUG'
89
+ result = is_port_open?(check['ip'], check['port'])
90
+ puts "Result: #{result}" if LOG_LEVEL == 'DEBUG'
91
+ break if result
92
+ when 'rest'
93
+ puts "Checking HTTP response #{check['uri']}." if LOG_LEVEL == 'DEBUG'
94
+ result = is_http_present?(check['uri'])
95
+ puts "Result: #{result}" if LOG_LEVEL == 'DEBUG'
96
+ break if result
97
+ when 'script'
98
+ `#{check['script']}`
99
+ break if $?.to_i == 0
100
+ else
101
+ puts 'Unrecognizable check type. Skipping ...'
102
+ end
103
+ try -= 1
104
+ abort ' Health check failed all retries' if try == 0
105
+ end
106
+ puts
107
+ end
108
+ end
109
+
110
+ def self.put_char(str)
111
+ print str
112
+ $stdout.flush
113
+ end
114
+
115
+ def self.is_http_present?(url)
116
+ begin
117
+ uri = URI(url)
118
+ request = Net::HTTP::Get.new(uri.request_uri)
119
+ response = Net::HTTP.start(uri.host, uri.port, :read_timeout => 500) {|http| http.request(request)}
120
+
121
+ return response.code == '200'
122
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
123
+ # ignored
124
+ end
125
+ return false
126
+ end
127
+
128
+ def self.is_port_open?(ip, port)
129
+ begin
130
+ Timeout::timeout(1) do
131
+ begin
132
+ s = TCPSocket.new(ip, port)
133
+ s.close
134
+ return true
135
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
136
+ return false
137
+ end
138
+ end
139
+ rescue Timeout::Error
140
+ # ignored
141
+ end
142
+
143
+ return false
144
+ end
145
+
146
+ def self.present?(name)
147
+ ! containers_by_name(name).empty?
148
+ end
149
+
150
+ def self.containers_by_name(name)
151
+ containers = `docker ps -a`
152
+ ps = []
153
+ containers.each_line { |line| if line.include?(name) then ps << line.strip.partition(' ').first end }
154
+ ps
155
+ end
156
+
157
+ def self.get_image_id(name)
158
+ images = `docker images`
159
+ img = []
160
+ images.each_line { |line| if line.include?(name) then img << line.strip.partition(' ').first end }
161
+ img.first
162
+ end
163
+
164
+ end
165
+ end
@@ -1,3 +1,3 @@
1
1
  module DockerRack
2
- VERSION = '0.0.3'.freeze
2
+ VERSION = '0.0.4'.freeze
3
3
  end
data/lib/docker_rack.rb CHANGED
@@ -1,20 +1,13 @@
1
1
  require 'docker_rack/version'
2
2
 
3
+ require 'docker_rack/docker_utils'
4
+ require 'docker_rack/container_template'
5
+ # require 'docker_rack/task_mngr'
6
+
3
7
  module DockerRack
4
8
  class << self
5
- attr_reader :client, :credentials, :debug, :file_mode
9
+ attr_reader :client, :debug, :no_debug
6
10
  attr_writer :logger
7
- def generator
8
- @_generator ||= Generator.new
9
- end
10
-
11
- def file_mode!
12
- @file_mode = true
13
- end
14
-
15
- def normal_mode!
16
- @file_mode = false
17
- end
18
11
 
19
12
  def debug!
20
13
  @debug = true
@@ -26,20 +19,10 @@ module DockerRack
26
19
  logger.level = Logger::INFO
27
20
  end
28
21
 
29
- def credentials=(creds)
30
- @credentials = creds
31
- @client = JenkinsApi::Client.new(credentials)
32
- @credentials
33
- end
34
-
35
22
  def logger
36
23
  @logger ||= client ? client.logger : Logger.new(STDOUT)
37
24
  end
38
-
39
- def registry
40
- generator.module_registry
41
- end
42
25
  end
43
26
  end
44
27
 
45
- require 'docker_rack/cli/base'
28
+ require 'docker_rack/cli/base'
@@ -0,0 +1,36 @@
1
+ require 'rspec'
2
+
3
+ require 'simplecov'
4
+ require 'simplecov-rcov'
5
+
6
+ require File.expand_path('../../../../lib/docker_rack', __FILE__)
7
+
8
+ RSpec::Matchers.define :have_min_version do |version|
9
+ match do |base|
10
+ @set = base
11
+ !base.extensions.select { |ext| ext.min_version == version }.empty?
12
+ end
13
+
14
+ failure_message do
15
+ versions = @set.map(&:min_version).join(', ')
16
+ "Expected to find extension #{@set.name} with version #{version}, found #{versions} instead"
17
+ end
18
+ end
19
+
20
+ RSpec.configure do |config|
21
+ config.expect_with :rspec do |c|
22
+ c.syntax = :expect
23
+ end
24
+ end
25
+
26
+ RSpec::Matchers.define :have_registered_versions do |versions|
27
+ match do |set|
28
+ @set = set
29
+ @registered_versions = set.versions.keys.map(&:version)
30
+ @registered_versions.sort == versions.sort
31
+ end
32
+
33
+ failure_message do
34
+ "Expected #{@set.name} to have registered versions #{versions}. Got #{@registered_versions}"
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Container::Templates do
4
+ describe 'test' do
5
+ puts 'Test'
6
+ end
7
+ end
metadata CHANGED
@@ -1,19 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker_rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Moochnick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-06 00:00:00.000000000 Z
11
+ date: 2016-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: thor
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.18'
17
34
  - - ">="
18
35
  - !ruby/object:Gem::Version
19
36
  version: 0.18.0
@@ -21,6 +38,9 @@ dependencies:
21
38
  prerelease: false
22
39
  version_requirements: !ruby/object:Gem::Requirement
23
40
  requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '0.18'
24
44
  - - ">="
25
45
  - !ruby/object:Gem::Version
26
46
  version: 0.18.0
@@ -39,7 +59,21 @@ dependencies:
39
59
  - !ruby/object:Gem::Version
40
60
  version: '1.3'
41
61
  - !ruby/object:Gem::Dependency
42
- name: rake
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: bump
43
77
  requirement: !ruby/object:Gem::Requirement
44
78
  requirements:
45
79
  - - ">="
@@ -53,21 +87,21 @@ dependencies:
53
87
  - !ruby/object:Gem::Version
54
88
  version: '0'
55
89
  - !ruby/object:Gem::Dependency
56
- name: rspec
90
+ name: json
57
91
  requirement: !ruby/object:Gem::Requirement
58
92
  requirements:
59
- - - "~>"
93
+ - - ">="
60
94
  - !ruby/object:Gem::Version
61
- version: '3.0'
95
+ version: '0'
62
96
  type: :development
63
97
  prerelease: false
64
98
  version_requirements: !ruby/object:Gem::Requirement
65
99
  requirements:
66
- - - "~>"
100
+ - - ">="
67
101
  - !ruby/object:Gem::Version
68
- version: '3.0'
102
+ version: '0'
69
103
  - !ruby/object:Gem::Dependency
70
- name: bump
104
+ name: gem-release
71
105
  requirement: !ruby/object:Gem::Requirement
72
106
  requirements:
73
107
  - - ">="
@@ -81,7 +115,7 @@ dependencies:
81
115
  - !ruby/object:Gem::Version
82
116
  version: '0'
83
117
  - !ruby/object:Gem::Dependency
84
- name: json
118
+ name: simplecov
85
119
  requirement: !ruby/object:Gem::Requirement
86
120
  requirements:
87
121
  - - ">="
@@ -95,7 +129,7 @@ dependencies:
95
129
  - !ruby/object:Gem::Version
96
130
  version: '0'
97
131
  - !ruby/object:Gem::Dependency
98
- name: gem-release
132
+ name: simplecov-rcov
99
133
  requirement: !ruby/object:Gem::Requirement
100
134
  requirements:
101
135
  - - ">="
@@ -159,13 +193,23 @@ extensions: []
159
193
  extra_rdoc_files: []
160
194
  files:
161
195
  - ".gitignore"
196
+ - ".rspec"
162
197
  - ".rubocop.yml"
198
+ - ".rubocop_todo.yml"
163
199
  - Gemfile
200
+ - Gemfile.lock
164
201
  - LICENSE
202
+ - Rakefile
165
203
  - bin/docker_rack
204
+ - docker_rack.gemspec
166
205
  - lib/docker_rack.rb
167
206
  - lib/docker_rack/cli/base.rb
207
+ - lib/docker_rack/container_template.rb
208
+ - lib/docker_rack/dev_environment.rb
209
+ - lib/docker_rack/docker_utils.rb
168
210
  - lib/docker_rack/version.rb
211
+ - spec/lib/docker_rack/spec_helper.rb
212
+ - spec/lib/docker_rack/task_mngr_spec.rb
169
213
  homepage: https://github.com/igorshare/docker_rack
170
214
  licenses:
171
215
  - MIT
@@ -190,5 +234,7 @@ rubygems_version: 2.4.5.1
190
234
  signing_key:
191
235
  specification_version: 4
192
236
  summary: This gem will orchestrate local Docker containers
193
- test_files: []
237
+ test_files:
238
+ - spec/lib/docker_rack/spec_helper.rb
239
+ - spec/lib/docker_rack/task_mngr_spec.rb
194
240
  has_rdoc: