dory 0.3.11 → 0.4.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/dinghy.rb +29 -0
- data/lib/dory/dnsmasq.rb +15 -4
- data/lib/dory/docker_service.rb +14 -9
- data/lib/dory/resolv/macos.rb +17 -2
- data/lib/dory/version.rb +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 065982a17c11138746bc3cf24270e3d047b0c16a
|
4
|
+
data.tar.gz: 7985ebfd3972c8661ca99385ef47eebc2b6d0885
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b08b713daa9363fbb32ff43efbbfecfc786cc26adc57a0bdd442a4117735cc67c6fafab4d1be41257e4b9594b74e784fe816d42a9b2131de2f9519cfa8573050
|
7
|
+
data.tar.gz: 9f0aff75f6c853d976632bd0c25baf0513739e0443d7279d57b0c7e0f8a06d54d35f9f68b9990b2d29500a776dc53bcdcb7870d58204d182f48c10f240ed1501
|
data/lib/dory/dinghy.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
|
3
|
+
module Dory
|
4
|
+
module Dinghy
|
5
|
+
class DinghyError < RuntimeError
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.installed?
|
9
|
+
Bash.run_command("which dinghy >/dev/null 2>&1").success?
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.ip
|
13
|
+
res = Bash.run_command("dinghy ip").stdout.chomp
|
14
|
+
unless res =~ /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/
|
15
|
+
raise DinghyError.new(<<-ERROR)
|
16
|
+
Dinghy responded with: '#{res}', but we expected an IP address.
|
17
|
+
Please make sure the dinghy vm is running, and that running
|
18
|
+
`dinghy ip` gives you an IP address
|
19
|
+
ERROR
|
20
|
+
end
|
21
|
+
res
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.match?(str)
|
25
|
+
# be lenient cause I typo this all the time
|
26
|
+
str =~ /^:?din.?.?y:?/
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/dory/dnsmasq.rb
CHANGED
@@ -30,8 +30,10 @@ module Dory
|
|
30
30
|
def self.handle_error(command_output)
|
31
31
|
puts "[DEBUG] handling dnsmasq start error" if Dory::Config.debug?
|
32
32
|
# If we've already tried to handle failure, prevent infinite recursion
|
33
|
-
if @@first_attempt_failed
|
34
|
-
|
33
|
+
if @@first_attempt_failed || !Dory::Dinghy.installed?
|
34
|
+
if Dory::Config.debug?
|
35
|
+
puts "[DEBUG] Attempt to kill conflicting service failed" if Dory
|
36
|
+
end
|
35
37
|
return false
|
36
38
|
else
|
37
39
|
puts "[DEBUG] First attempt to start dnsmasq failed. There is probably a conflicting service present" if Dory::Config.debug?
|
@@ -40,6 +42,11 @@ module Dory
|
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
45
|
+
def self.ip_from_dinghy?
|
46
|
+
Dory::Dinghy.match?(self.address(self.old_address)) ||
|
47
|
+
self.domains.any?{ |domain| Dory::Dinghy.match?(self.address(domain[:address])) }
|
48
|
+
end
|
49
|
+
|
43
50
|
def self.port
|
44
51
|
return 53 unless Os.macos?
|
45
52
|
p = Dory::Config.settings[:dory][:dnsmasq][:port]
|
@@ -66,12 +73,16 @@ module Dory
|
|
66
73
|
Dory::Config.settings[:dory][:dnsmasq][:address]
|
67
74
|
end
|
68
75
|
|
76
|
+
def self.address(addr)
|
77
|
+
Dory::Dinghy.match?(addr) ? Dory::Dinghy.ip : addr
|
78
|
+
end
|
79
|
+
|
69
80
|
def self.domain_addr_arg_string
|
70
81
|
if self.old_domain
|
71
|
-
"#{Shellwords.escape(self.old_domain)} #{Shellwords.escape(self.old_address)}"
|
82
|
+
"#{Shellwords.escape(self.old_domain)} #{Shellwords.escape(self.address(self.old_address))}"
|
72
83
|
else
|
73
84
|
self.domains.map do |domain|
|
74
|
-
"#{Shellwords.escape(domain[:domain])} #{Shellwords.escape(domain[:address])}"
|
85
|
+
"#{Shellwords.escape(domain[:domain])} #{Shellwords.escape(self.address(domain[:address]))}"
|
75
86
|
end.join(" ")
|
76
87
|
end
|
77
88
|
end
|
data/lib/dory/docker_service.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'shellwords'
|
2
|
+
require 'ostruct'
|
2
3
|
|
3
4
|
module Dory
|
4
5
|
module DockerService
|
@@ -28,16 +29,20 @@ module Dory
|
|
28
29
|
puts "[DEBUG] Container '#{self.container_name}' exists. Deleting" if Dory::Config.debug?
|
29
30
|
self.delete
|
30
31
|
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
32
|
+
begin
|
33
|
+
if Dory::Config.debug?
|
34
|
+
puts "[DEBUG] '#{self.container_name}' does not exist. Creating/starting " \
|
35
|
+
"'#{self.container_name}' with '#{self.run_command}'"
|
36
|
+
end
|
37
|
+
status = Sh.run_command(self.run_command)
|
38
|
+
unless status.success?
|
39
|
+
if !handle_error || !self.handle_error(status)
|
40
|
+
puts "Failed to start docker container '#{self.container_name}' " \
|
41
|
+
". Command '#{self.run_command}' failed".red
|
42
|
+
end
|
40
43
|
end
|
44
|
+
rescue DinghyError => e
|
45
|
+
puts e.message.red
|
41
46
|
end
|
42
47
|
else
|
43
48
|
err_msg = "Docker does not appear to be installed /o\\\n" \
|
data/lib/dory/resolv/macos.rb
CHANGED
@@ -30,8 +30,13 @@ module Dory
|
|
30
30
|
self.resolv_file_names.map{ |f| "#{self.resolv_dir}/#{f}" }
|
31
31
|
end
|
32
32
|
|
33
|
+
def self.configured_to_use_dinghy
|
34
|
+
Dory::Dinghy.match?(Dory::Config.settings[:dory][:resolv][:nameserver])
|
35
|
+
end
|
36
|
+
|
33
37
|
def self.nameserver
|
34
|
-
Dory::Config.settings[:dory][:resolv][:nameserver]
|
38
|
+
ns = Dory::Config.settings[:dory][:resolv][:nameserver]
|
39
|
+
Dory::Dinghy.match?(ns) ? Dory::Dinghy.ip : ns
|
35
40
|
end
|
36
41
|
|
37
42
|
def self.file_nameserver_line
|
@@ -60,6 +65,9 @@ module Dory
|
|
60
65
|
puts "Requesting sudo to write to #{filename}".green
|
61
66
|
Bash.run_command("echo -e '#{self.resolv_contents}' | sudo tee #{Shellwords.escape(filename)} >/dev/null")
|
62
67
|
end
|
68
|
+
rescue DinghyError => e
|
69
|
+
puts e.message.red
|
70
|
+
false
|
63
71
|
end
|
64
72
|
|
65
73
|
def self.clean
|
@@ -88,7 +96,14 @@ module Dory
|
|
88
96
|
end
|
89
97
|
|
90
98
|
def self.contents_has_our_nameserver?(contents)
|
91
|
-
|
99
|
+
comment_match = contents =~ /#{self.file_comment}/
|
100
|
+
port_match = contents =~ /port.#{self.port}/
|
101
|
+
if configured_to_use_dinghy
|
102
|
+
!!(comment_match && port_match)
|
103
|
+
else
|
104
|
+
nameserver_match = contents =~ /#{self.file_nameserver_line}/
|
105
|
+
!!(comment_match && port_match && nameserver_match)
|
106
|
+
end
|
92
107
|
end
|
93
108
|
end
|
94
109
|
end
|
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.
|
4
|
+
version: 0.4.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-12-
|
11
|
+
date: 2016-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- bin/dory
|
137
137
|
- lib/dory.rb
|
138
138
|
- lib/dory/config.rb
|
139
|
+
- lib/dory/dinghy.rb
|
139
140
|
- lib/dory/dnsmasq.rb
|
140
141
|
- lib/dory/docker_service.rb
|
141
142
|
- lib/dory/os.rb
|