escualo 1.0.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/escualo +5 -7
- data/lib/command.rb +6 -7
- data/lib/commands/artifact.rb +47 -79
- data/lib/commands/bootstrap.rb +30 -25
- data/lib/commands/deploy.rb +8 -6
- data/lib/commands/env.rb +12 -9
- data/lib/commands/globals.rb +7 -36
- data/lib/commands/plugin.rb +9 -19
- data/lib/commands/rake.rb +3 -5
- data/lib/commands/remote.rb +6 -5
- data/lib/commands/script.rb +6 -25
- data/lib/commands/upload.rb +2 -2
- data/lib/escualo/apt_get.rb +10 -0
- data/lib/escualo/artifact.rb +40 -43
- data/lib/escualo/base.rb +36 -15
- data/lib/escualo/env.rb +22 -32
- data/lib/escualo/gems.rb +4 -4
- data/lib/escualo/plugin/docker.rb +4 -4
- data/lib/escualo/plugin/haskell.rb +4 -4
- data/lib/escualo/plugin/mongo.rb +6 -10
- data/lib/escualo/plugin/monit.rb +16 -17
- data/lib/escualo/plugin/nginx.rb +7 -10
- data/lib/escualo/plugin/node.rb +6 -8
- data/lib/escualo/plugin/postgres.rb +26 -0
- data/lib/escualo/plugin/rabbit.rb +9 -14
- data/lib/escualo/plugin.rb +1 -6
- data/lib/escualo/remote.rb +18 -20
- data/lib/escualo/ruby.rb +17 -0
- data/lib/escualo/script.rb +7 -61
- data/lib/escualo/session/docker_session.rb +56 -0
- data/lib/escualo/session/local_session.rb +23 -0
- data/lib/escualo/session/remote_session.rb +42 -0
- data/lib/escualo/session.rb +83 -0
- data/lib/escualo/version.rb +2 -2
- data/lib/escualo.rb +13 -1
- data/lib/ssh.rb +26 -4
- data/lib/templates/codechange.sh.erb +1 -1
- data/lib/templates/init.sh.erb +7 -0
- data/lib/templates/post-receive.sh.erb +8 -2
- metadata +9 -9
- data/lib/commands/base.rb +0 -8
- data/lib/escualo/bootstrap.rb +0 -37
- data/lib/escualo/plugin/postgre.rb +0 -23
- data/lib/ssh/local_session.rb +0 -44
- data/lib/ssh/perform.rb +0 -9
- data/lib/ssh/session.rb +0 -61
- data/lib/ssh/upload.rb +0 -9
data/lib/escualo/script.rb
CHANGED
@@ -1,77 +1,23 @@
|
|
1
1
|
module Escualo
|
2
2
|
module Script
|
3
|
-
def self.
|
4
|
-
script.map { |it| "escualo #{it} #{extra}" }
|
3
|
+
def self.commands(escualo, script, extra)
|
4
|
+
(script||[]).map { |it| "#{escualo} #{it} #{extra}" }
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.delegated_options(options)
|
8
8
|
[options.hostname.try { |it| "--hostname #{it}" },
|
9
9
|
options.username.try { |it| "--username #{it}" },
|
10
|
-
options.password.try { |it| "--password #{it}" },
|
10
|
+
options.password.try { |it| "--ssh-password #{it}" },
|
11
11
|
options.ssh_key.try { |it| "--ssh-key #{it}" },
|
12
12
|
options.ssh_port.try { |it| "--ssh-port #{it}" },
|
13
13
|
options.trace && '--trace',
|
14
|
-
options.verbose && '--verbose'
|
14
|
+
options.verbose && '--verbose',
|
15
15
|
].compact.join(' ')
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
run_command! command, ssh, options
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class Standard < Mode
|
27
|
-
def start!(*)
|
28
|
-
end
|
29
|
-
|
30
|
-
def run_command!(command, ssh, options)
|
31
|
-
ssh.shell.perform! command, options
|
32
|
-
end
|
33
|
-
|
34
|
-
def finish!
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
class Dockerized < Mode
|
39
|
-
attr_accessor :dockerfile
|
40
|
-
|
41
|
-
def start!(options)
|
42
|
-
@dockerfile = "
|
43
|
-
FROM #{base_image options}
|
44
|
-
MAINTAINER #{ENV['USER']}
|
45
|
-
RUN apt-get update && apt-get install ruby ruby-dev build-essential -y
|
46
|
-
#{escualo_install options}"
|
47
|
-
end
|
48
|
-
|
49
|
-
def escualo_install(options)
|
50
|
-
if options.development
|
51
|
-
"
|
52
|
-
COPY escualo-#{Escualo::VERSION}.gem escualo-#{Escualo::VERSION}.gem
|
53
|
-
RUN gem install escualo-#{Escualo::VERSION}.gem\n"
|
54
|
-
else
|
55
|
-
"RUN gem install escualo -v #{Escualo::VERSION}\n"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def base_image(options)
|
60
|
-
if options.base_image == 'ubuntu'
|
61
|
-
'ubuntu:xenial'
|
62
|
-
elsif options.base_image == 'debian'
|
63
|
-
'debian:jessie'
|
64
|
-
else
|
65
|
-
raise "Unsupported base image #{options.base_image}. Only debian and ubuntu are supported"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def run_command!(command, ssh, options)
|
70
|
-
@dockerfile << "RUN #{command}\n"
|
71
|
-
end
|
72
|
-
|
73
|
-
def finish!
|
74
|
-
File.write('Dockerfile', @dockerfile)
|
18
|
+
def self.run!(session, escualo, script, extra='')
|
19
|
+
Escualo::Script.commands(escualo, script, extra).each do |command|
|
20
|
+
session.embed! command
|
75
21
|
end
|
76
22
|
end
|
77
23
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
class Escualo::Session::Docker < Escualo::Session
|
2
|
+
attr_accessor :dockerfile
|
3
|
+
|
4
|
+
def embed!(command)
|
5
|
+
dockerfile << Open3.exec!("#{command} --dockerized")
|
6
|
+
end
|
7
|
+
|
8
|
+
def tell!(command)
|
9
|
+
dockerfile << "RUN #{command}\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
def upload!(file, destination)
|
13
|
+
dockerfile << "COPY #{file} #{destination}\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
def write_template!(name, template, &block)
|
17
|
+
template.write! name
|
18
|
+
block.call name
|
19
|
+
end
|
20
|
+
|
21
|
+
def ask(*)
|
22
|
+
raise 'can not ask on a docker session'
|
23
|
+
end
|
24
|
+
|
25
|
+
def start!(options)
|
26
|
+
if options.write_dockerfile
|
27
|
+
@dockerfile = "FROM #{base_image options}\nMAINTAINER #{ENV['USER']}\n"
|
28
|
+
else
|
29
|
+
@dockerfile = ''
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def base_image(options)
|
34
|
+
if options.base_image == 'ubuntu'
|
35
|
+
'ubuntu:xenial'
|
36
|
+
elsif options.base_image == 'debian'
|
37
|
+
'debian:jessie'
|
38
|
+
else
|
39
|
+
raise "Unsupported base image #{options.base_image}. Only debian and ubuntu are supported"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def finish!(options)
|
44
|
+
if options.write_dockerfile
|
45
|
+
File.write('Dockerfile', dockerfile)
|
46
|
+
else
|
47
|
+
puts dockerfile
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.started(options = struct)
|
52
|
+
new.tap do |it|
|
53
|
+
it.start!(options)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Escualo::Session::Local < Escualo::Session
|
2
|
+
def exec!(command)
|
3
|
+
ask command
|
4
|
+
nil
|
5
|
+
end
|
6
|
+
|
7
|
+
def ask(command)
|
8
|
+
Open3.exec! command
|
9
|
+
end
|
10
|
+
|
11
|
+
def stream!(command)
|
12
|
+
Open3.popen2e command do |_input, output, wait|
|
13
|
+
output.each do |line|
|
14
|
+
$stdout.print line
|
15
|
+
end
|
16
|
+
raise "command #{command} failed" unless wait.value.success?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def upload!(file, destination)
|
21
|
+
FileUtils.cp file, destination
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class Escualo::Session::Remote < Escualo::Session
|
2
|
+
def initialize(ssh, options)
|
3
|
+
super(options)
|
4
|
+
@ssh = ssh
|
5
|
+
end
|
6
|
+
|
7
|
+
def upload!(file, destination)
|
8
|
+
@ssh.scp.upload! file, destination
|
9
|
+
end
|
10
|
+
|
11
|
+
def exec!(command)
|
12
|
+
ask command
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def ask(command)
|
17
|
+
out = []
|
18
|
+
@ssh.stream! wrap(command) do |_stream, data|
|
19
|
+
out << data
|
20
|
+
end
|
21
|
+
out
|
22
|
+
end
|
23
|
+
|
24
|
+
def stream!(command)
|
25
|
+
command = wrap(command)
|
26
|
+
@ssh.stream! command do |stream, data|
|
27
|
+
if stream == :stdout
|
28
|
+
$stdout.print data
|
29
|
+
else
|
30
|
+
$stderr.print data
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def wrap(command)
|
38
|
+
"bash -i -s <<EOBASH
|
39
|
+
#{command.gsub('$', '\$')}
|
40
|
+
EOBASH"
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
class Escualo::Session
|
4
|
+
attr_accessor :options
|
5
|
+
|
6
|
+
def initialize(options=struct)
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def check?(command, include)
|
11
|
+
ask(command).include? include rescue false
|
12
|
+
end
|
13
|
+
|
14
|
+
def embed!(command)
|
15
|
+
tell! command
|
16
|
+
end
|
17
|
+
|
18
|
+
def tell_all!(*commands)
|
19
|
+
tell! commands.compact.join(' && ')
|
20
|
+
end
|
21
|
+
|
22
|
+
def tell!(command)
|
23
|
+
if options.verbose
|
24
|
+
stream! command
|
25
|
+
else
|
26
|
+
exec! command
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def upload_template!(destination, name, bindings)
|
31
|
+
write_template! name, Mumukit::Core::Template.new(File.join(__dir__, '..', 'templates', "#{name}.erb"), bindings) do |file|
|
32
|
+
upload! file, destination
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def write_template!(name, template, &block)
|
37
|
+
template.with_tempfile!('template', &block)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.parse_session_options(options)
|
41
|
+
struct username: options.username || 'root',
|
42
|
+
hostname: options.hostname || 'localhost',
|
43
|
+
ssh_options: {
|
44
|
+
keys: [options.ssh_key].compact,
|
45
|
+
port: options.ssh_port || 22
|
46
|
+
},
|
47
|
+
verbose: options.verbose,
|
48
|
+
local: options.hostname.blank? && options.username.blank? && options.ssh_key.blank? && options.ssh_port.blank?,
|
49
|
+
dockerized: options.dockerized
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.within(options, force_local=false, &block)
|
53
|
+
session_options = parse_session_options options
|
54
|
+
|
55
|
+
if session_options.dockerized
|
56
|
+
within_dockerized_session session_options, options, &block
|
57
|
+
elsif session_options.local || force_local
|
58
|
+
block.call(Escualo::Session::Local.new session_options)
|
59
|
+
else
|
60
|
+
within_ssh_session(session_options, &block)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.within_dockerized_session(session_options, options, &block)
|
65
|
+
session = Escualo::Session::Docker.new session_options
|
66
|
+
session.start! options
|
67
|
+
block.call(session)
|
68
|
+
session.finish! options
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.within_ssh_session(session_options, &block)
|
72
|
+
Net::SSH.start(
|
73
|
+
session_options.hostname,
|
74
|
+
session_options.username,
|
75
|
+
session_options.ssh_options) do |ssh|
|
76
|
+
block.call(Escualo::Session::Remote.new ssh, session_options)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
require_relative './session/docker_session'
|
82
|
+
require_relative './session/remote_session'
|
83
|
+
require_relative './session/local_session'
|
data/lib/escualo/version.rb
CHANGED
data/lib/escualo.rb
CHANGED
@@ -13,15 +13,27 @@ require 'mumukit/core'
|
|
13
13
|
module Escualo
|
14
14
|
end
|
15
15
|
|
16
|
+
require 'open3'
|
17
|
+
|
18
|
+
module Open3
|
19
|
+
def self.exec!(command)
|
20
|
+
out, status = Open3.capture2e(command)
|
21
|
+
raise "command failed #{command}: #{out}" unless status.success?
|
22
|
+
out
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
16
26
|
require_relative './template'
|
17
27
|
require_relative './ssh'
|
18
28
|
|
19
29
|
require_relative './escualo/version'
|
30
|
+
require_relative './escualo/session'
|
20
31
|
require_relative './escualo/env'
|
21
32
|
require_relative './escualo/ppa'
|
33
|
+
require_relative './escualo/apt_get'
|
22
34
|
require_relative './escualo/gems'
|
23
35
|
require_relative './escualo/base'
|
24
|
-
require_relative './escualo/
|
36
|
+
require_relative './escualo/ruby'
|
25
37
|
require_relative './escualo/script'
|
26
38
|
require_relative './escualo/plugin'
|
27
39
|
require_relative './escualo/remote'
|
data/lib/ssh.rb
CHANGED
@@ -1,4 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
class Net::SSH::Connection::Session
|
2
|
+
def stream!(command)
|
3
|
+
exit_code = 0
|
4
|
+
channel = self.open_channel do |channel|
|
5
|
+
channel.exec command do |ch, success|
|
6
|
+
raise 'could not execute command' unless success
|
7
|
+
ch.on_data do |c, data|
|
8
|
+
yield :stdout, data unless garbage? data
|
9
|
+
end
|
10
|
+
ch.on_extended_data do |c, type, data|
|
11
|
+
yield :stderr, data unless garbage? data
|
12
|
+
end
|
13
|
+
ch.on_request('exit-status') do |c, data|
|
14
|
+
exit_code = data.read_long
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
channel.wait
|
19
|
+
raise "command failed #{command}!" if exit_code != 0
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def garbage?(data)
|
24
|
+
data.start_with?('bash: cannot set terminal process group') || data.start_with?('bash: no job control in this shell')
|
25
|
+
end
|
26
|
+
end
|
data/lib/templates/init.sh.erb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/bin/bash
|
2
2
|
REVISION=$1
|
3
|
+
START_TYPE=$2
|
3
4
|
|
4
5
|
cd /var/www/<%= @name %>
|
5
6
|
|
@@ -13,6 +14,12 @@ fi
|
|
13
14
|
echo "[Escualo] [<%= @name %>] installing dependencies..."
|
14
15
|
<%= @install_command %>
|
15
16
|
|
17
|
+
if [ $START_TYPE = first ] && [ -e .escualo/install/first ]; then
|
18
|
+
echo "[Escualo] [<%= @name %>] .escualo/install/start and it is first run. Running it..."
|
19
|
+
chmod u+x .escualo/install/first
|
20
|
+
.escualo/install/first
|
21
|
+
fi
|
22
|
+
|
16
23
|
monit unmonitor escualo-<%= @name %>
|
17
24
|
service <%= @name %> stop
|
18
25
|
|
@@ -14,11 +14,17 @@ do
|
|
14
14
|
|
15
15
|
echo "[Escualo] [<%= @name %>] master branch detected, deploying..."
|
16
16
|
mkdir -p /var/www/<%= @name %>
|
17
|
-
git --work-tree=/var/www/<%= @name %> --git-dir=/var/repo/<%= @name %>.git checkout master -f
|
18
17
|
|
18
|
+
if [ "$(ls -A /var/www/<%= @name %>)" ]; then
|
19
|
+
START_TYPE=restart
|
20
|
+
else
|
21
|
+
START_TYPE=first
|
22
|
+
fi
|
23
|
+
|
24
|
+
git --work-tree=/var/www/<%= @name %> --git-dir=/var/repo/<%= @name %>.git checkout master -f
|
19
25
|
<% if @service %>
|
20
26
|
/var/scripts/<%= @name %>/codechange $newrev
|
21
27
|
<% end %>
|
22
|
-
/var/scripts/<%= @name %>/init $newrev
|
28
|
+
/var/scripts/<%= @name %>/init $newrev $START_TYPE
|
23
29
|
fi
|
24
30
|
done
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: escualo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Franco Leonardo Bulgarelli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|
@@ -135,7 +135,6 @@ files:
|
|
135
135
|
- bin/escualo
|
136
136
|
- lib/command.rb
|
137
137
|
- lib/commands/artifact.rb
|
138
|
-
- lib/commands/base.rb
|
139
138
|
- lib/commands/bootstrap.rb
|
140
139
|
- lib/commands/deploy.rb
|
141
140
|
- lib/commands/env.rb
|
@@ -146,9 +145,9 @@ files:
|
|
146
145
|
- lib/commands/script.rb
|
147
146
|
- lib/commands/upload.rb
|
148
147
|
- lib/escualo.rb
|
148
|
+
- lib/escualo/apt_get.rb
|
149
149
|
- lib/escualo/artifact.rb
|
150
150
|
- lib/escualo/base.rb
|
151
|
-
- lib/escualo/bootstrap.rb
|
152
151
|
- lib/escualo/env.rb
|
153
152
|
- lib/escualo/gems.rb
|
154
153
|
- lib/escualo/plugin.rb
|
@@ -158,17 +157,18 @@ files:
|
|
158
157
|
- lib/escualo/plugin/monit.rb
|
159
158
|
- lib/escualo/plugin/nginx.rb
|
160
159
|
- lib/escualo/plugin/node.rb
|
161
|
-
- lib/escualo/plugin/
|
160
|
+
- lib/escualo/plugin/postgres.rb
|
162
161
|
- lib/escualo/plugin/rabbit.rb
|
163
162
|
- lib/escualo/ppa.rb
|
164
163
|
- lib/escualo/remote.rb
|
164
|
+
- lib/escualo/ruby.rb
|
165
165
|
- lib/escualo/script.rb
|
166
|
+
- lib/escualo/session.rb
|
167
|
+
- lib/escualo/session/docker_session.rb
|
168
|
+
- lib/escualo/session/local_session.rb
|
169
|
+
- lib/escualo/session/remote_session.rb
|
166
170
|
- lib/escualo/version.rb
|
167
171
|
- lib/ssh.rb
|
168
|
-
- lib/ssh/local_session.rb
|
169
|
-
- lib/ssh/perform.rb
|
170
|
-
- lib/ssh/session.rb
|
171
|
-
- lib/ssh/upload.rb
|
172
172
|
- lib/template.rb
|
173
173
|
- lib/templates/codechange.sh.erb
|
174
174
|
- lib/templates/init.sh.erb
|
data/lib/commands/base.rb
DELETED
data/lib/escualo/bootstrap.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
module Escualo
|
2
|
-
module Bootstrap
|
3
|
-
def self.install_ruby(ssh, options)
|
4
|
-
ssh.shell.perform! 'apt-get purge libruby* -y', options
|
5
|
-
if options.with_rbenv
|
6
|
-
ssh.shell.perform! %q{
|
7
|
-
curl https://raw.githubusercontent.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash &&
|
8
|
-
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc &&
|
9
|
-
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
|
10
|
-
}, options
|
11
|
-
ssh.shell.perform! 'rbenv install 2.3.1 && rbenv global 2.3.1 && rbenv rehash', options
|
12
|
-
else
|
13
|
-
ssh.shell.perform! %Q{
|
14
|
-
apt-get install software-properties-common -y &&
|
15
|
-
apt-add-repository '#{Escualo::PPA.for 'brightbox/ruby-ng'}' &&
|
16
|
-
apt-get update &&
|
17
|
-
apt-get install -y ruby2.3 ruby2.3-dev
|
18
|
-
}, options
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.enable_swap(ssh)
|
23
|
-
ssh.exec! %q{ \
|
24
|
-
test -e /swapfile ||
|
25
|
-
fallocate -l 4G /swapfile && \
|
26
|
-
chmod 600 /swapfile && \
|
27
|
-
mkswap /swapfile && \
|
28
|
-
swapon /swapfile && \
|
29
|
-
swapon -s && \
|
30
|
-
echo '/swapfile none swap sw 0 0' >> /etc/fstab}
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.check(ssh)
|
34
|
-
Escualo::Env.present?(ssh, :ESCUALO_BASE_VERSION) && Escualo::Gems.present?(ssh)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Escualo::Plugin
|
2
|
-
class Postgre
|
3
|
-
def run(ssh, options)
|
4
|
-
pg_hba_conf = "/etc/postgresql/#{options.pg_version}/main/pg_hba.conf"
|
5
|
-
|
6
|
-
ssh.shell.perform! %Q{
|
7
|
-
apt-get install postgresql libpq-dev -y &&
|
8
|
-
echo 'local all postgres peer' > #{pg_hba_conf} &&
|
9
|
-
echo 'local all postgres peer' >> #{pg_hba_conf} &&
|
10
|
-
echo 'local all all password' >> #{pg_hba_conf} &&
|
11
|
-
echo 'host all all 127.0.0.1/32 md5' >> #{pg_hba_conf} &&
|
12
|
-
cd / &&
|
13
|
-
sudo -u postgres PGDATABASE='' psql <<EOF
|
14
|
-
create role $POSTGRESQL_DB_USERNAME with createdb login password '$POSTGRESQL_DB_PASSWORD';
|
15
|
-
EOF
|
16
|
-
}, options
|
17
|
-
end
|
18
|
-
|
19
|
-
def check(ssh, options)
|
20
|
-
ssh.shell.exec!('psql --version').include? "psql (PostgreSQL) #{options.pg_version}" rescue false
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/lib/ssh/local_session.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'open3'
|
3
|
-
|
4
|
-
module Net::SSH
|
5
|
-
def self.with_session(options, &block)
|
6
|
-
if options.delete(:local)
|
7
|
-
block.call(Net::SSH::Connection::LocalSession.new)
|
8
|
-
else
|
9
|
-
start(options.delete(:hostname),
|
10
|
-
options.delete(:username),
|
11
|
-
options.compact) do |ssh|
|
12
|
-
block.call(ssh)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class Net::SSH::Connection::LocalSession
|
19
|
-
include Net::SSH::Connection::Perform
|
20
|
-
include Net::SSH::Connection::Upload
|
21
|
-
|
22
|
-
def exec!(command)
|
23
|
-
out, status = Open3.capture2e(command)
|
24
|
-
raise out unless status.success?
|
25
|
-
out
|
26
|
-
end
|
27
|
-
|
28
|
-
def upload_file!(file, destination)
|
29
|
-
FileUtils.cp file, destination
|
30
|
-
end
|
31
|
-
|
32
|
-
def tell!(command)
|
33
|
-
Open3.popen2e command do |_input, output, wait|
|
34
|
-
output.each do |line|
|
35
|
-
$stdout.print line
|
36
|
-
end
|
37
|
-
raise "command #{command} failed" unless wait.value.success?
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def shell
|
42
|
-
self
|
43
|
-
end
|
44
|
-
end
|
data/lib/ssh/perform.rb
DELETED
data/lib/ssh/session.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
class Net::SSH::Connection::Session
|
2
|
-
include Net::SSH::Connection::Perform
|
3
|
-
include Net::SSH::Connection::Upload
|
4
|
-
|
5
|
-
def upload_file!(file, destination)
|
6
|
-
scp.upload! file, destination
|
7
|
-
end
|
8
|
-
|
9
|
-
def tell!(command)
|
10
|
-
channel = self.open_channel do |ch|
|
11
|
-
ch.exec command do |ch, success|
|
12
|
-
raise 'could not execute command' unless success
|
13
|
-
ch.on_data do |c, data|
|
14
|
-
$stdout.print data unless garbage? data
|
15
|
-
end
|
16
|
-
ch.on_extended_data do |c, type, data|
|
17
|
-
$stderr.print data unless garbage? data
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
channel.wait
|
22
|
-
end
|
23
|
-
|
24
|
-
def shell
|
25
|
-
Shell.new self
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def garbage?(data)
|
31
|
-
data.start_with?('bash: cannot set terminal process group') || data.start_with?('bash: no job control in this shell')
|
32
|
-
end
|
33
|
-
|
34
|
-
class Shell
|
35
|
-
attr_reader :ssh
|
36
|
-
|
37
|
-
def initialize(ssh)
|
38
|
-
@ssh = ssh
|
39
|
-
end
|
40
|
-
|
41
|
-
def perform!(command, options)
|
42
|
-
ssh.perform! wrap(command), options
|
43
|
-
end
|
44
|
-
|
45
|
-
def exec!(command)
|
46
|
-
ssh.exec! wrap(command)
|
47
|
-
end
|
48
|
-
|
49
|
-
def tell!(command)
|
50
|
-
ssh.tell! wrap(command)
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
def wrap(command)
|
56
|
-
"bash -i -s <<EOBASH
|
57
|
-
#{command.gsub('$', '\$')}
|
58
|
-
EOBASH"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
data/lib/ssh/upload.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
module Net::SSH::Connection::Upload
|
2
|
-
def upload_template!(destination, name, bindings)
|
3
|
-
Mumukit::Core::Template
|
4
|
-
.new(File.join(__dir__, '..', 'templates', "#{name}.erb"), bindings)
|
5
|
-
.with_tempfile!('template') do |file|
|
6
|
-
upload_file! file, destination
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|