escualo 0.8.0 → 0.9.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2311d5bcbd817cbed4b83e76cbf0186a48d10854
4
- data.tar.gz: 51835791f32711753d833276c54c11ebc1bf700c
3
+ metadata.gz: 59841e0d8f38aefbe2fd5639987a7a9ebc98e83b
4
+ data.tar.gz: 4bfefa0fa63748a7af08e6daf8efc2f30522f174
5
5
  SHA512:
6
- metadata.gz: 13c4f2ee302e8f8f1c61ce235d5df7e9a2661e230f07c24f527452c9c7057cce2cd7071062057ca9e66100f3eb1a9be792c80c711836bf45c60ba4d11396911e
7
- data.tar.gz: b6c2495418d878d3f722316acbe8710f92ea264eb44c497fd8ed84449c1366580ae4b79d64fc07000215ce286835744978f21f8dbd700a75e3d0534741fc02db
6
+ metadata.gz: c3439fcb6720ff05c6fbc9aa5772c6de4794406ce3fcaccbac8bbf925b3d2bc31fc73094dc3c0057f72f527a796309478a4376c47cd8613d0257be9d27b43b1e
7
+ data.tar.gz: d4f1073f77f625d182caa5ce9f811f726c658e6030f8683db3a0a77d569f102efbc3dbe8bb832292fefee23f4937a9b61498848de0affc830ae8904f64c40e51
@@ -19,13 +19,11 @@ command 'plugin install' do |c|
19
19
  options do
20
20
 
21
21
  step "Installing plugin #{plugin}" do
22
- log = installer.run ssh, options
23
- end
24
-
25
- if installer.check ssh, options
26
- say 'Installed successfully!'
27
- else
28
- say "Something went wrong"
22
+ if Escualo::Plugin.run_and_check installer, ssh, options
23
+ say 'Installed successfully!'
24
+ else
25
+ say "Something went wrong"
26
+ end
29
27
  end
30
28
  end
31
29
  end
@@ -1,30 +1,38 @@
1
- def run_commands_for!(script, extra='', ssh, options)
2
- Escualo::Script.each_command script, extra do |command|
3
- puts "Running `#{command}`"
4
- ssh.shell.perform! command, options
5
- end
6
- end
7
-
8
1
  command 'script' do |c|
9
2
  c.syntax = 'escualo script <FILE>'
10
3
  c.description = 'Runs a escualo configuration'
4
+ c.option '--dockerized', TrueClass, 'Create a Dockerfile instead of running commands'
5
+ c.option '--base-image BASE_IMAGE', String, 'Default base image. Only for dockerized runs'
6
+
11
7
  c.action do |args, options|
8
+ options.default base_image: 'ubuntu'
9
+
10
+ if options.dockerized
11
+ mode = Escualo::Script::Dockerized.new
12
+ else
13
+ mode = Escualo::Script::Standard.new
14
+ end
15
+
16
+ mode.start! options
17
+
12
18
  file = YAML.load_file args.first
13
19
  local_ssh = Net::SSH::Connection::LocalSession.new
14
20
  delegated_options = Escualo::Script.delegated_options options
15
21
 
16
22
  step 'Running local commands...' do
17
- run_commands_for! file['local'], delegated_options, local_ssh, options
23
+ mode.run_commands_for! file['local'], delegated_options, local_ssh, options
18
24
  end
19
25
 
20
26
  step 'Running remote commands...' do
21
27
  Net::SSH.with_session(ssh_session_options) do |ssh|
22
- run_commands_for! file['remote'], ssh, options
28
+ mode.run_commands_for! file['remote'], ssh, options
23
29
  end
24
30
  end
25
31
 
26
32
  step 'Running deploy commands...' do
27
- run_commands_for! file['deploy'], delegated_options, local_ssh, options
33
+ mode.run_commands_for! file['deploy'], delegated_options, local_ssh, options
28
34
  end
35
+
36
+ mode.finish!
29
37
  end
30
38
  end
@@ -28,13 +28,11 @@ module Escualo
28
28
  }, options
29
29
  ssh.shell.perform! 'rbenv install 2.3.1 && rbenv global 2.3.1 && rbenv rehash', options
30
30
  else
31
- ssh.shell.perform! %q{
31
+ ssh.shell.perform! %Q{
32
32
  apt-get install software-properties-common -y &&
33
- apt-add-repository ppa:brightbox/ruby-ng &&
33
+ apt-add-repository #{Escualo::PPA.for 'brightbox/ruby-ng'} &&
34
34
  apt-get update &&
35
- apt-get install -y \
36
- ruby2.3 \
37
- ruby2.3-dev
35
+ apt-get install -y ruby2.3 ruby2.3-dev
38
36
  }, options
39
37
  end
40
38
  end
data/lib/escualo/env.rb CHANGED
@@ -37,10 +37,14 @@ module Escualo
37
37
 
38
38
  def self.set(ssh, variables)
39
39
  variables.each do |key, value|
40
- ssh.exec!("echo 'export #{key}=#{value}' > ~/.escualo/vars/#{key}")
40
+ ssh.exec!(set_command key, value)
41
41
  end
42
42
  end
43
43
 
44
+ def self.set_command(key, value)
45
+ "echo export #{key}=#{value} > ~/.escualo/vars/#{key}"
46
+ end
47
+
44
48
  def self.unset(ssh, variable_names)
45
49
  variable_names.each do |name|
46
50
  ssh.exec!("rm ~/.escualo/vars/#{name}")
@@ -4,10 +4,10 @@ module Escualo::Plugin
4
4
  config = options.nginx_conf.try { |it| File.read it }
5
5
 
6
6
  ssh.perform! %Q{
7
- sudo add-apt-repository ppa:nginx/stable && \
8
- sudo apt-get update && \
9
- sudo apt-get install nginx -y && \
10
- #{config ? "/etc/nginx/nginx.conf < cat #{config} && " : ''} \
7
+ sudo add-apt-repository #{Escualo::PPA.for 'nginx/stable'} &&
8
+ sudo apt-get update &&
9
+ sudo apt-get install nginx -y &&
10
+ #{config ? "/etc/nginx/nginx.conf < cat #{config} && " : ''}
11
11
  service nginx restart
12
12
  }, options
13
13
  end
@@ -5,6 +5,11 @@ module Escualo
5
5
  def self.load(name)
6
6
  "Escualo::Plugin::#{name.capitalize}".constantize.new
7
7
  end
8
+
9
+ def self.run_and_check(plugin, ssh, options)
10
+ plugin.run ssh, options
11
+ plugin.check ssh, options
12
+ end
8
13
  end
9
14
  end
10
15
 
@@ -0,0 +1,5 @@
1
+ module Escualo::PPA
2
+ def self.for(name)
3
+ "deb http://ppa.launchpad.net/#{name}/ubuntu trusty main"
4
+ end
5
+ end
@@ -2,10 +2,18 @@ module Escualo
2
2
  module Remote
3
3
  def self.attach(dir, name)
4
4
  remote_name = "escualo-#{name}-#{$hostname}"
5
- remote_url = "ssh://#{$username}@#{$hostname}:#{$ssh_port}/var/repo/#{name}.git"
5
+ remote_url = remote_git_url(name)
6
6
  %x{cd #{dir} && git remote add #{remote_name} #{remote_url}}
7
7
  end
8
8
 
9
+ def self.remote_git_url(name)
10
+ if $ssh_remote
11
+ "ssh://#{$username}@#{$hostname}:#{$ssh_port}/var/repo/#{name}.git"
12
+ else
13
+ "/var/repo/#{name}.git"
14
+ end
15
+ end
16
+
9
17
  def self.clone(dir, repo, options)
10
18
  repo_url = "https://github.com/#{repo}"
11
19
  %x{git clone #{repo_url} #{dir}}
@@ -14,6 +14,57 @@ module Escualo
14
14
  options.verbose && '--verbose'
15
15
  ].compact.join(' ')
16
16
  end
17
+
18
+ class Mode
19
+ def run_commands_for!(script, extra='', ssh, options)
20
+ Escualo::Script.each_command script, extra do |command|
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
+ RUN gem install escualo
47
+ "
48
+ end
49
+
50
+ def base_image(options)
51
+ if options.base_image == 'ubuntu'
52
+ 'ubuntu:xenial'
53
+ elsif options.base_image == 'debian'
54
+ 'debian:jessie'
55
+ else
56
+ raise "Unsupported base image #{options.base_image}. Only debian and ubuntu are supported"
57
+ end
58
+ end
59
+
60
+ def run_command!(command, ssh, options)
61
+ @dockerfile << "RUN #{command}\n"
62
+ end
63
+
64
+ def finish!
65
+ File.write('Dockerfile', @dockerfile)
66
+ end
67
+ end
17
68
  end
18
69
  end
19
70
 
@@ -1,4 +1,4 @@
1
1
  module Escualo
2
- VERSION = '0.8.0'
2
+ VERSION = '0.9.0'
3
3
  BASE_VERSION = '3.2'
4
4
  end
data/lib/escualo.rb CHANGED
@@ -18,6 +18,7 @@ require_relative './ssh'
18
18
 
19
19
  require_relative './escualo/version'
20
20
  require_relative './escualo/env'
21
+ require_relative './escualo/ppa'
21
22
  require_relative './escualo/bootstrap'
22
23
  require_relative './escualo/script'
23
24
  require_relative './escualo/plugin'
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: 0.8.0
4
+ version: 0.9.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-06 00:00:00.000000000 Z
11
+ date: 2016-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -142,6 +142,7 @@ files:
142
142
  - lib/escualo/plugin/node.rb
143
143
  - lib/escualo/plugin/postgre.rb
144
144
  - lib/escualo/plugin/rabbit.rb
145
+ - lib/escualo/ppa.rb
145
146
  - lib/escualo/remote.rb
146
147
  - lib/escualo/script.rb
147
148
  - lib/escualo/version.rb