dory 0.5.0 → 0.5.1

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: 453ef08977df972322e1995689d8b358cb6f345d
4
- data.tar.gz: 40e16950427429b82d877302f465183f71ced5b8
3
+ metadata.gz: 1c9a8eb4e309988a08bc4418c313cc5fcd942fef
4
+ data.tar.gz: ea5da1d8d1541824b3566669565c614414e27ad3
5
5
  SHA512:
6
- metadata.gz: 8d883026dd79a18d5ec040e4df9ff81fd055f4b517071eb1ebd936f250343f71063aa05f258a0f6db084a7287a746af97a2bc457e2a4daa2b85e91f473a1e13a
7
- data.tar.gz: d35f5e27adebcca7de68609ab7dab69e8aae9fc31705c40441a3c4f6c753d21beda006bfd5fb335b29b0a301bb7ada397f62e3c295319096812136dda2fe1400
6
+ metadata.gz: af839401db81b131b4bdd0a7f45d401f3cb796240dc8b256647f8073386dfc84093ab403d1d1adc31a5cb451e0ae67e6417c13b2beb19bb989ca959d4c683c3b
7
+ data.tar.gz: eb51a6604b6539d11c164113557718ac2f028b636f283ee8293477416a3f4d88bbe038db5884bcf8bc070664614a0a1bfa26c053564313bdbc74608d57c066bc
data/lib/dory/dnsmasq.rb CHANGED
@@ -8,22 +8,45 @@ module Dory
8
8
  # I really hate these globals. It would be great to refactor these out
9
9
  #
10
10
  @@first_attempt_failed = false
11
- @@handle_systemd_services = false
11
+ @@handle_systemd_services = []
12
12
 
13
13
  def self.dnsmasq_image_name
14
14
  'freedomben/dory-dnsmasq:1.1.0'
15
15
  end
16
16
 
17
+ def self.first_attempt_failed?
18
+ @@first_attempt_failed ||= false if @first_attempt_failed.nil?
19
+ @@first_attempt_failed
20
+ end
21
+
22
+ def self.set_first_attempt_failed(failed)
23
+ @@first_attempt_failed = failed
24
+ end
25
+
26
+ def self.systemd_services?
27
+ return false unless self.systemd_services
28
+ self.systemd_services.count > 0
29
+ end
30
+
31
+ def self.systemd_services
32
+ @@systemd_services ||= []
33
+ @@systemd_services
34
+ end
35
+
36
+ def self.set_systemd_services(services)
37
+ @@systemd_services = services
38
+ end
39
+
17
40
  def self.run_preconditions
18
41
  puts "[DEBUG] dnsmasq service running preconditions" if Dory::Config.debug?
19
42
 
20
43
  # we don't want to hassle the user with checking the port unless necessary
21
- if @@first_attempt_failed
22
- @@handle_systemd_services = self.has_systemd? && self.has_services_that_block_dnsmasq?
23
- self.down_systemd_services if @@handle_systemd_services
44
+ if first_attempt_failed?
45
+ self.set_systemd_services(self.running_services_that_block_dnsmasq)
46
+ self.down_systemd_services if self.systemd_services?
24
47
 
25
48
  puts "[DEBUG] First attempt failed. Checking port #{self.port}" if Dory::Config.debug?
26
- listener_list = self.check_port(self.port)
49
+ listener_list = Dory::PortUtils.check_port(self.port)
27
50
  unless listener_list.empty?
28
51
  return self.offer_to_kill(listener_list)
29
52
  end
@@ -37,13 +60,13 @@ module Dory
37
60
 
38
61
  def self.run_postconditions
39
62
  puts "[DEBUG] dnsmasq service running postconditions" if Dory::Config.debug?
40
- self.up_systemd_services if @@handle_systemd_services
63
+ self.up_systemd_services if self.systemd_services?
41
64
  end
42
65
 
43
- def self.handle_error(command_output)
66
+ def self.handle_error(_command_output)
44
67
  puts "[DEBUG] handling dnsmasq start error" if Dory::Config.debug?
45
68
  # If we've already tried to handle failure, prevent infinite recursion
46
- if @@first_attempt_failed
69
+ if first_attempt_failed?
47
70
  puts "[DEBUG] Attempt to kill conflicting service failed" if Dory::Config.debug?
48
71
  return false
49
72
  else
@@ -51,7 +74,7 @@ module Dory
51
74
  puts "[DEBUG] First attempt to start dnsmasq failed." \
52
75
  "There is probably a conflicting service present"
53
76
  end
54
- @@first_attempt_failed = true
77
+ set_first_attempt_failed(true)
55
78
  self.start(handle_error: false)
56
79
  end
57
80
  end
@@ -101,36 +124,13 @@ module Dory
101
124
  end
102
125
  end
103
126
 
104
- def self.run_command(domains = self.domains)
127
+ def self.run_command
105
128
  "docker run -d -p #{self.port}:#{self.port}/tcp -p #{self.port}:#{self.port}/udp " \
106
129
  "--name=#{Shellwords.escape(self.container_name)} " \
107
130
  "--cap-add=NET_ADMIN #{Shellwords.escape(self.dnsmasq_image_name)} " \
108
131
  "#{self.domain_addr_arg_string}"
109
132
  end
110
133
 
111
- def self.check_port(port_num)
112
- puts "Requesting sudo to check if something is bound to port #{self.port}".green
113
- ret = Sh.run_command("sudo lsof -i :#{self.port}")
114
- return [] unless ret.success?
115
-
116
- list = ret.stdout.split("\n")
117
- list.shift # get rid of the column headers
118
- list.map! do |process|
119
- command, pid, user, fd, type, device, size, node, name = process.split(/\s+/)
120
- OpenStruct.new({
121
- command: command,
122
- pid: pid,
123
- user: user,
124
- fd: fd,
125
- type: type,
126
- device: device,
127
- size: size,
128
- node: node,
129
- name: name
130
- })
131
- end
132
- end
133
-
134
134
  def self.offer_to_kill(listener_list, answer: nil)
135
135
  listener_list.each do |process|
136
136
  puts "Process '#{process.command}' with PID '#{process.pid}' is listening on #{process.node} port #{self.port}.".yellow
@@ -149,14 +149,6 @@ module Dory
149
149
  end
150
150
  end
151
151
 
152
- def self.has_systemd?
153
- Sh.run_command('which systemctl').success?
154
- end
155
-
156
- def self.systemd_service_installed?(service)
157
- !(Sh.run_command("systemctl status #{service} | head -1").stdout =~ /unit.*not.*found/i)
158
- end
159
-
160
152
  def self.services_that_block_dnsmasq
161
153
  %w[
162
154
  NetworkManager.service
@@ -165,23 +157,22 @@ module Dory
165
157
  end
166
158
 
167
159
  def self.has_services_that_block_dnsmasq?
168
- !self.enabled_services_that_block_dnsmasq.empty?
160
+ !self.running_services_that_block_dnsmasq.empty?
169
161
  end
170
162
 
171
- def self.enabled_services_that_block_dnsmasq
163
+ def self.running_services_that_block_dnsmasq
172
164
  self.services_that_block_dnsmasq.select do |service|
173
- self.systemd_service_installed?(service)
165
+ Dory::Systemd.systemd_service_running?(service)
174
166
  end
175
167
  end
176
168
 
177
169
  def self.down_systemd_services
178
170
  puts "[DEBUG] Putting systemd services down" if Dory::Config.debug?
179
171
 
180
- services = self.enabled_services_that_block_dnsmasq
181
172
  conf = if ask_about_killing?
182
173
  puts "You have some systemd services running that will race against us \n" \
183
174
  "to bind to port 53 (and usually they win):".yellow
184
- puts "\n #{services.join(', ')}\n".yellow
175
+ puts "\n #{self.systemd_services.join(', ')}\n".yellow
185
176
  puts "If we don't stop these services temporarily while putting up the \n" \
186
177
  "dnsmasq container, starting it will likely fail.".yellow
187
178
  print "Would you like me to put them down while we start dns \n" \
@@ -190,42 +181,35 @@ module Dory
190
181
  else
191
182
  answer_from_settings
192
183
  end
193
- @@handle_systemd_services = conf =~ /y/i
194
- if @@handle_systemd_services
195
- if services.all? { |service|
196
- self.set_systemd_service(service: service, up: false)
184
+ if conf =~ /y/i
185
+ if self.systemd_services.all? { |service|
186
+ Dory::Systemd.set_systemd_service(service: service, up: false)
197
187
  }
198
188
  puts "Putting down services succeeded".green
199
189
  else
200
- puts "One or more services failed to go down".red
190
+ puts "One or more services failed to stop".red
201
191
  end
202
192
  else
203
193
  puts 'OK, not putting down the services'.yellow
194
+ set_systemd_services([])
204
195
  end
205
196
  end
206
197
 
207
198
  def self.up_systemd_services
208
- if @@handle_systemd_services
209
- puts "[DEBUG] Putting systemd services back up" if Dory::Config.debug?
210
- services = self.enabled_services_that_block_dnsmasq
211
- if services.reverse.all? { |service|
212
- self.set_systemd_service(service: service, up: true)
199
+ if self.systemd_services?
200
+ puts "[DEBUG] Putting systemd services back up: #{self.systemd_services.join(', ')}" if Dory::Config.debug?
201
+ if self.systemd_services.reverse.all? { |service|
202
+ Dory::Systemd.set_systemd_service(service: service, up: true)
213
203
  }
214
- puts "#{services.join(', ')} were successfully restarted".green
204
+ puts "#{self.systemd_services.join(', ')} were successfully restarted".green
215
205
  else
216
- puts "#{services.join(', ')} failed to restart".red
206
+ puts "#{self.systemd_services.join(', ')} failed to restart".red
217
207
  end
218
208
  else
219
- puts "[DEBUG] Not putting systemd services back up cause skipped " if Dory::Config.debug?
209
+ puts "[DEBUG] Not putting systemd services back up cause array was empty " if Dory::Config.debug?
220
210
  end
221
211
  end
222
212
 
223
- def self.set_systemd_service(service:, up:)
224
- action = up ? 'start' : 'stop'
225
- puts "Requesting sudo to #{action} #{service}".green
226
- Sh.run_command("sudo systemctl #{action} #{service}").success?
227
- end
228
-
229
213
  def self.ask_about_killing?
230
214
  !self.answer_from_settings
231
215
  end
@@ -21,7 +21,7 @@ module Dory
21
21
  return true
22
22
  end
23
23
 
24
- def handle_error(command_output)
24
+ def handle_error(_command_output)
25
25
  # Override to provide error handling
26
26
  return false
27
27
  end
@@ -0,0 +1,28 @@
1
+ require_relative 'docker_service'
2
+
3
+ module Dory
4
+ module PortUtils
5
+ def self.check_port(port_num = self.port)
6
+ puts "Requesting sudo to check if something is bound to port #{port_num}".green
7
+ ret = Dory::Sh.run_command("sudo lsof -i :#{port_num}")
8
+ return [] unless ret.success?
9
+
10
+ list = ret.stdout.split("\n")
11
+ list.shift # get rid of the column headers
12
+ list.map! do |process|
13
+ command, pid, user, fd, type, device, size, node, name = process.split(/\s+/)
14
+ OpenStruct.new({
15
+ command: command,
16
+ pid: pid,
17
+ user: user,
18
+ fd: fd,
19
+ type: type,
20
+ device: device,
21
+ size: size,
22
+ node: node,
23
+ name: name
24
+ })
25
+ end
26
+ end
27
+ end
28
+ end
data/lib/dory/proxy.rb CHANGED
@@ -31,7 +31,7 @@ module Dory
31
31
  def self.tls_arg
32
32
  if [:tls_enabled, :ssl_enabled, :https_enabled].any? { |s|
33
33
  Dory::Config.settings[:dory][:nginx_proxy][s]
34
- }
34
+ }
35
35
  "-p 443:443"
36
36
  else
37
37
  ''
@@ -0,0 +1,30 @@
1
+ require_relative 'docker_service'
2
+
3
+ module Dory
4
+ module Systemd
5
+ def self.has_systemd?
6
+ Sh.run_command('which systemctl').success?
7
+ end
8
+
9
+ def self.systemd_service_installed?(service)
10
+ return false unless self.has_systemd?
11
+ !(Sh.run_command("systemctl status #{service} | head -1").stdout =~ /not-found/)
12
+ end
13
+
14
+ def self.systemd_service_running?(service)
15
+ return false unless self.has_systemd?
16
+ !!(Sh.run_command("systemctl status #{service} | head -3").stdout =~ /Active:\s+active.*running/)
17
+ end
18
+
19
+ def self.systemd_service_enabled?(service)
20
+ return false unless self.has_systemd?
21
+ !!(Sh.run_command("systemctl status #{service} | head -3").stdout.gsub(/Loaded.*?;/, '') =~ /^\s*enabled;/)
22
+ end
23
+
24
+ def self.set_systemd_service(service:, up:)
25
+ action = up ? 'start' : 'stop'
26
+ puts "Requesting sudo to #{action} #{service}".green
27
+ Sh.run_command("sudo systemctl #{action} #{service}").success?
28
+ end
29
+ end
30
+ end
data/lib/dory/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Dory
2
- VERSION = '0.5.0'
3
- DATE = '2016-02-13'
2
+ VERSION = '0.5.1'
3
+ DATE = '2016-02-15'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Porter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-13 00:00:00.000000000 Z
11
+ date: 2016-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0.6'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.47'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.47'
125
139
  description: 'Dory lets you forget about IP addresses and port numbers while you are
126
140
  developing your application. Through the magic of local DNS and a reverse proxy,
127
141
  you can access your app at the domain of your choosing. For example, http://myapp.docker
@@ -140,11 +154,13 @@ files:
140
154
  - lib/dory/dnsmasq.rb
141
155
  - lib/dory/docker_service.rb
142
156
  - lib/dory/os.rb
157
+ - lib/dory/port_utils.rb
143
158
  - lib/dory/proxy.rb
144
159
  - lib/dory/resolv.rb
145
160
  - lib/dory/resolv/linux.rb
146
161
  - lib/dory/resolv/macos.rb
147
162
  - lib/dory/shell.rb
163
+ - lib/dory/systemd.rb
148
164
  - lib/dory/upgrade.rb
149
165
  - lib/dory/version.rb
150
166
  homepage: https://github.com/FreedomBen/dory
@@ -167,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
183
  version: '0'
168
184
  requirements: []
169
185
  rubyforge_project:
170
- rubygems_version: 2.5.2
186
+ rubygems_version: 2.2.5
171
187
  signing_key:
172
188
  specification_version: 4
173
189
  summary: Your development proxy for Docker