docker_rack 0.0.4 → 0.0.5

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: ea65c176d2cfb82e154297fe668c4473c2c9af26
4
- data.tar.gz: cf8c6de8e2163233ff8a7d41d8460f993ee9e482
3
+ metadata.gz: 8f5cc5e09334e35027c40055aa1d1382fd758d69
4
+ data.tar.gz: 82ece69939e1e74f359809f86440af5b2db14659
5
5
  SHA512:
6
- metadata.gz: fec22a282babc91291bec9be6f2042cef5500fc3ed6565a9c8b3ab937505fd4de5debfb96420aa9363a0ee21b3f1792bace6b015657471554154985d656a0a6d
7
- data.tar.gz: 3aa4405e349873862a16d8a8e7e3feef743a7d4e6c91ca13e5d7b73f8c9025933052dcd5925bf1aeb7dbd0e2d33c6262ac074bd95e141722ba82447352824285
6
+ metadata.gz: 384018106a1cfdb4275f823808623524c9de6988ec3ebc3bb7e3a8181b58c8aea23d460a2ee399cc6774d249e726c4cc58d896a7bd50b952ea3a3951809ab550
7
+ data.tar.gz: 24484e7449dd7f195f8bb6034df8bedb967ef5d60e4fe2b093ca6c4a7bf209ae5573ffd2b97baab41509cb4646d485d88d0edc82dcfe835485310951bb2be0f9
data/.rubocop.yml CHANGED
@@ -5,6 +5,6 @@ inherit_from: .rubocop_todo.yml
5
5
  Metrics/AbcSize:
6
6
  Max: 22
7
7
  Metrics/MethodLength:
8
- Max: 20
8
+ Max: 30
9
9
  Metrics/ClassLength:
10
10
  Max: 190
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2016-02-07 13:41:07 -0500 using RuboCop version 0.37.0.
3
+ # on 2016-02-07 18:30:47 -0500 using RuboCop version 0.37.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -33,15 +33,11 @@ Lint/UselessAssignment:
33
33
  - 'lib/docker_rack/container_template.rb'
34
34
  - 'lib/docker_rack/dev_environment.rb'
35
35
 
36
- # Offense count: 3
37
- Metrics/AbcSize:
38
- Max: 59
39
-
40
36
  # Offense count: 3
41
37
  Metrics/CyclomaticComplexity:
42
- Max: 18
38
+ Max: 15
43
39
 
44
- # Offense count: 24
40
+ # Offense count: 23
45
41
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
46
42
  # URISchemes: http, https
47
43
  Metrics/LineLength:
@@ -50,11 +46,11 @@ Metrics/LineLength:
50
46
  # Offense count: 3
51
47
  # Configuration parameters: CountComments.
52
48
  Metrics/MethodLength:
53
- Max: 35
49
+ Max: 30
54
50
 
55
51
  # Offense count: 3
56
52
  Metrics/PerceivedComplexity:
57
- Max: 17
53
+ Max: 15
58
54
 
59
55
  # Offense count: 3
60
56
  # Cop supports --auto-correct.
@@ -69,12 +65,6 @@ Style/ColonMethodCall:
69
65
  Exclude:
70
66
  - 'lib/docker_rack/docker_utils.rb'
71
67
 
72
- # Offense count: 2
73
- # Cop supports --auto-correct.
74
- Style/CommentIndentation:
75
- Exclude:
76
- - 'lib/docker_rack/docker_utils.rb'
77
-
78
68
  # Offense count: 6
79
69
  Style/Documentation:
80
70
  Exclude:
@@ -87,12 +77,6 @@ Style/Documentation:
87
77
  - 'lib/docker_rack/docker_utils.rb'
88
78
  - 'lib/docker_rack/task_mngr1.rb'
89
79
 
90
- # Offense count: 1
91
- # Cop supports --auto-correct.
92
- Style/EmptyLines:
93
- Exclude:
94
- - 'lib/docker_rack/container_template.rb'
95
-
96
80
  # Offense count: 2
97
81
  # Cop supports --auto-correct.
98
82
  # Configuration parameters: EnforcedStyle, SupportedStyles.
@@ -148,12 +132,6 @@ Style/InfiniteLoop:
148
132
  Exclude:
149
133
  - 'lib/docker_rack/docker_utils.rb'
150
134
 
151
- # Offense count: 3
152
- # Cop supports --auto-correct.
153
- Style/LeadingCommentSpace:
154
- Exclude:
155
- - 'lib/docker_rack/dev_environment.rb'
156
-
157
135
  # Offense count: 1
158
136
  # Cop supports --auto-correct.
159
137
  Style/MethodCallParentheses:
@@ -196,7 +174,7 @@ Style/RedundantParentheses:
196
174
  Exclude:
197
175
  - 'lib/docker_rack/cli/base.rb'
198
176
 
199
- # Offense count: 6
177
+ # Offense count: 9
200
178
  # Cop supports --auto-correct.
201
179
  # Configuration parameters: AllowMultipleReturnValues.
202
180
  Style/RedundantReturn:
@@ -213,25 +191,6 @@ Style/RegexpLiteral:
213
191
  Exclude:
214
192
  - 'lib/docker_rack/docker_utils.rb'
215
193
 
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
194
  # Offense count: 3
236
195
  # Cop supports --auto-correct.
237
196
  # Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
@@ -239,12 +198,6 @@ Style/SpaceAroundOperators:
239
198
  Style/SpaceInsideBlockBraces:
240
199
  Enabled: false
241
200
 
242
- # Offense count: 4
243
- # Cop supports --auto-correct.
244
- Style/SpaceInsideBrackets:
245
- Exclude:
246
- - 'container_templates/scripts/settings.rake'
247
-
248
201
  # Offense count: 2
249
202
  # Cop supports --auto-correct.
250
203
  # Configuration parameters: EnforcedStyleForEmptyBraces, SupportedStyles.
@@ -259,18 +212,9 @@ Style/SpaceInsideHashLiteralBraces:
259
212
  Style/SpecialGlobalVars:
260
213
  Enabled: false
261
214
 
262
- # Offense count: 8
215
+ # Offense count: 2
263
216
  # Cop supports --auto-correct.
264
217
  # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
265
218
  # SupportedStyles: single_quotes, double_quotes
266
219
  Style/StringLiterals:
267
220
  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 CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- docker_rack (0.0.4)
4
+ docker_rack (0.0.5)
5
5
  rake (~> 0)
6
6
  thor (~> 0.18, >= 0.18.0)
7
7
 
data/bin/docker_rack CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
4
4
  require 'docker_rack'
5
- DockerRack::CLI::Base.start
5
+ DockerRack::CLI::Base.start
@@ -50,4 +50,4 @@ module DockerRack
50
50
  end
51
51
  end
52
52
  end
53
- end
53
+ end
@@ -1,3 +1,5 @@
1
+ # rubocop:disable Metrics/AbcSize
2
+
1
3
  require 'rake'
2
4
  require 'rake/tasklib'
3
5
  require 'pathname'
@@ -68,7 +70,6 @@ module Container
68
70
  tasks.any? { |task| task.name == task_name }
69
71
  end
70
72
 
71
-
72
73
  def invoke(name)
73
74
  Rake.application[name].invoke
74
75
  end
@@ -102,27 +103,27 @@ module Container
102
103
  args || args = []
103
104
 
104
105
  # desc "Starting #{template_name}"
105
- task (name + ":start").to_sym do
106
+ task (name + ':start').to_sym do
106
107
  puts "Starting: #{path}"
107
108
  Docker::Utils.start_container load_container_template(path)
108
109
  end
109
110
 
110
111
  # # desc "Stopping #{template_name}"
111
- task (name + ":stop").to_sym do
112
+ task (name + ':stop').to_sym do
112
113
  puts "Stopping: #{path}"
113
114
  container_template = load_template_file(path)
114
115
  Docker::Utils.stop_container container_template
115
116
  end
116
117
 
117
118
  # # desc "Restarting #{template_name}"
118
- task (name + ":restart").to_sym do
119
+ task (name + ':restart').to_sym do
119
120
  puts "Restarting: #{path}"
120
- Rake::Task[name + ":stop"].invoke
121
- Rake::Task[name + ":start"].invoke
121
+ Rake::Task[name + ':stop'].invoke
122
+ Rake::Task[name + ':start'].invoke
122
123
  end
123
124
 
124
125
  desc "Tasks help for #{template_name}"
125
- task (name + ":help").to_sym do
126
+ task (name + ':help').to_sym do
126
127
  puts "Tasks for: #{path}"
127
128
  puts "rake #{name}:start\t\t# Starting #{template_name}"
128
129
  puts "rake #{name}:stop\t\t# Stopping #{template_name}"
@@ -140,7 +141,7 @@ module Container
140
141
 
141
142
  container_template = YAML.load_file(file_path)
142
143
  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
+ template = ERB.new(container_template.to_yaml).result(OpenStruct.new(vars).instance_eval { binding })
144
145
  puts template if LOG_LEVEL == 'DEBUG'
145
146
  container_template = YAML.load(template)
146
147
  end
@@ -50,9 +50,9 @@ module Environment
50
50
  # http.set_debug_output($stdout)
51
51
  header = {'Content-Type' => 'text/json'}
52
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
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
56
  response = http.request(request)
57
57
  result = response.body
58
58
  else
@@ -1,10 +1,12 @@
1
+ # rubocop:disable Metrics/AbcSize
2
+
1
3
  module Docker
2
4
  class Utils
3
5
 
4
6
  def self.dockerhost
5
7
  @dockerhost = ENV['DOCKER_HOST']
6
8
  return nil if @dockerhost.nil?
7
- @dockerhost[/tcp:\/\/([^:]+)/,1]
9
+ @dockerhost[/tcp:\/\/([^:]+)/, 1]
8
10
  end
9
11
 
10
12
  def self.create_docker_command(info)
@@ -80,23 +82,18 @@ module Docker
80
82
  Array(info['checks']).each do |check|
81
83
  try = (check['retry'] || 3).to_i
82
84
  interval = (check['interval'] || 2).to_i
85
+ check['ip'] ||= dockerhost
86
+ detect_check(check)
83
87
  while true
84
88
  sleep interval
85
89
  put_char '.' if LOG_LEVEL != 'DEBUG'
86
90
  case check['type']
87
91
  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
+ break if check_port(check)
92
93
  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
94
+ break if check_rest(check)
97
95
  when 'script'
98
- `#{check['script']}`
99
- break if $?.to_i == 0
96
+ break if check_script(check)
100
97
  else
101
98
  puts 'Unrecognizable check type. Skipping ...'
102
99
  end
@@ -107,6 +104,34 @@ module Docker
107
104
  end
108
105
  end
109
106
 
107
+ def self.detect_check(check)
108
+ return if check.key?('type')
109
+ if check.key?('port')
110
+ check['type'] = 'port'
111
+ elsif check.key?('uri')
112
+ check['type'] = 'rest'
113
+ end
114
+ end
115
+
116
+ def self.check_port(check)
117
+ puts "Checking port #{check['ip']}:#{check['port']} availability." if LOG_LEVEL == 'DEBUG'
118
+ result = is_port_open?(check['ip'], check['port'])
119
+ puts "Result: #{result}" if LOG_LEVEL == 'DEBUG'
120
+ return result
121
+ end
122
+
123
+ def self.check_rest(check)
124
+ puts "Checking HTTP response #{check['uri']}." if LOG_LEVEL == 'DEBUG'
125
+ result = is_http_present?(check['uri'])
126
+ puts "Result: #{result}" if LOG_LEVEL == 'DEBUG'
127
+ return result
128
+ end
129
+
130
+ def self.check_script(check)
131
+ `#{check['script']}`
132
+ return $?.to_i == 0
133
+ end
134
+
110
135
  def self.put_char(str)
111
136
  print str
112
137
  $stdout.flush
@@ -144,7 +169,7 @@ module Docker
144
169
  end
145
170
 
146
171
  def self.present?(name)
147
- ! containers_by_name(name).empty?
172
+ !containers_by_name(name).empty?
148
173
  end
149
174
 
150
175
  def self.containers_by_name(name)
@@ -1,3 +1,3 @@
1
1
  module DockerRack
2
- VERSION = '0.0.4'.freeze
2
+ VERSION = '0.0.5'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker_rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Moochnick