pygmy 0.9.3 → 0.9.4
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 +4 -4
- data/bin/pygmy +31 -20
- data/lib/pygmy/docker_service.rb +1 -1
- data/lib/pygmy/haproxy.rb +1 -1
- data/lib/pygmy/resolv.rb +14 -2
- data/lib/pygmy/resolv_osx.rb +52 -0
- data/lib/pygmy/ssh_agent.rb +1 -1
- data/lib/pygmy/ssh_agent_add_key.rb +9 -0
- data/lib/pygmy/version.rb +1 -1
- metadata +2 -2
- data/lib/pygmy/inst_vars_to_hash.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a01f3f5b33da9753d56df7bb251645e1cf0cc961
|
4
|
+
data.tar.gz: a9e466393f6eaeb238e55f6ee9716dd01e7dd6f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1902a2367c478394ef2b162aace8a8a5dc2c36a0e1ca20c4e46b066949742ee5b34e7e5f5e6924efe2018ba249a3ee0b9b4c65840b5aba6daab54fa001d119e5
|
7
|
+
data.tar.gz: c032329491620456068a6fa59f127b325963dcb60d323626ec5662e4e153d3c385a3aea1a632997c9e02ae4d5fe33acc5f09e317cabe7c8dff49d490312743b3
|
data/bin/pygmy
CHANGED
@@ -30,16 +30,26 @@ class PygmyBin < Thor
|
|
30
30
|
exec_up(options)
|
31
31
|
end
|
32
32
|
|
33
|
-
desc '
|
33
|
+
desc 'stop', 'Stop all pygmy services'
|
34
34
|
long_desc <<-LONGDESC
|
35
35
|
Stops all pygmy services. Can optionally pass [-d|--destroy]
|
36
36
|
to destroy the containers when they stop.
|
37
37
|
|
38
|
-
> $ pygmy
|
38
|
+
> $ pygmy stop [-d|--destroy]
|
39
|
+
LONGDESC
|
40
|
+
option :destroy, type: :boolean, aliases: '-d', default: false
|
41
|
+
def stop
|
42
|
+
exec_stop(options)
|
43
|
+
end
|
44
|
+
|
45
|
+
desc 'down', 'Stop and destroy all pygmy services'
|
46
|
+
long_desc <<-LONGDESC
|
47
|
+
Stops all pygmy services and destroy the containers when they stop.
|
48
|
+
|
49
|
+
> $ pygmy down
|
39
50
|
LONGDESC
|
40
|
-
option :destroy, type: :boolean, aliases: 'd', default: false
|
41
51
|
def down
|
42
|
-
|
52
|
+
exec_stop({:destroy => true})
|
43
53
|
end
|
44
54
|
|
45
55
|
desc 'addkey [~/.ssh/id_rsa]', 'Add additional ssh-key'
|
@@ -61,13 +71,13 @@ class PygmyBin < Thor
|
|
61
71
|
|
62
72
|
desc 'restart', 'Stop and restart all pygmy services'
|
63
73
|
long_desc <<-LONGDESC
|
64
|
-
Stop and restart pygmy services (dnsmasq, resolv)
|
74
|
+
Stop and restart pygmy services (dnsmasq, resolv, haproxy, ssh-agent)
|
65
75
|
|
66
76
|
> $ pygmy restart [-d|--destroy]
|
67
77
|
LONGDESC
|
68
|
-
option :destroy, type: :boolean, aliases: 'd', default: false
|
78
|
+
option :destroy, type: :boolean, aliases: '-d', default: false
|
69
79
|
def restart
|
70
|
-
|
80
|
+
exec_stop(options)
|
71
81
|
exec_up(options)
|
72
82
|
end
|
73
83
|
|
@@ -126,23 +136,25 @@ class PygmyBin < Thor
|
|
126
136
|
puts "[*] Dnsmasq is not running".red
|
127
137
|
end
|
128
138
|
|
129
|
-
if Pygmy::
|
130
|
-
puts "[*]
|
139
|
+
if Pygmy::Haproxy.running?
|
140
|
+
puts "[*] Haproxy: Running as docker container #{Pygmy::Haproxy.container_name}".green
|
131
141
|
else
|
132
|
-
puts "[*]
|
142
|
+
puts "[*] Haproxy is not running".red
|
133
143
|
end
|
134
144
|
|
135
|
-
if Pygmy::
|
136
|
-
puts "[*]
|
145
|
+
if Pygmy::Resolv.has_our_nameserver?
|
146
|
+
puts "[*] Resolv is properly configured".green
|
137
147
|
else
|
138
|
-
puts "[*]
|
148
|
+
puts "[*] Resolv is not configured".red
|
139
149
|
end
|
140
150
|
|
141
|
-
if Pygmy::
|
142
|
-
puts "[*]
|
151
|
+
if Pygmy::SshAgent.running?
|
152
|
+
puts "[*] ssh-agent: Running as docker container #{Pygmy::SshAgent.container_name}, loaded keys:".green
|
153
|
+
Pygmy::SshAgentAddKey.show_ssh_keys
|
143
154
|
else
|
144
|
-
puts "[*]
|
155
|
+
puts "[*] ssh-agent is not running".red
|
145
156
|
end
|
157
|
+
|
146
158
|
end
|
147
159
|
|
148
160
|
|
@@ -160,11 +172,11 @@ class PygmyBin < Thor
|
|
160
172
|
|
161
173
|
end
|
162
174
|
|
163
|
-
def
|
175
|
+
def exec_stop(options)
|
164
176
|
if Pygmy::Resolv.clean
|
165
|
-
puts "
|
177
|
+
puts "Resolver removed".green
|
166
178
|
else
|
167
|
-
puts "Unable to remove
|
179
|
+
puts "Unable to remove resolver".red
|
168
180
|
end
|
169
181
|
|
170
182
|
if Pygmy::Dnsmasq.stop
|
@@ -211,7 +223,6 @@ end
|
|
211
223
|
|
212
224
|
aliases = {
|
213
225
|
'start' => 'up',
|
214
|
-
'stop' => 'down',
|
215
226
|
}
|
216
227
|
|
217
228
|
if !ARGV.empty? && %w[-v --version].include?(ARGV.first)
|
data/lib/pygmy/docker_service.rb
CHANGED
@@ -41,7 +41,7 @@ module Pygmy
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def stop(container_name = self.container_name)
|
44
|
-
Sh.run_command("docker
|
44
|
+
Sh.run_command("docker stop -t 1 #{Shellwords.escape(container_name)}") if self.running?
|
45
45
|
!self.running?
|
46
46
|
end
|
47
47
|
|
data/lib/pygmy/haproxy.rb
CHANGED
data/lib/pygmy/resolv.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'colorize'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'pathname'
|
2
4
|
|
3
5
|
module Pygmy
|
4
6
|
module Resolv
|
@@ -13,7 +15,7 @@ module Pygmy
|
|
13
15
|
end
|
14
16
|
|
15
17
|
def self.file_comment
|
16
|
-
'# added by pygmy'
|
18
|
+
'# added by amazee.io pygmy'
|
17
19
|
end
|
18
20
|
|
19
21
|
def self.nameserver
|
@@ -30,7 +32,7 @@ module Pygmy
|
|
30
32
|
|
31
33
|
def self.resolv_file
|
32
34
|
if Linux.ubuntu?
|
33
|
-
return self.ubuntu_resolv_file
|
35
|
+
return self.ubuntu_resolv_file
|
34
36
|
elsif Linux.fedora? || Linux.arch? || File.exist?(self.common_resolv_file)
|
35
37
|
return self.common_resolv_file
|
36
38
|
else
|
@@ -40,7 +42,11 @@ module Pygmy
|
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
45
|
+
|
43
46
|
def self.configure
|
47
|
+
if Linux.osx?
|
48
|
+
return ResolvOsx.create_resolver?
|
49
|
+
end
|
44
50
|
# we want to be the first nameserver in the list for performance reasons
|
45
51
|
# we only want to add the nameserver if it isn't already there
|
46
52
|
prev_conts = self.resolv_file_contents
|
@@ -57,6 +63,9 @@ module Pygmy
|
|
57
63
|
end
|
58
64
|
|
59
65
|
def self.clean
|
66
|
+
if Linux.osx?
|
67
|
+
return ResolvOsx.clean?
|
68
|
+
end
|
60
69
|
prev_conts = self.resolv_file_contents
|
61
70
|
if self.contents_has_our_nameserver?(prev_conts)
|
62
71
|
prev_conts.gsub!(/#{Regexp.escape(self.nameserver_contents + "\n")}/, '')
|
@@ -77,6 +86,9 @@ module Pygmy
|
|
77
86
|
end
|
78
87
|
|
79
88
|
def self.has_our_nameserver?
|
89
|
+
if Linux.osx?
|
90
|
+
return ResolvOsx.resolver_file_exists?
|
91
|
+
end
|
80
92
|
self.contents_has_our_nameserver?(self.resolv_file_contents)
|
81
93
|
end
|
82
94
|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
module Pygmy
|
6
|
+
module ResolvOsx
|
7
|
+
def self.resolver_dir
|
8
|
+
Pathname("/etc/resolver")
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.resolver_file
|
12
|
+
"/etc/resolver/docker.amazee.io"
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.create_resolver?
|
16
|
+
puts "setting up DNS resolution, this may require sudo".green
|
17
|
+
unless self.resolver_dir.directory?
|
18
|
+
self.system!("creating #{self.resolver_dir}", "sudo", "mkdir", "-p", self.resolver_dir)
|
19
|
+
end
|
20
|
+
Tempfile.open('amazeeio_pygmy-dnsmasq') do |f|
|
21
|
+
f.write(self.resolver_contents)
|
22
|
+
f.close
|
23
|
+
self.system!("creating #{self.resolver_file}", "sudo", "cp", f.path, self.resolver_file)
|
24
|
+
self.system!("creating #{self.resolver_file}", "sudo", "chmod", "644", self.resolver_file)
|
25
|
+
end
|
26
|
+
self.system!("restarting mDNSResponder", "sudo", "killall", "mDNSResponder")
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.clean?
|
30
|
+
self.system!("removing resolverfile", "sudo", "rm", "-f", self.resolver_file)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.system!(step, *args)
|
34
|
+
system(*args.map(&:to_s)) || raise("Error with the #{name} daemon during #{step}")
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.resolver_contents; <<-EOS.gsub(/^ /, '')
|
38
|
+
# Generated by amazeeio pygmy
|
39
|
+
nameserver 127.0.0.1
|
40
|
+
port 53
|
41
|
+
EOS
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.resolver_file_contents
|
45
|
+
File.read(self.resolver_file) unless !File.file?(self.resolver_file)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.resolver_file_exists?
|
49
|
+
(self.resolver_file_contents == self.resolver_contents)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/pygmy/ssh_agent.rb
CHANGED
@@ -18,8 +18,17 @@ module Pygmy
|
|
18
18
|
"ssh-add #{key}")
|
19
19
|
else
|
20
20
|
puts "ssh key: #{key}, does not exist, ignoring...".yellow
|
21
|
+
return false
|
21
22
|
end
|
23
|
+
end
|
22
24
|
|
25
|
+
def self.show_ssh_keys
|
26
|
+
system("docker run --rm -it " \
|
27
|
+
"--volumes-from=amazeeio-ssh-agent " \
|
28
|
+
"--name=#{Shellwords.escape(self.container_name)} " \
|
29
|
+
"#{Shellwords.escape(self.image_name)} " \
|
30
|
+
"ssh-add -l")
|
23
31
|
end
|
32
|
+
|
24
33
|
end
|
25
34
|
end
|
data/lib/pygmy/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pygmy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Schmid
|
@@ -125,9 +125,9 @@ files:
|
|
125
125
|
- lib/pygmy/dnsmasq.rb
|
126
126
|
- lib/pygmy/docker_service.rb
|
127
127
|
- lib/pygmy/haproxy.rb
|
128
|
-
- lib/pygmy/inst_vars_to_hash.rb
|
129
128
|
- lib/pygmy/linux.rb
|
130
129
|
- lib/pygmy/resolv.rb
|
130
|
+
- lib/pygmy/resolv_osx.rb
|
131
131
|
- lib/pygmy/shell.rb
|
132
132
|
- lib/pygmy/ssh_agent.rb
|
133
133
|
- lib/pygmy/ssh_agent_add_key.rb
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module InstVarsToHash
|
2
|
-
def to_s
|
3
|
-
to_h.to_s
|
4
|
-
end
|
5
|
-
|
6
|
-
def to_h
|
7
|
-
retval = {}
|
8
|
-
instance_variables.each do |iv|
|
9
|
-
retval[iv.to_s.delete('@').to_sym] = elem_to_h(instance_variable_get(iv))
|
10
|
-
end
|
11
|
-
retval
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def expandable_classes
|
17
|
-
[ InstVarsToHash ]
|
18
|
-
end
|
19
|
-
|
20
|
-
def expandable_to_hash(klass)
|
21
|
-
expandable_classes.any?{ |k| klass == k || klass < k }
|
22
|
-
end
|
23
|
-
|
24
|
-
def elem_to_h(elem)
|
25
|
-
if elem.class == Array
|
26
|
-
elem.map { |el| elem_to_h(el) }
|
27
|
-
elsif expandable_to_hash(elem.class)
|
28
|
-
elem.to_h
|
29
|
-
else
|
30
|
-
elem
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|