dory 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dory/dnsmasq.rb +73 -1
- data/lib/dory/docker_service.rb +22 -9
- data/lib/dory/proxy.rb +1 -1
- data/lib/dory/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b636e5e451b94e93e9ef2ce598f7b41af8e49463
|
4
|
+
data.tar.gz: 4513ecc2eace13190f46355ff93ec0ca0f9a0b57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12db07585ec03aa4478c969586976c1365595bbbd72dd8dba8dce2daede46aedd96d59b3cff68247a9b1285183e8213d56d71ae4fd0216a63963d9ec9ff078f6
|
7
|
+
data.tar.gz: 4efa86ae20f8bf1ef7386f4ef61891396e6c84016fc68742d843a66513a9c1f491c47cb5a9b932e3771af3ec03e01d3132b764a3e619f09b4cb0617458917ac6
|
data/lib/dory/dnsmasq.rb
CHANGED
@@ -4,6 +4,38 @@ module Dory
|
|
4
4
|
class Dnsmasq
|
5
5
|
extend Dory::DockerService
|
6
6
|
|
7
|
+
@@first_attempt_failed = false
|
8
|
+
|
9
|
+
def self.run_preconditions
|
10
|
+
puts "[DEBUG] dnsmasq service running preconditions" if Dory::Config.debug?
|
11
|
+
|
12
|
+
# we don't want to hassle the user with checking the port unless necessary
|
13
|
+
if @@first_attempt_failed
|
14
|
+
puts "[DEBUG] First attempt failed. Checking port 53" if Dory::Config.debug?
|
15
|
+
listener_list = self.check_port(53)
|
16
|
+
unless listener_list.empty?
|
17
|
+
return self.offer_to_kill(listener_list)
|
18
|
+
end
|
19
|
+
return false
|
20
|
+
else
|
21
|
+
puts "[DEBUG] Skipping preconditions on first run" if Dory::Config.debug?
|
22
|
+
return true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.handle_error(command_output)
|
27
|
+
puts "[DEBUG] handling dnsmasq start error" if Dory::Config.debug?
|
28
|
+
# If we've already tried to handle failure, prevent infinite recursion
|
29
|
+
if @@first_attempt_failed
|
30
|
+
puts "[DEBUG] Attempt to kill conflicting service failed" if Dory::Config.debug?
|
31
|
+
return false
|
32
|
+
else
|
33
|
+
puts "[DEBUG] First attempt to start dnsmasq failed. There is probably a conflicting service present" if Dory::Config.debug?
|
34
|
+
@@first_attempt_failed = true
|
35
|
+
self.start(handle_error: false)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
7
39
|
def self.dnsmasq_image_name
|
8
40
|
'freedomben/dory-dnsmasq'
|
9
41
|
end
|
@@ -20,10 +52,50 @@ module Dory
|
|
20
52
|
Dory::Config.settings[:dory][:dnsmasq][:address]
|
21
53
|
end
|
22
54
|
|
23
|
-
def self.
|
55
|
+
def self.run_command(domain = self.domain, addr = self.addr)
|
24
56
|
"docker run -d -p 53:53/tcp -p 53:53/udp --name=#{Shellwords.escape(self.container_name)} " \
|
25
57
|
"--cap-add=NET_ADMIN #{Shellwords.escape(self.dnsmasq_image_name)} " \
|
26
58
|
"#{Shellwords.escape(domain)} #{Shellwords.escape(addr)}"
|
27
59
|
end
|
60
|
+
|
61
|
+
def self.check_port(port_num)
|
62
|
+
puts "Requesting sudo to check if something is bound to port 53".green
|
63
|
+
ret = Sh.run_command('sudo lsof -i :53')
|
64
|
+
return [] unless ret.success?
|
65
|
+
|
66
|
+
list = ret.stdout.split("\n")
|
67
|
+
list.shift # get rid of the column headers
|
68
|
+
list.map! do |process|
|
69
|
+
command, pid, user, fd, type, device, size, node, name = process.split(/\s+/)
|
70
|
+
OpenStruct.new({
|
71
|
+
command: command,
|
72
|
+
pid: pid,
|
73
|
+
user: user,
|
74
|
+
fd: fd,
|
75
|
+
type: type,
|
76
|
+
device: device,
|
77
|
+
size: size,
|
78
|
+
node: node,
|
79
|
+
name: name
|
80
|
+
})
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.offer_to_kill(listener_list, answer: nil)
|
85
|
+
listener_list.each do |process|
|
86
|
+
puts "Process '#{process.command}' with PID '#{process.pid}' is listening on #{process.node} port 53."
|
87
|
+
end
|
88
|
+
pids = listener_list.uniq(&:pid).map(&:pid)
|
89
|
+
pidstr = pids.join(' and ')
|
90
|
+
print "This interferes with Dory's dnsmasq container. Would you like me to kill PID #{pidstr}? (Y/N): "
|
91
|
+
conf = answer ? answer : STDIN.gets.chomp
|
92
|
+
if conf =~ /y/i
|
93
|
+
puts "Requesting sudo to kill PID #{pidstr}"
|
94
|
+
return Sh.run_command("sudo kill #{pids.join(' ')}").success?
|
95
|
+
else
|
96
|
+
puts "OK, not killing PID #{pidstr}. Please kill manually and try starting dory again.".red
|
97
|
+
return false
|
98
|
+
end
|
99
|
+
end
|
28
100
|
end
|
29
101
|
end
|
data/lib/dory/docker_service.rb
CHANGED
@@ -2,25 +2,38 @@ require 'shellwords'
|
|
2
2
|
|
3
3
|
module Dory
|
4
4
|
module DockerService
|
5
|
-
def
|
5
|
+
def run_preconditions
|
6
|
+
# Override if preconditions are needed
|
7
|
+
return true
|
8
|
+
end
|
9
|
+
|
10
|
+
def handle_error(command_output)
|
11
|
+
# Override to provide error handling
|
12
|
+
return false
|
13
|
+
end
|
14
|
+
|
15
|
+
def start(handle_error: true)
|
6
16
|
unless self.running?
|
7
|
-
|
17
|
+
self.run_preconditions
|
18
|
+
status = if self.container_exists?
|
8
19
|
if Dory::Config.debug?
|
9
20
|
puts "[DEBUG] Container '#{self.container_name}' already exists. " \
|
10
21
|
"Starting with '#{self.start_cmd}'"
|
11
22
|
end
|
12
|
-
Sh.run_command(self.start_cmd)
|
23
|
+
Sh.run_command(self.start_cmd)
|
13
24
|
else
|
14
25
|
if Dory::Config.debug?
|
15
26
|
puts "[DEBUG] Container '#{self.container_name}' does not exist. " \
|
16
|
-
"Creating/starting with '#{self.
|
27
|
+
"Creating/starting with '#{self.run_command}'"
|
17
28
|
end
|
18
|
-
Sh.run_command(self.
|
29
|
+
Sh.run_command(self.run_command)
|
19
30
|
end
|
20
|
-
unless success
|
21
|
-
|
22
|
-
|
23
|
-
|
31
|
+
unless status.success?
|
32
|
+
if !handle_error || !self.handle_error(status)
|
33
|
+
raise RuntimeError.new(
|
34
|
+
"Failed to run #{self.container_name}. Command #{self.run_command} failed"
|
35
|
+
)
|
36
|
+
end
|
24
37
|
end
|
25
38
|
end
|
26
39
|
self.running?
|
data/lib/dory/proxy.rb
CHANGED
@@ -33,7 +33,7 @@ module Dory
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def self.
|
36
|
+
def self.run_command
|
37
37
|
"docker run -d -p 80:80 #{self.tls_arg} #{self.certs_arg} "\
|
38
38
|
"-v /var/run/docker.sock:/tmp/docker.sock -e " \
|
39
39
|
"'CONTAINER_NAME=#{Shellwords.escape(self.container_name)}' --name " \
|
data/lib/dory/version.rb
CHANGED
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.0
|
4
|
+
version: 0.1.0
|
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-
|
11
|
+
date: 2016-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|