docker_rack 0.0.5 → 0.0.6

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: 8f5cc5e09334e35027c40055aa1d1382fd758d69
4
- data.tar.gz: 82ece69939e1e74f359809f86440af5b2db14659
3
+ metadata.gz: 9aedc0085f11b56cb2f360414cfcbe24dd37b745
4
+ data.tar.gz: 4a207c2a8aaac2dc8886bee3fa65bc9836a51fc2
5
5
  SHA512:
6
- metadata.gz: 384018106a1cfdb4275f823808623524c9de6988ec3ebc3bb7e3a8181b58c8aea23d460a2ee399cc6774d249e726c4cc58d896a7bd50b952ea3a3951809ab550
7
- data.tar.gz: 24484e7449dd7f195f8bb6034df8bedb967ef5d60e4fe2b093ca6c4a7bf209ae5573ffd2b97baab41509cb4646d485d88d0edc82dcfe835485310951bb2be0f9
6
+ metadata.gz: 572c8d621e1836d9f7be30222bc262ae219842e92d19b2ea0a18f67c5342dca41efa16e79aafab779442551f52cc547e4f5c0842662ec27acece3a8cb9e01ee7
7
+ data.tar.gz: d6ecdada512abf538a764c48af821e3f0ff64c48f9293ebfd4a9f71c933eb5c8213f01d92254188c78f570346a090b2342b2879c550ec06967feced21c201cb5
data/.rubocop.yml CHANGED
@@ -1,10 +1,13 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
+ AllCops:
4
+ TargetRubyVersion: 2.2
5
+
3
6
  #######
4
7
  # WIP These should all go back to defaults at some point
5
8
  Metrics/AbcSize:
6
9
  Max: 22
7
10
  Metrics/MethodLength:
8
- Max: 30
11
+ Max: 40
9
12
  Metrics/ClassLength:
10
13
  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 18:30:47 -0500 using RuboCop version 0.37.0.
3
+ # on 2016-02-07 23:58:16 -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
@@ -16,7 +16,7 @@ Lint/LiteralInCondition:
16
16
  Exclude:
17
17
  - 'lib/docker_rack/docker_utils.rb'
18
18
 
19
- # Offense count: 4
19
+ # Offense count: 2
20
20
  Lint/ParenthesesAsGroupedExpression:
21
21
  Exclude:
22
22
  - 'lib/docker_rack/container_template.rb'
@@ -27,26 +27,20 @@ Lint/StringConversionInInterpolation:
27
27
  Exclude:
28
28
  - 'lib/docker_rack/docker_utils.rb'
29
29
 
30
- # Offense count: 2
30
+ # Offense count: 1
31
31
  Lint/UselessAssignment:
32
32
  Exclude:
33
- - 'lib/docker_rack/container_template.rb'
34
33
  - 'lib/docker_rack/dev_environment.rb'
35
34
 
36
35
  # Offense count: 3
37
36
  Metrics/CyclomaticComplexity:
38
37
  Max: 15
39
38
 
40
- # Offense count: 23
39
+ # Offense count: 27
41
40
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
42
41
  # URISchemes: http, https
43
42
  Metrics/LineLength:
44
- Max: 121
45
-
46
- # Offense count: 3
47
- # Configuration parameters: CountComments.
48
- Metrics/MethodLength:
49
- Max: 30
43
+ Max: 118
50
44
 
51
45
  # Offense count: 3
52
46
  Metrics/PerceivedComplexity:
@@ -65,7 +59,7 @@ Style/ColonMethodCall:
65
59
  Exclude:
66
60
  - 'lib/docker_rack/docker_utils.rb'
67
61
 
68
- # Offense count: 6
62
+ # Offense count: 5
69
63
  Style/Documentation:
70
64
  Exclude:
71
65
  - 'spec/**/*'
@@ -75,7 +69,6 @@ Style/Documentation:
75
69
  - 'lib/docker_rack/container_template.rb'
76
70
  - 'lib/docker_rack/dev_environment.rb'
77
71
  - 'lib/docker_rack/docker_utils.rb'
78
- - 'lib/docker_rack/task_mngr1.rb'
79
72
 
80
73
  # Offense count: 2
81
74
  # Cop supports --auto-correct.
@@ -102,9 +95,17 @@ Style/EmptyLinesAroundModuleBody:
102
95
 
103
96
  # Offense count: 1
104
97
  # Cop supports --auto-correct.
105
- # Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
106
- Style/ExtraSpacing:
98
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
99
+ # SupportedStyles: when_needed, always
100
+ Style/FrozenStringLiteralComment:
101
+ Exclude:
102
+ - 'lib/docker_rack/version.rb'
103
+
104
+ # Offense count: 2
105
+ # Configuration parameters: AllowedVariables.
106
+ Style/GlobalVars:
107
107
  Exclude:
108
+ - 'container_templates/scripts/settings.rake'
108
109
  - 'lib/docker_rack/container_template.rb'
109
110
 
110
111
  # Offense count: 2
@@ -198,7 +199,7 @@ Style/RegexpLiteral:
198
199
  Style/SpaceInsideBlockBraces:
199
200
  Enabled: false
200
201
 
201
- # Offense count: 2
202
+ # Offense count: 6
202
203
  # Cop supports --auto-correct.
203
204
  # Configuration parameters: EnforcedStyleForEmptyBraces, SupportedStyles.
204
205
  # SupportedStyles: space, no_space
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.2.3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- docker_rack (0.0.5)
4
+ docker_rack (0.0.6)
5
5
  rake (~> 0)
6
6
  thor (~> 0.18, >= 0.18.0)
7
7
 
@@ -1,13 +1,15 @@
1
- # rubocop:disable Metrics/AbcSize
2
-
3
1
  require 'rake'
4
2
  require 'rake/tasklib'
5
3
  require 'pathname'
6
4
  require 'erb'
7
5
  require 'ostruct'
8
6
  require 'yaml'
7
+ require 'json/ext'
8
+ require 'net/http'
9
+
9
10
  require_relative 'docker_utils'
10
11
  require_relative 'dev_environment'
12
+ require_relative 'utils'
11
13
 
12
14
  module Container
13
15
  module Templates
@@ -39,6 +41,8 @@ module Container
39
41
  options.dryrun = false
40
42
 
41
43
  Rake::TaskManager.record_task_metadata = true
44
+
45
+ $environment = environment
42
46
  end
43
47
 
44
48
  def process(params)
@@ -55,13 +59,6 @@ module Container
55
59
  end
56
60
  end
57
61
 
58
- def options
59
- options = OpenStruct.new
60
- options.trace = false
61
- options.dryrun = false
62
- options
63
- end
64
-
65
62
  def tasks
66
63
  Rake.application.tasks()
67
64
  end
@@ -74,18 +71,21 @@ module Container
74
71
  Rake.application[name].invoke
75
72
  end
76
73
 
74
+ def environment
75
+ {
76
+ dockerhost: Docker::Utils.dockerhost,
77
+ work_dir: Environment.work_dir
78
+ }
79
+ end
80
+
77
81
  private
78
82
 
79
83
  def load_templates(path, pattern)
80
- curr = Pathname.new(Dir.pwd) + path
84
+ # curr = Pathname.new(Dir.pwd) + path
81
85
  # puts "Current: #{curr}"
82
86
 
83
87
  FileList[File.join(path, pattern)].each do |f|
84
- full_path = File.expand_path(f)
85
- template_name = Pathname(strip_extension(full_path)).relative_path_from(curr)
86
- # puts "Found #{template_name}: #{friendly_name(template_name.to_s)}"
87
-
88
- load_template ('container:' + friendly_name(template_name.to_s)), full_path, template_name.to_s
88
+ load_template_from_file File.expand_path(f)
89
89
  end
90
90
  end
91
91
 
@@ -99,53 +99,87 @@ module Container
99
99
  .gsub(/\s+/, '_')
100
100
  end
101
101
 
102
- def load_template(name, path, template_name, *args)
103
- args || args = []
102
+ def load_template_from_file(path)
103
+ load_container_template(path).each do |_, container_template|
104
+ define_start_task container_template, path
105
+ define_stop_task container_template, path
106
+ define_restart_task container_template, path
107
+ define_help_task container_template, path
108
+ end
109
+ end
110
+
111
+ def define_start_task(container_template, path)
112
+ container_name = "container:#{container_template['name']}:start"
113
+ dependencies = container_template['depends']
104
114
 
105
- # desc "Starting #{template_name}"
106
- task (name + ':start').to_sym do
115
+ args = []
116
+ if dependencies.nil?
117
+ args.insert 0, container_name
118
+ else
119
+ args.insert 0, container_name => dependencies.map { |id| "container:#{id}:start" }
120
+ end
121
+
122
+ body = proc do
107
123
  puts "Starting: #{path}"
108
- Docker::Utils.start_container load_container_template(path)
124
+ Docker::Utils.start_container container_template
109
125
  end
110
126
 
111
- # # desc "Stopping #{template_name}"
112
- task (name + ':stop').to_sym do
127
+ Rake::Task.define_task(*args, &body)
128
+ end
129
+
130
+ def define_stop_task(container_template, path)
131
+ container_name = "container:#{container_template['name']}:stop"
132
+ dependencies = container_template['depends'] || []
133
+
134
+ args = []
135
+ args.insert 0, container_name
136
+
137
+ body = proc do
113
138
  puts "Stopping: #{path}"
114
- container_template = load_template_file(path)
115
139
  Docker::Utils.stop_container container_template
116
140
  end
117
141
 
118
- # # desc "Restarting #{template_name}"
119
- task (name + ':restart').to_sym do
142
+ Rake::Task.define_task(*args, &body)
143
+
144
+ # Create reverse dependency
145
+ dependencies.map { |id| "container:#{id}:stop" }.each do |id|
146
+ task id => container_name
147
+ end
148
+ end
149
+
150
+ def define_restart_task(container_template, path)
151
+ container_name = "container:#{container_template['name']}"
152
+ task (container_name + ':restart').to_sym do
120
153
  puts "Restarting: #{path}"
121
- Rake::Task[name + ':stop'].invoke
122
- Rake::Task[name + ':start'].invoke
154
+ Rake::Task[container_name + ':stop'].invoke
155
+ Rake::Task[container_name + ':start'].invoke
123
156
  end
157
+ end
124
158
 
125
- desc "Tasks help for #{template_name}"
126
- task (name + ':help').to_sym do
159
+ def define_help_task(container_template, path)
160
+ container_name = "container:#{container_template['name']}"
161
+ desc "Tasks help for #{container_name}"
162
+ task (container_name + ':help').to_sym do
127
163
  puts "Tasks for: #{path}"
128
- puts "rake #{name}:start\t\t# Starting #{template_name}"
129
- puts "rake #{name}:stop\t\t# Stopping #{template_name}"
130
- puts "rake #{name}:restart\t\t# Restarting #{template_name}"
164
+ printf("%-40s %-40s\n\r", "#{container_name}:start", "# Starting #{container_name}")
165
+ printf("%-40s %-40s\n\r", "#{container_name}:stop", "# Stopping #{container_name}")
166
+ printf("%-40s %-40s\n\r", "#{container_name}:restart", "# Restarting #{container_name}")
131
167
  end
132
168
  end
133
169
 
134
170
  def load_template_file(file_path)
135
171
  puts "Loading #{file_path}" if LOG_LEVEL == 'DEBUG'
136
172
 
137
- vars = {
138
- dockerhost: Docker::Utils.dockerhost,
139
- work_dir: Environment.work_dir
140
- }
173
+ vars = environment
141
174
 
142
175
  container_template = YAML.load_file(file_path)
143
176
  if Pathname.new(file_path).basename.to_s.include? '.erb'
144
177
  template = ERB.new(container_template.to_yaml).result(OpenStruct.new(vars).instance_eval { binding })
145
- puts template if LOG_LEVEL == 'DEBUG'
146
178
  container_template = YAML.load(template)
147
179
  end
148
180
 
181
+ puts container_template.to_yaml if LOG_LEVEL == 'DEBUG'
182
+
149
183
  return container_template
150
184
  end
151
185
 
@@ -154,12 +188,10 @@ module Container
154
188
 
155
189
  container_template.each do |template_id, template|
156
190
  template['name'] = template_id
157
- if template.key? 'environment'
158
- environment = template['environment']
159
- # TODO: simplify this
160
- environment['LOG_LEVEL'] = LOG_LEVEL unless environment.key? 'LOG_LEVEL'
161
- end
162
- return template
191
+ next unless template.key? 'environment'
192
+ environment = template['environment']
193
+ # TODO: simplify this
194
+ environment['LOG_LEVEL'] = LOG_LEVEL unless environment.key? 'LOG_LEVEL'
163
195
  end
164
196
  end
165
197
  end
@@ -41,32 +41,30 @@ module Docker
41
41
 
42
42
  def self.stop_container(container_template)
43
43
 
44
- container_template.each do |template_id, _|
45
- name = template_id
46
- # containers = `docker ps`
47
- ps = containers_by_name(name)
48
- ps.each do |line|
49
- if line != ''
50
- cmd = "docker inspect -f {{.State.Running}} #{line}"
44
+ name = container_template['name']
45
+ # containers = `docker ps`
46
+ ps = containers_by_name(name)
47
+ ps.each do |line|
48
+ if line != ''
49
+ cmd = "docker inspect -f {{.State.Running}} #{line}"
50
+ puts cmd if LOG_LEVEL == 'DEBUG'
51
+ is_running = `#{cmd}`.strip
52
+ if is_running == 'true'
53
+ cmd = "docker kill #{line}"
51
54
  puts cmd if LOG_LEVEL == 'DEBUG'
52
- is_running = `#{cmd}`.strip
53
- if is_running == 'true'
54
- cmd = "docker kill #{line}"
55
- puts cmd if LOG_LEVEL == 'DEBUG'
56
- `#{cmd}`
57
- else
58
- puts 'Container not running. Nothing to kill. Skipping...'
59
- end
55
+ `#{cmd}`
56
+ else
57
+ puts 'Container not running. Nothing to kill. Skipping...'
60
58
  end
61
59
  end
60
+ end
62
61
 
63
- ps = containers_by_name(name)
64
- ps.each do |line|
65
- if line != ''
66
- cmd = "docker rm #{line}"
67
- puts cmd if LOG_LEVEL == 'DEBUG'
68
- `#{cmd}`
69
- end
62
+ ps = containers_by_name(name)
63
+ ps.each do |line|
64
+ if line != ''
65
+ cmd = "docker rm #{line}"
66
+ puts cmd if LOG_LEVEL == 'DEBUG'
67
+ `#{cmd}`
70
68
  end
71
69
  end
72
70
  end
@@ -75,6 +73,7 @@ module Docker
75
73
  command = create_docker_command(info)
76
74
  puts command if LOG_LEVEL == 'DEBUG'
77
75
  if present?(info['name'])
76
+ skip_first_sleep = true
78
77
  puts 'Detected as running. Skipping ....' # if LOG_LEVEL == 'DEBUG'
79
78
  else
80
79
  `#{command}`
@@ -85,7 +84,8 @@ module Docker
85
84
  check['ip'] ||= dockerhost
86
85
  detect_check(check)
87
86
  while true
88
- sleep interval
87
+ sleep interval unless skip_first_sleep
88
+ skip_first_sleep = false
89
89
  put_char '.' if LOG_LEVEL != 'DEBUG'
90
90
  case check['type']
91
91
  when 'port'
@@ -0,0 +1,25 @@
1
+ # Collection of useful utilities
2
+ class Utils
3
+ def self.http_get(url)
4
+ uri = URI.parse(url)
5
+ http = Net::HTTP.new(uri.host, uri.port)
6
+ request = Net::HTTP::Get.new(uri.request_uri, 'Content-Type' => 'application/json')
7
+
8
+ http.request(request)
9
+ end
10
+
11
+ def self.http_post(url, json)
12
+ uri = URI.parse(url)
13
+
14
+ json_headers = {'Content-Type' => 'application/json',
15
+ 'Accept' => 'application/json'}
16
+
17
+ http = Net::HTTP.new(uri.host, uri.port)
18
+
19
+ response = http.post(uri.path, json.to_json, json_headers)
20
+ # puts response.code
21
+ # puts "Response #{response.code} #{response.message}:
22
+ # {response.body}"
23
+ response
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module DockerRack
2
- VERSION = '0.0.5'.freeze
2
+ VERSION = '0.0.6'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker_rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
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-07 00:00:00.000000000 Z
11
+ date: 2016-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -196,6 +196,7 @@ files:
196
196
  - ".rspec"
197
197
  - ".rubocop.yml"
198
198
  - ".rubocop_todo.yml"
199
+ - ".ruby-version"
199
200
  - Gemfile
200
201
  - Gemfile.lock
201
202
  - LICENSE
@@ -207,6 +208,7 @@ files:
207
208
  - lib/docker_rack/container_template.rb
208
209
  - lib/docker_rack/dev_environment.rb
209
210
  - lib/docker_rack/docker_utils.rb
211
+ - lib/docker_rack/utils.rb
210
212
  - lib/docker_rack/version.rb
211
213
  - spec/lib/docker_rack/spec_helper.rb
212
214
  - spec/lib/docker_rack/task_mngr_spec.rb