pygmy 0.9.1
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 +7 -0
- data/bin/pygmy +221 -0
- data/lib/pygmy/dnsmasq.rb +28 -0
- data/lib/pygmy/docker_service.rb +60 -0
- data/lib/pygmy/haproxy.rb +24 -0
- data/lib/pygmy/inst_vars_to_hash.rb +33 -0
- data/lib/pygmy/linux.rb +53 -0
- data/lib/pygmy/resolv.rb +87 -0
- data/lib/pygmy/shell.rb +25 -0
- data/lib/pygmy/ssh_agent.rb +22 -0
- data/lib/pygmy/ssh_agent_add_key.rb +20 -0
- data/lib/pygmy/version.rb +4 -0
- data/lib/pygmy.rb +3 -0
- metadata +160 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 2d9ca74d85c1a5306760f436b11560b8dc92b63d
|
|
4
|
+
data.tar.gz: f41bd940449ec83b530da8f060d23f930a0539e1
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b9932499926356627b02ac6b15765284ff380b9443f39c4da672c7b4fb5c213a77e90d243c8e45e0bc2218a75a5990b337bc485cfb26193c11948c092a70f95b
|
|
7
|
+
data.tar.gz: b9028cfc479c86481864b6c7e47a0b6d451e2f5af9b948eb371212cbda25623e0fa91ec01a68a409a5620ef3cbc8ad16dc5217de90f4688d5a5fc971d0ce8031
|
data/bin/pygmy
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'thor'
|
|
4
|
+
require 'yaml'
|
|
5
|
+
|
|
6
|
+
require 'pygmy'
|
|
7
|
+
|
|
8
|
+
class PygmyBin < Thor
|
|
9
|
+
class_option :verbose, type: :boolean, aliases: '-v', default: false
|
|
10
|
+
|
|
11
|
+
desc 'up', 'Bring up pygmy services (dnsmasq, resolv, ssh-agent)'
|
|
12
|
+
long_desc <<-LONGDESC
|
|
13
|
+
Bring up pygmy services (dnsmasq, haproxy, resolv, ssh-agent)
|
|
14
|
+
|
|
15
|
+
When run, there will be two docker containers started:
|
|
16
|
+
|
|
17
|
+
- dnsmasq: to resolve DNS requests for your the domain *.docker.amazee.io
|
|
18
|
+
|
|
19
|
+
- haproxy: to forward HTTP and HTTPs requests to the docker containers running Drupal.
|
|
20
|
+
|
|
21
|
+
- ssh-agent: to keep the ssh-agent at one single place, so that all other docker containers
|
|
22
|
+
can consume the ssh key.
|
|
23
|
+
|
|
24
|
+
Additionally the local resolver (/etc/resolv.conf) will be configured to use the dnsmasq
|
|
25
|
+
instance as a nameserver
|
|
26
|
+
|
|
27
|
+
> $ pygmy up
|
|
28
|
+
LONGDESC
|
|
29
|
+
def up
|
|
30
|
+
exec_up(options)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
desc 'down', 'Stop all pygmy services'
|
|
34
|
+
long_desc <<-LONGDESC
|
|
35
|
+
Stops all pygmy services. Can optionally pass [-d|--destroy]
|
|
36
|
+
to destroy the containers when they stop.
|
|
37
|
+
|
|
38
|
+
> $ pygmy down [-d|--destroy]
|
|
39
|
+
LONGDESC
|
|
40
|
+
option :destroy, type: :boolean, aliases: 'd', default: false
|
|
41
|
+
def down
|
|
42
|
+
exec_down(options)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
desc 'addkey [~/.ssh/id_rsa]', 'Add additional ssh-key'
|
|
46
|
+
long_desc <<-LONGDESC
|
|
47
|
+
Adds an additional ssh key to the ssh-agent.
|
|
48
|
+
Needs the absolute path to key as an argument
|
|
49
|
+
or uses ~/.ssh/id_rsa if none provided
|
|
50
|
+
|
|
51
|
+
> $ pygmy addkey [~/.ssh/other_key]
|
|
52
|
+
LONGDESC
|
|
53
|
+
def addkey(key = "$HOME/.ssh/id_rsa")
|
|
54
|
+
add_ssh_key(key)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
desc 'version', 'Check current installed version of pygmy'
|
|
58
|
+
def version
|
|
59
|
+
puts "Pygmy - Version: #{Pygmy::VERSION}"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
desc 'restart', 'Stop and restart all pygmy services'
|
|
63
|
+
long_desc <<-LONGDESC
|
|
64
|
+
Stop and restart pygmy services (dnsmasq, resolv)
|
|
65
|
+
|
|
66
|
+
> $ pygmy restart [-d|--destroy]
|
|
67
|
+
LONGDESC
|
|
68
|
+
option :destroy, type: :boolean, aliases: 'd', default: false
|
|
69
|
+
def restart
|
|
70
|
+
exec_down(options)
|
|
71
|
+
exec_up(options)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
desc 'status', 'Report status of the pygmy services'
|
|
75
|
+
long_desc <<-LONGDESC
|
|
76
|
+
Checks the current status of the services managed by pygmy.
|
|
77
|
+
This includes dnsmasq, and resolv
|
|
78
|
+
|
|
79
|
+
> $ pygmy status
|
|
80
|
+
LONGDESC
|
|
81
|
+
def status
|
|
82
|
+
exec_status(options)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
private
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def exec_up(options)
|
|
89
|
+
|
|
90
|
+
if Pygmy::Dnsmasq.start
|
|
91
|
+
puts "Successfully started dnsmasq".green
|
|
92
|
+
else
|
|
93
|
+
puts "Error starting dnsmasq".red
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
if Pygmy::Haproxy.start
|
|
97
|
+
puts "Successfully started haproxy".green
|
|
98
|
+
else
|
|
99
|
+
puts "Error starting haproxy".red
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
if Pygmy::SshAgent.start
|
|
103
|
+
puts "Successfully started ssh-agent".green
|
|
104
|
+
else
|
|
105
|
+
puts "Error starting ssh-agent".red
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
if Pygmy::SshAgentAddKey.add_ssh_key
|
|
109
|
+
puts "Successfully injected ssh key".green
|
|
110
|
+
else
|
|
111
|
+
puts "Error injected ssh key".red
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
if Pygmy::Resolv.configure
|
|
115
|
+
puts "Successfully configured local resolver".green
|
|
116
|
+
else
|
|
117
|
+
puts "Error configuring local resolver".red
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def exec_status(_options)
|
|
122
|
+
|
|
123
|
+
if Pygmy::Dnsmasq.running?
|
|
124
|
+
puts "[*] Dnsmasq: Running as docker container #{Pygmy::Dnsmasq.container_name}".green
|
|
125
|
+
else
|
|
126
|
+
puts "[*] Dnsmasq is not running".red
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
if Pygmy::SshAgent.running?
|
|
130
|
+
puts "[*] ssh-agent: Running as docker container #{Pygmy::Haproxy.container_name}".green
|
|
131
|
+
else
|
|
132
|
+
puts "[*] ssh-agent is not running".red
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
if Pygmy::Dnsmasq.running?
|
|
136
|
+
puts "[*] Dnsmasq: Running as docker container #{Pygmy::Dnsmasq.container_name}".green
|
|
137
|
+
else
|
|
138
|
+
puts "[*] Dnsmasq is not running".red
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
if Pygmy::Resolv.has_our_nameserver?
|
|
142
|
+
puts "[*] Resolv: configured with #{Pygmy::Resolv.file_nameserver_line}".green
|
|
143
|
+
else
|
|
144
|
+
puts "[*] Resolv is not configured".red
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def add_ssh_key(key)
|
|
150
|
+
|
|
151
|
+
if Pygmy::SshAgent.running?
|
|
152
|
+
if Pygmy::SshAgentAddKey.add_ssh_key(key)
|
|
153
|
+
puts "Successfully added ssh key".green
|
|
154
|
+
else
|
|
155
|
+
puts "Error added ssh key".red
|
|
156
|
+
end
|
|
157
|
+
else
|
|
158
|
+
puts "ssh-agent is not running, cannot add key".red
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def exec_down(options)
|
|
164
|
+
if Pygmy::Resolv.clean
|
|
165
|
+
puts "nameserver removed from resolv file".green
|
|
166
|
+
else
|
|
167
|
+
puts "Unable to remove nameserver from resolv file".red
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
if Pygmy::Dnsmasq.stop
|
|
171
|
+
puts "Dnsmasq container stopped".green
|
|
172
|
+
if options[:destroy]
|
|
173
|
+
if Pygmy::Dnsmasq.delete
|
|
174
|
+
puts "Dnsmasq container successfully deleted".green
|
|
175
|
+
else
|
|
176
|
+
puts "Dnsmasq container failed to delete".red
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
else
|
|
180
|
+
puts "Dnsmasq container failed to stop".red
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
if Pygmy::SshAgent.stop
|
|
184
|
+
puts "ssh-agent container stopped".green
|
|
185
|
+
if options[:destroy]
|
|
186
|
+
if Pygmy::SshAgent.delete
|
|
187
|
+
puts "ssh-agent container successfully deleted".green
|
|
188
|
+
else
|
|
189
|
+
puts "ssh-agent container failed to delete".red
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
else
|
|
193
|
+
puts "ssh-agent container failed to stop".red
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
if Pygmy::Haproxy.stop
|
|
197
|
+
puts "Haproxy container stopped".green
|
|
198
|
+
if options[:destroy]
|
|
199
|
+
if Pygmy::Haproxy.delete
|
|
200
|
+
puts "Haproxy container successfully deleted".green
|
|
201
|
+
else
|
|
202
|
+
puts "Haproxy container failed to delete".red
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
else
|
|
206
|
+
puts "Haproxy container failed to stop".red
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
aliases = {
|
|
213
|
+
'start' => 'up',
|
|
214
|
+
'stop' => 'down',
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if !ARGV.empty? && %w[-v --version].include?(ARGV.first)
|
|
218
|
+
puts "Pygmy - Version: #{Pygmy::VERSION}"
|
|
219
|
+
else
|
|
220
|
+
PygmyBin.start(ARGV.map { |a| aliases.keys.include?(a) ? aliases[a] : a })
|
|
221
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require_relative 'docker_service'
|
|
2
|
+
|
|
3
|
+
module Pygmy
|
|
4
|
+
class Dnsmasq
|
|
5
|
+
extend Pygmy::DockerService
|
|
6
|
+
|
|
7
|
+
def self.image_name
|
|
8
|
+
'andyshinn/dnsmasq:2.75'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.container_name
|
|
12
|
+
'amazeeio-dnsmasq'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.domain
|
|
16
|
+
'docker.amazee.io'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.addr
|
|
20
|
+
'127.0.0.1'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.run_cmd(domain = self.domain, addr = self.addr)
|
|
24
|
+
"docker run -d -p 53:53/tcp -p 53:53/udp --name=#{Shellwords.escape(self.container_name)} " \
|
|
25
|
+
"--cap-add=NET_ADMIN #{Shellwords.escape(self.image_name)} -A /#{Shellwords.escape(domain)}/#{Shellwords.escape(addr)}"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'shellwords'
|
|
2
|
+
|
|
3
|
+
module Pygmy
|
|
4
|
+
module DockerService
|
|
5
|
+
def start
|
|
6
|
+
unless self.running?
|
|
7
|
+
success = if self.container_exists?
|
|
8
|
+
Sh.run_command(self.start_cmd).success?
|
|
9
|
+
else
|
|
10
|
+
Sh.run_command(self.run_cmd).success?
|
|
11
|
+
end
|
|
12
|
+
unless success
|
|
13
|
+
raise RuntimeError.new(
|
|
14
|
+
"Failed to run #{self.container_name}. Command #{self.run_cmd} failed"
|
|
15
|
+
)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
self.running?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def running?(container_name = self.container_name)
|
|
22
|
+
!!(self.ps =~ /#{container_name}/)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def container_exists?(container_name = self.container_name)
|
|
26
|
+
!!(self.ps(all: true) =~ /#{container_name}/)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def ps(all: false)
|
|
30
|
+
cmd = "docker ps#{all ? ' -a' : ''}"
|
|
31
|
+
ret = Sh.run_command(cmd)
|
|
32
|
+
if ret.success?
|
|
33
|
+
return ret.stdout
|
|
34
|
+
else
|
|
35
|
+
raise RuntimeError.new("Failure running command '#{cmd}'")
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def has_docker_client?
|
|
40
|
+
Sh.run_command('which docker').success?
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def stop(container_name = self.container_name)
|
|
44
|
+
Sh.run_command("docker kill #{Shellwords.escape(container_name)}") if self.running?
|
|
45
|
+
!self.running?
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def delete(container_name = self.container_name)
|
|
49
|
+
if self.container_exists?
|
|
50
|
+
self.stop if self.running?
|
|
51
|
+
Sh.run_command("docker rm #{Shellwords.escape(container_name)}")
|
|
52
|
+
end
|
|
53
|
+
!self.container_exists?
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def start_cmd
|
|
57
|
+
"docker start #{Shellwords.escape(self.container_name)}"
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require_relative 'docker_service'
|
|
2
|
+
|
|
3
|
+
module Pygmy
|
|
4
|
+
class Haproxy
|
|
5
|
+
extend Pygmy::DockerService
|
|
6
|
+
|
|
7
|
+
def self.image_name
|
|
8
|
+
'amazeeio/haproxy'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.container_name
|
|
12
|
+
'amazeeio-haproxy'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.run_cmd()
|
|
16
|
+
"docker run -d " \
|
|
17
|
+
"-p 80:80 -p 443:443 " \
|
|
18
|
+
"--volume=/var/run/docker.sock:/tmp/docker.sock " \
|
|
19
|
+
"--restart=always " \
|
|
20
|
+
"--name=#{Shellwords.escape(self.container_name)} " \
|
|
21
|
+
"#{Shellwords.escape(self.image_name)}"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
data/lib/pygmy/linux.rb
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module Dory
|
|
2
|
+
module Linux
|
|
3
|
+
def self.bash(command)
|
|
4
|
+
system("bash -c '#{command}'")
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.ubuntu?
|
|
8
|
+
self.bash(self.ubuntu_cmd)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.fedora?
|
|
12
|
+
self.bash(self.fedora_cmd)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.arch?
|
|
16
|
+
self.bash(self.arch_cmd)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.osx?
|
|
20
|
+
self.bash('uname -a | grep "Darwin" > /dev/null')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.ubuntu_cmd
|
|
24
|
+
%q(
|
|
25
|
+
if $(which lsb_release >/dev/null 2>&1); then
|
|
26
|
+
lsb_release -d | grep --color=auto "Ubuntu" > /dev/null
|
|
27
|
+
else
|
|
28
|
+
uname -a | grep --color=auto "Ubuntu" > /dev/null
|
|
29
|
+
fi
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.fedora_cmd
|
|
34
|
+
%q(
|
|
35
|
+
if $(which lsb_release >/dev/null 2>&1); then
|
|
36
|
+
lsb_release -d | grep --color=auto "Fedora" > /dev/null
|
|
37
|
+
else
|
|
38
|
+
uname -r | grep --color=auto "fc" > /dev/null
|
|
39
|
+
fi
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.arch_cmd
|
|
44
|
+
%q(
|
|
45
|
+
if $(which lsb_release >/dev/null 2>&1); then
|
|
46
|
+
lsb_release -d | grep --color=auto "Arch" > /dev/null
|
|
47
|
+
else
|
|
48
|
+
uname -a | grep --color=auto "ARCH" > /dev/null
|
|
49
|
+
fi
|
|
50
|
+
)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
data/lib/pygmy/resolv.rb
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
require 'colorize'
|
|
2
|
+
|
|
3
|
+
module Pygmy
|
|
4
|
+
module Resolv
|
|
5
|
+
def self.common_resolv_file
|
|
6
|
+
'/etc/resolv.conf'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.ubuntu_resolv_file
|
|
10
|
+
#'/etc/resolvconf/resolv.conf.d/base'
|
|
11
|
+
# For now, use the common_resolv_file
|
|
12
|
+
self.common_resolv_file
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.file_comment
|
|
16
|
+
'# added by pygmy'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.nameserver
|
|
20
|
+
"127.0.0.1"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.file_nameserver_line
|
|
24
|
+
"nameserver #{self.nameserver}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.nameserver_contents
|
|
28
|
+
"#{self.file_nameserver_line} #{self.file_comment}"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.resolv_file
|
|
32
|
+
if Linux.ubuntu?
|
|
33
|
+
return self.ubuntu_resolv_file if Linux.ubuntu?
|
|
34
|
+
elsif Linux.fedora? || Linux.arch? || File.exist?(self.common_resolv_file)
|
|
35
|
+
return self.common_resolv_file
|
|
36
|
+
else
|
|
37
|
+
raise RuntimeError.new(
|
|
38
|
+
"Unable to determine location of resolv file"
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.configure
|
|
44
|
+
# we want to be the first nameserver in the list for performance reasons
|
|
45
|
+
# we only want to add the nameserver if it isn't already there
|
|
46
|
+
prev_conts = self.resolv_file_contents
|
|
47
|
+
unless self.contents_has_our_nameserver?(prev_conts)
|
|
48
|
+
if prev_conts =~ /nameserver/
|
|
49
|
+
prev_conts.sub!(/nameserver/, "#{self.nameserver_contents}\nnameserver")
|
|
50
|
+
else
|
|
51
|
+
prev_conts = "#{prev_conts}\n#{self.nameserver_contents}"
|
|
52
|
+
end
|
|
53
|
+
prev_conts.gsub!(/\s+$/, '')
|
|
54
|
+
self.write_to_file(prev_conts)
|
|
55
|
+
end
|
|
56
|
+
self.has_our_nameserver?
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def self.clean
|
|
60
|
+
prev_conts = self.resolv_file_contents
|
|
61
|
+
if self.contents_has_our_nameserver?(prev_conts)
|
|
62
|
+
prev_conts.gsub!(/#{Regexp.escape(self.nameserver_contents + "\n")}/, '')
|
|
63
|
+
prev_conts.gsub!(/\s+$/, '')
|
|
64
|
+
self.write_to_file(prev_conts)
|
|
65
|
+
end
|
|
66
|
+
!self.has_our_nameserver?
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def self.write_to_file(contents)
|
|
70
|
+
# have to use this hack cuz we don't run as root :-(
|
|
71
|
+
puts "Requesting sudo to write to #{self.resolv_file}".green
|
|
72
|
+
Bash.run_command("echo -e '#{contents}' | sudo tee #{Shellwords.escape(self.resolv_file)} >/dev/null")
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def self.resolv_file_contents
|
|
76
|
+
File.read(self.resolv_file)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def self.has_our_nameserver?
|
|
80
|
+
self.contents_has_our_nameserver?(self.resolv_file_contents)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def self.contents_has_our_nameserver?(contents)
|
|
84
|
+
!!((contents =~ /#{self.file_comment}/) || (contents =~ /#{self.file_nameserver_line}/))
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
data/lib/pygmy/shell.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'ostruct'
|
|
2
|
+
|
|
3
|
+
module Pygmy
|
|
4
|
+
module Sh
|
|
5
|
+
def self.run_command(command)
|
|
6
|
+
stdout = `#{command}`
|
|
7
|
+
OpenStruct.new({
|
|
8
|
+
success?: $?.exitstatus == 0,
|
|
9
|
+
exitstatus: $?.exitstatus,
|
|
10
|
+
stdout: stdout
|
|
11
|
+
})
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
module Bash
|
|
16
|
+
def self.run_command(command)
|
|
17
|
+
stdout = `bash -c "#{command}"`
|
|
18
|
+
OpenStruct.new({
|
|
19
|
+
success?: $?.exitstatus == 0,
|
|
20
|
+
exitstatus: $?.exitstatus,
|
|
21
|
+
stdout: stdout
|
|
22
|
+
})
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require_relative 'docker_service'
|
|
2
|
+
|
|
3
|
+
module Pygmy
|
|
4
|
+
class SshAgent
|
|
5
|
+
extend Pygmy::DockerService
|
|
6
|
+
|
|
7
|
+
def self.image_name
|
|
8
|
+
'amazeeio/ssh-agent'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.container_name
|
|
12
|
+
'amazeeio-ssh-agent'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.run_cmd()
|
|
16
|
+
"docker run -d " \
|
|
17
|
+
"--restart=always " \
|
|
18
|
+
"--name=#{Shellwords.escape(self.container_name)} " \
|
|
19
|
+
"#{Shellwords.escape(self.image_name)}"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Pygmy
|
|
2
|
+
class SshAgentAddKey
|
|
3
|
+
def self.image_name
|
|
4
|
+
'amazeeio/ssh-agent'
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.container_name
|
|
8
|
+
'amazeeio-ssh-agent-add-key'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.add_ssh_key(key = "$HOME/.ssh/id_rsa")
|
|
12
|
+
system("docker run --rm -it " \
|
|
13
|
+
"--volume=#{key}:/#{key} " \
|
|
14
|
+
"--volumes-from=amazeeio-ssh-agent " \
|
|
15
|
+
"--name=#{Shellwords.escape(self.container_name)} " \
|
|
16
|
+
"#{Shellwords.escape(self.image_name)} " \
|
|
17
|
+
"ssh-add #{key}")
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
data/lib/pygmy.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: pygmy
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.9.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Michael Schmid
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-04-30 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: colorize
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0.7'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0.7'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: thor
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0.19'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0.19'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: ptools
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1.3'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1.3'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rspec
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '3.4'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '3.4'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rake
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '10.5'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '10.5'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: byebug
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '8.2'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '8.2'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: codeclimate-test-reporter
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0.5'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0.5'
|
|
111
|
+
description: To fully and easy run a local Drupal development system you need more
|
|
112
|
+
then just a docker container with the Drupal running. Default development workflows
|
|
113
|
+
involves running multiple sites at the same time, interacting with other services
|
|
114
|
+
which are authenticated via ssh and more.Pygmy makes usre that the required Docker
|
|
115
|
+
containers are started and that youcomfortably can access the Drupal Containers
|
|
116
|
+
just via the browser.
|
|
117
|
+
email: michael@amazee.io
|
|
118
|
+
executables:
|
|
119
|
+
- pygmy
|
|
120
|
+
extensions: []
|
|
121
|
+
extra_rdoc_files: []
|
|
122
|
+
files:
|
|
123
|
+
- bin/pygmy
|
|
124
|
+
- lib/pygmy.rb
|
|
125
|
+
- lib/pygmy/dnsmasq.rb
|
|
126
|
+
- lib/pygmy/docker_service.rb
|
|
127
|
+
- lib/pygmy/haproxy.rb
|
|
128
|
+
- lib/pygmy/inst_vars_to_hash.rb
|
|
129
|
+
- lib/pygmy/linux.rb
|
|
130
|
+
- lib/pygmy/resolv.rb
|
|
131
|
+
- lib/pygmy/shell.rb
|
|
132
|
+
- lib/pygmy/ssh_agent.rb
|
|
133
|
+
- lib/pygmy/ssh_agent_add_key.rb
|
|
134
|
+
- lib/pygmy/version.rb
|
|
135
|
+
homepage: https://github.com/amazeeio/pygmy
|
|
136
|
+
licenses:
|
|
137
|
+
- MIT
|
|
138
|
+
metadata: {}
|
|
139
|
+
post_install_message:
|
|
140
|
+
rdoc_options: []
|
|
141
|
+
require_paths:
|
|
142
|
+
- lib
|
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
|
+
requirements:
|
|
145
|
+
- - ">="
|
|
146
|
+
- !ruby/object:Gem::Version
|
|
147
|
+
version: '0'
|
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
|
+
requirements:
|
|
150
|
+
- - ">="
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: '0'
|
|
153
|
+
requirements: []
|
|
154
|
+
rubyforge_project:
|
|
155
|
+
rubygems_version: 2.6.4
|
|
156
|
+
signing_key:
|
|
157
|
+
specification_version: 4
|
|
158
|
+
summary: pygmy provides the required servies to run the amazee.io Drupal local development
|
|
159
|
+
environment on linux.
|
|
160
|
+
test_files: []
|