escualo 2.0.2 → 3.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 +0 -1
- data/lib/commands/artifact.rb +6 -0
- data/lib/commands/globals.rb +1 -0
- data/lib/commands/plugin.rb +2 -1
- data/lib/escualo.rb +0 -1
- data/lib/escualo/env.rb +16 -13
- data/lib/escualo/plugin/postgres.rb +22 -10
- data/lib/escualo/session.rb +6 -44
- data/lib/escualo/session/docker_session.rb +23 -24
- data/lib/escualo/session/environment.rb +22 -0
- data/lib/escualo/session/within.rb +43 -0
- data/lib/escualo/version.rb +1 -1
- metadata +4 -4
- data/lib/commands/script.rb +0 -20
- data/lib/escualo/script.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f760bc96fc3d1d909c168493dc696bbe728430e1
|
4
|
+
data.tar.gz: 573ffed5fa0763389d1b23f0b548cd95d2265647
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8020df47e8a153df05b1e4326d693ea2720355cbe2d1c2458f6d898b5bf2fa7e2565f14c70c89627bacb11be047a10c078af2b32d972de9bc13e8bb5aaab157
|
7
|
+
data.tar.gz: 5f2dfa0644bff836637bac440b68e0805ff734e41832f976acc4e020cc27d8032e48f9d6d802b217b05333e59f1d774b2c3e049e5653807b4e64b418c1e14f37
|
data/bin/escualo
CHANGED
@@ -27,7 +27,6 @@ require_relative '../lib/commands/globals'
|
|
27
27
|
|
28
28
|
require_relative '../lib/commands/bootstrap'
|
29
29
|
require_relative '../lib/commands/deploy'
|
30
|
-
require_relative '../lib/commands/script'
|
31
30
|
require_relative '../lib/commands/upload'
|
32
31
|
require_relative '../lib/commands/rake'
|
33
32
|
|
data/lib/commands/artifact.rb
CHANGED
@@ -24,6 +24,9 @@ command 'artifact create service' do |c|
|
|
24
24
|
name = args.first
|
25
25
|
port = args.second
|
26
26
|
|
27
|
+
raise 'missing service name!' unless name
|
28
|
+
raise 'missing port!' unless port
|
29
|
+
|
27
30
|
exit_if("Service #{name} already created", options) { Escualo::Artifact.present?(session, name) }
|
28
31
|
|
29
32
|
launch_command = "exec bundle exec rackup -o 0.0.0.0 -p #{port} > rack.log"
|
@@ -58,6 +61,8 @@ command 'artifact create site' do |c|
|
|
58
61
|
|
59
62
|
c.session_action do |args, options, session|
|
60
63
|
name = args.first
|
64
|
+
raise 'missing site name!' unless name
|
65
|
+
|
61
66
|
exit_if("Site #{name} already created", options) { Escualo::Artifact.present?(session, name) }
|
62
67
|
|
63
68
|
step 'Creating init scripts...', options do
|
@@ -77,6 +82,7 @@ command 'artifact create executable' do |c|
|
|
77
82
|
|
78
83
|
c.session_action do |args, options, session|
|
79
84
|
name = args.first
|
85
|
+
raise 'missing executable name!' unless name
|
80
86
|
|
81
87
|
exit_if("Executable #{name} already created", options) { Escualo::Artifact.present?(session, name) }
|
82
88
|
step 'Creating init scripts...', options do
|
data/lib/commands/globals.rb
CHANGED
@@ -6,6 +6,7 @@ global_option '--ssh-port PORT', String, 'The ssh port to connect. Defaults to 2
|
|
6
6
|
global_option '--ssh-password PASSWORD', String, 'An optional remote password'
|
7
7
|
|
8
8
|
global_option '--dockerized', TrueClass, 'Generate a docker script instead of running the commands'
|
9
|
+
global_option '--unoptimized-dockerfile', TrueClass, 'Do not optimize commands when run dockerized'
|
9
10
|
|
10
11
|
global_option '--verbose', TrueClass, 'Dumps extra output'
|
11
12
|
|
data/lib/commands/plugin.rb
CHANGED
@@ -5,7 +5,8 @@ command 'plugin install' do |c|
|
|
5
5
|
|
6
6
|
c.option '--rabbit-admin-password PASSWORD', String, 'rabbitmq admin password, only for rabbit plugin'
|
7
7
|
|
8
|
-
c.option '--pg-
|
8
|
+
c.option '--pg-libs-only', TrueClass, 'Do not install server, only for postgres'
|
9
|
+
c.option '--pg-version VERSION', String, 'PostgreSQL major and minor version. Default is 9.3, only for postgres plugin'
|
9
10
|
c.option '--pg-username USERNAME', String, 'PostgreSQL username'
|
10
11
|
c.option '--pg-password PASSWORD', String, 'PostgreSQL password'
|
11
12
|
|
data/lib/escualo.rb
CHANGED
@@ -34,7 +34,6 @@ require_relative './escualo/apt_get'
|
|
34
34
|
require_relative './escualo/gems'
|
35
35
|
require_relative './escualo/base'
|
36
36
|
require_relative './escualo/ruby'
|
37
|
-
require_relative './escualo/script'
|
38
37
|
require_relative './escualo/plugin'
|
39
38
|
require_relative './escualo/remote'
|
40
39
|
require_relative './escualo/artifact'
|
data/lib/escualo/env.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
module Escualo
|
2
2
|
module Env
|
3
3
|
def self.setup(session)
|
4
|
-
|
5
|
-
session.tell_all! 'mkdir -p ~/.escualo/vars',
|
6
|
-
%q{echo 'for var in ~/.escualo/vars/*; do source $var; done' > ~/.escualorc},
|
7
|
-
%q{chmod u+x ~/.escualorc},
|
8
|
-
"grep -q #{source_escualorc} ~/.bashrc || echo #{source_escualorc} >> ~/.bashrc"
|
4
|
+
session.setup_environment_variables!
|
9
5
|
end
|
10
6
|
|
11
7
|
def self.set_builtins(session, options)
|
@@ -19,7 +15,8 @@ module Escualo
|
|
19
15
|
end
|
20
16
|
|
21
17
|
def self.clean(session, options)
|
22
|
-
session.
|
18
|
+
session.clean_environment_variables!
|
19
|
+
|
23
20
|
set_builtins session, options
|
24
21
|
end
|
25
22
|
|
@@ -34,17 +31,23 @@ module Escualo
|
|
34
31
|
end
|
35
32
|
|
36
33
|
def self.set(session, variables)
|
37
|
-
session.
|
34
|
+
session.set_environment_variables! variables
|
38
35
|
end
|
39
36
|
|
40
|
-
def self.
|
41
|
-
|
37
|
+
def self.unset(session, variable_names)
|
38
|
+
session.unset_environment_variables! variable_names
|
42
39
|
end
|
43
40
|
|
44
|
-
def self.
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
def self.unset_command(name)
|
42
|
+
"rm ~/.escualo/vars/#{name}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.clean_command
|
46
|
+
'rm ~/.escualo/vars/*'
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.set_command(key, value)
|
50
|
+
"echo export #{key}=#{value} > ~/.escualo/vars/#{key}"
|
48
51
|
end
|
49
52
|
|
50
53
|
def self.locale_variables
|
@@ -1,23 +1,35 @@
|
|
1
1
|
module Escualo::Plugin
|
2
2
|
class Postgres
|
3
3
|
def run(session, options)
|
4
|
-
|
5
|
-
|
4
|
+
if_server options do
|
5
|
+
raise 'missing pg-username' unless options.pg_username
|
6
|
+
raise 'missing pg-password' unless options.pg_password
|
7
|
+
end
|
6
8
|
|
7
9
|
pg_hba_conf = "/etc/postgresql/#{options.pg_version}/main/pg_hba.conf"
|
10
|
+
dependencies = options.pg_libs_only ?
|
11
|
+
"postgresql-client-#{options.pg_version} libpq-dev" :
|
12
|
+
"postgresql-#{options.pg_version} libpq-dev"
|
8
13
|
|
9
|
-
Escualo::AptGet.install session,
|
14
|
+
Escualo::AptGet.install session, dependencies
|
10
15
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
if_server options do
|
17
|
+
session.tell_all! "echo 'local all postgres peer' > #{pg_hba_conf}",
|
18
|
+
"echo 'local all postgres peer' >> #{pg_hba_conf}",
|
19
|
+
"echo 'local all all password' >> #{pg_hba_conf}",
|
20
|
+
"echo 'host all all 127.0.0.1/32 md5' >> #{pg_hba_conf}"
|
15
21
|
|
16
|
-
|
17
|
-
|
18
|
-
|
22
|
+
session.tell_all! '/etc/init.d/postgresql restart',
|
23
|
+
'cd /',
|
24
|
+
"echo \"create role #{options.pg_username} with createdb login password '#{options.pg_password}';\" | sudo -u postgres PGDATABASE='' psql"
|
25
|
+
end
|
19
26
|
end
|
20
27
|
|
28
|
+
def if_server(options)
|
29
|
+
unless options.pg_libs_only
|
30
|
+
yield
|
31
|
+
end
|
32
|
+
end
|
21
33
|
|
22
34
|
def installed?(session, options)
|
23
35
|
session.check? 'psql --version', "psql (PostgreSQL) #{options.pg_version}"
|
data/lib/escualo/session.rb
CHANGED
@@ -11,10 +11,6 @@ class Escualo::Session
|
|
11
11
|
ask(command).include? include rescue false
|
12
12
|
end
|
13
13
|
|
14
|
-
def embed!(command)
|
15
|
-
tell! command
|
16
|
-
end
|
17
|
-
|
18
14
|
def tell_all!(*commands)
|
19
15
|
tell! commands.compact.join(' && ')
|
20
16
|
end
|
@@ -33,51 +29,17 @@ class Escualo::Session
|
|
33
29
|
end
|
34
30
|
end
|
35
31
|
|
36
|
-
def
|
37
|
-
|
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
|
32
|
+
def self.set_command(key, value)
|
33
|
+
"echo export #{key}=#{value} > ~/.escualo/vars/#{key}"
|
69
34
|
end
|
70
35
|
|
71
|
-
def
|
72
|
-
|
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
|
36
|
+
def write_template!(name, template, &block)
|
37
|
+
template.with_tempfile!('template', &block)
|
78
38
|
end
|
79
39
|
end
|
80
40
|
|
81
41
|
require_relative './session/docker_session'
|
82
42
|
require_relative './session/remote_session'
|
83
43
|
require_relative './session/local_session'
|
44
|
+
require_relative './session/within'
|
45
|
+
require_relative './session/environment'
|
@@ -1,8 +1,25 @@
|
|
1
1
|
class Escualo::Session::Docker < Escualo::Session
|
2
2
|
attr_accessor :dockerfile
|
3
3
|
|
4
|
-
def
|
5
|
-
dockerfile
|
4
|
+
def unset_environment_variables!(*)
|
5
|
+
raise 'can not unset variables on dockerfile optimized mode' unless options.unoptimized_dockerfile
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def clean_environment_variables!(*)
|
10
|
+
raise 'can not clean variables on dockerfile optimized mode' unless options.unoptimized_dockerfile
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup_environment_variables!
|
15
|
+
super if options.unoptimized_dockerfile
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_environment_variables!(variables)
|
19
|
+
return super if options.unoptimized_dockerfile
|
20
|
+
variables.each do |key, value|
|
21
|
+
dockerfile << "ENV #{key} #{value}\n"
|
22
|
+
end
|
6
23
|
end
|
7
24
|
|
8
25
|
def tell!(command)
|
@@ -22,30 +39,12 @@ class Escualo::Session::Docker < Escualo::Session
|
|
22
39
|
raise 'can not ask on a docker session'
|
23
40
|
end
|
24
41
|
|
25
|
-
def start!(
|
26
|
-
|
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
|
42
|
+
def start!(_options)
|
43
|
+
@dockerfile = ''
|
41
44
|
end
|
42
45
|
|
43
|
-
def finish!(
|
44
|
-
|
45
|
-
File.write('Dockerfile', dockerfile)
|
46
|
-
else
|
47
|
-
puts dockerfile
|
48
|
-
end
|
46
|
+
def finish!(_options)
|
47
|
+
puts dockerfile
|
49
48
|
end
|
50
49
|
|
51
50
|
def self.started(options = struct)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Escualo::Session
|
2
|
+
|
3
|
+
def clean_environment_variables!
|
4
|
+
tell! Escualo::Env.clean_command
|
5
|
+
end
|
6
|
+
|
7
|
+
def setup_environment_variables!
|
8
|
+
source_escualorc = "'source ~/.escualorc'"
|
9
|
+
tell_all! 'mkdir -p ~/.escualo/vars',
|
10
|
+
%q{echo 'for var in ~/.escualo/vars/*; do source $var; done' > ~/.escualorc},
|
11
|
+
%q{chmod u+x ~/.escualorc},
|
12
|
+
"grep -q #{source_escualorc} ~/.bashrc || echo #{source_escualorc} >> ~/.bashrc"
|
13
|
+
end
|
14
|
+
|
15
|
+
def set_environment_variables!(variables)
|
16
|
+
tell_all! *variables.map { |key, value| Escualo::Env.set_command key, value }
|
17
|
+
end
|
18
|
+
|
19
|
+
def unset_environment_variables!(variable_names)
|
20
|
+
tell_all! *variable_names.map { |name| Escualo::Env.unset_command name }
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Escualo::Session
|
2
|
+
def self.parse_session_options(options)
|
3
|
+
struct username: options.username || 'root',
|
4
|
+
hostname: options.hostname || 'localhost',
|
5
|
+
ssh_options: {
|
6
|
+
keys: [options.ssh_key].compact,
|
7
|
+
port: options.ssh_port || 22
|
8
|
+
},
|
9
|
+
verbose: options.verbose,
|
10
|
+
local: options.hostname.blank? && options.username.blank? && options.ssh_key.blank? && options.ssh_port.blank?,
|
11
|
+
dockerized: options.dockerized,
|
12
|
+
unoptimized_dockerfile: options.unoptimized_dockerfile
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.within(options, force_local=false, &block)
|
17
|
+
session_options = parse_session_options options
|
18
|
+
|
19
|
+
if session_options.dockerized
|
20
|
+
within_dockerized_session session_options, options, &block
|
21
|
+
elsif session_options.local || force_local
|
22
|
+
block.call(Escualo::Session::Local.new session_options)
|
23
|
+
else
|
24
|
+
within_ssh_session(session_options, &block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.within_dockerized_session(session_options, options, &block)
|
29
|
+
session = Escualo::Session::Docker.new session_options
|
30
|
+
session.start! options
|
31
|
+
block.call(session)
|
32
|
+
session.finish! options
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.within_ssh_session(session_options, &block)
|
36
|
+
Net::SSH.start(
|
37
|
+
session_options.hostname,
|
38
|
+
session_options.username,
|
39
|
+
session_options.ssh_options) do |ssh|
|
40
|
+
block.call(Escualo::Session::Remote.new ssh, session_options)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/escualo/version.rb
CHANGED
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: 3.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-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|
@@ -142,7 +142,6 @@ files:
|
|
142
142
|
- lib/commands/plugin.rb
|
143
143
|
- lib/commands/rake.rb
|
144
144
|
- lib/commands/remote.rb
|
145
|
-
- lib/commands/script.rb
|
146
145
|
- lib/commands/upload.rb
|
147
146
|
- lib/escualo.rb
|
148
147
|
- lib/escualo/apt_get.rb
|
@@ -162,11 +161,12 @@ files:
|
|
162
161
|
- lib/escualo/ppa.rb
|
163
162
|
- lib/escualo/remote.rb
|
164
163
|
- lib/escualo/ruby.rb
|
165
|
-
- lib/escualo/script.rb
|
166
164
|
- lib/escualo/session.rb
|
167
165
|
- lib/escualo/session/docker_session.rb
|
166
|
+
- lib/escualo/session/environment.rb
|
168
167
|
- lib/escualo/session/local_session.rb
|
169
168
|
- lib/escualo/session/remote_session.rb
|
169
|
+
- lib/escualo/session/within.rb
|
170
170
|
- lib/escualo/version.rb
|
171
171
|
- lib/ssh.rb
|
172
172
|
- lib/template.rb
|
data/lib/commands/script.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
command 'script' do |c|
|
2
|
-
c.syntax = 'escualo script <FILE>'
|
3
|
-
c.description = 'Runs a escualo configuration'
|
4
|
-
c.option '--dockerized', TrueClass, 'Create a Dockerfile instead of running commands'
|
5
|
-
c.option '--write-dockerfile', TrueClass, 'Write a complete Dockerfile instead of writing to stdout. Default is false'
|
6
|
-
c.option '--dockerfile PATH', String, 'Destination Dockerfile. Default is `Dockerfile`'
|
7
|
-
c.option '--development', TrueClass, 'Use local escualo gemspec instead of fetching from internet'
|
8
|
-
c.option '--base-image BASE_IMAGE', String, 'Default base image. Only for dockerized runs'
|
9
|
-
|
10
|
-
c.action do |args, options|
|
11
|
-
options.default base_image: 'ubuntu',
|
12
|
-
dockerfile: 'Dockerfile'
|
13
|
-
file = YAML.load_file args.first
|
14
|
-
delegated_options = Escualo::Script.delegated_options options
|
15
|
-
|
16
|
-
Escualo::Session.within(options, true) do |session|
|
17
|
-
Escualo::Script.run!(session, $PROGRAM_NAME, file, delegated_options)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/escualo/script.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
module Escualo
|
2
|
-
module Script
|
3
|
-
def self.commands(escualo, script, extra)
|
4
|
-
(script||[]).map { |it| "#{escualo} #{it} #{extra}" }
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.delegated_options(options)
|
8
|
-
[options.hostname.try { |it| "--hostname #{it}" },
|
9
|
-
options.username.try { |it| "--username #{it}" },
|
10
|
-
options.password.try { |it| "--ssh-password #{it}" },
|
11
|
-
options.ssh_key.try { |it| "--ssh-key #{it}" },
|
12
|
-
options.ssh_port.try { |it| "--ssh-port #{it}" },
|
13
|
-
options.trace && '--trace',
|
14
|
-
options.verbose && '--verbose',
|
15
|
-
].compact.join(' ')
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.run!(session, escualo, script, extra='')
|
19
|
-
Escualo::Script.commands(escualo, script, extra).each do |command|
|
20
|
-
session.embed! command
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|