foreplay 0.9.9 → 0.9.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54fa14c8cd58bcbcfa3d6ae58721785d2cbedf60
4
- data.tar.gz: 78bfd857d56736431725d9d3b9eddc307f327c85
3
+ metadata.gz: 890c4c0d5051375ad322d3de7434723c50f8c547
4
+ data.tar.gz: 012197386d009fae9f671ec6dcfbc5ab1325f041
5
5
  SHA512:
6
- metadata.gz: df13a59675a8e854d44d4b09c85723af3d8ef482c1fd726a5f3c1dd7169d5d0e17b77b8b4a6088fe122c74a6942dc42989ae44a4cf6edfe2bb0ee4f5a6d59dab
7
- data.tar.gz: d98356701a491e17c6beea0abeedf0530515f13f6952bb3278d289089990a87b984fbf64bcf3e91671f7cc2658acca1f3737eb1609f31078ab0239ec52c53266
6
+ metadata.gz: 9291d32cb558210be93527cd3c04e442f842ee23e6971b2160bf7a8caab8697d79e6c33472bd4d05684061d42f056e74f228bb720578ae8b4149a51be469635a
7
+ data.tar.gz: b333b86d8fc828e3161913b57f0dd1e6a945c08757d45bff0543cb21e20835e2b7f48f0c6816724ec6c76b2bacbc81082fb3c7f9b3afcc15d35e654f5b7e3aad
data/lib/foreplay/cli.rb CHANGED
@@ -8,6 +8,7 @@ class Foreplay::CLI < Thor
8
8
  method_option :role, aliases: '-r'
9
9
  method_option :server, aliases: '-s'
10
10
  method_option :config_file, aliases: '-f'
11
+ method_option :verbose, aliases: '-v'
11
12
 
12
13
  def deploy(environment)
13
14
  Foreplay::Launcher.start [:deploy, environment, options]
@@ -18,6 +19,7 @@ class Foreplay::CLI < Thor
18
19
  method_option :role, aliases: '-r'
19
20
  method_option :server, aliases: '-s'
20
21
  method_option :config_file, aliases: '-f'
22
+ method_option :verbose, aliases: '-v'
21
23
 
22
24
  def check(environment)
23
25
  Foreplay::Launcher.start [:check, environment, options]
@@ -0,0 +1,45 @@
1
+ class Foreplay::Engine::Logger
2
+ INDENT = 4
3
+ MARGIN = 24
4
+
5
+ attr_reader :message, :options
6
+
7
+ def initialize(m, o = {})
8
+ @message = m
9
+ @options = o
10
+
11
+ output
12
+ end
13
+
14
+ def output
15
+ puts formatted_message unless silent?
16
+ end
17
+
18
+ def formatted_message
19
+ @formatted_message ||= header + message.gsub(/\s+\z/, '').gsub(/(\r\n*)/, "\\1#{margin}")
20
+ end
21
+
22
+ def header
23
+ @header ||= (margin_format % header_content[0, margin_width - 1]).white
24
+ end
25
+
26
+ def header_content
27
+ @header_content ||= (options[:host] || '')
28
+ end
29
+
30
+ def margin
31
+ @margin ||= margin_format % ''
32
+ end
33
+
34
+ def silent?
35
+ @silent ||= (options[:silent] == true) || message.blank?
36
+ end
37
+
38
+ def margin_width
39
+ @margin_width ||= MARGIN + INDENT * (options[:indent] || 0)
40
+ end
41
+
42
+ def margin_format
43
+ @margin_format ||= "%-#{margin_width}s"
44
+ end
45
+ end
@@ -46,9 +46,9 @@ module Foreplay::Engine::Port
46
46
  current_port_string = Foreplay::Engine::Remote.new(server, port_steps, instructions).__send__(mode).strip!
47
47
 
48
48
  if current_port_string.blank?
49
- puts "#{host}#{INDENT}No instance is currently deployed"
49
+ log 'No instance is currently deployed', host: host
50
50
  else
51
- puts "#{host}#{INDENT}Current instance is using port #{current_port_string}"
51
+ log "Current instance is using port #{current_port_string}", host: host
52
52
  end
53
53
 
54
54
  cp = current_port_string.to_i
@@ -10,7 +10,7 @@ class Foreplay::Engine::Remote::Check
10
10
 
11
11
  def perform
12
12
  steps.each do |step|
13
- puts "#{host}#{INDENT}#{(step['commentary'] || step['command']).yellow}" unless step['silent'] == true
13
+ log "#{(step['commentary'] || step['command']).yellow}", host: host, silent: step['silent']
14
14
 
15
15
  if step.key? 'key'
16
16
  list_file_contents step['key']
@@ -26,17 +26,17 @@ class Foreplay::Engine::Remote::Check
26
26
  i = instructions[id]
27
27
 
28
28
  if i.is_a? Hash
29
- i.each { |k, v| puts "#{host}#{INDENT * 2}#{k}: #{v}" }
29
+ i.each { |k, v| log "#{k}: #{v}", host: host, indent: 1 }
30
30
  else
31
- puts "#{host}#{INDENT * 2}#{i}"
31
+ log i, host: host, indent: 1
32
32
  end
33
33
  end
34
34
 
35
35
  def list_commands(step)
36
- commands = Foreplay::Engine::Step.new(step, instructions).build
36
+ commands = Foreplay::Engine::Step.new(host, step, instructions).commands
37
37
 
38
38
  commands.each do |command|
39
- puts "#{host}#{INDENT * 2}#{command}" unless step['silent']
39
+ log command, host: host, silent: step['silent']
40
40
  end
41
41
  end
42
42
  end
@@ -10,21 +10,26 @@ class Foreplay::Engine::Remote::Step
10
10
  end
11
11
 
12
12
  def execute
13
- puts "#{host}#{INDENT}#{(step['commentary'] || step['command']).yellow}" unless step['silent'] == true
14
- output Foreplay::Engine::Step.new(step, instructions).build.map { |command| execute_command(command) }.join
13
+ s = Foreplay::Engine::Step.new(host, step, instructions)
14
+ s.announce
15
+ output s.commands.map { |command| execute_command(command) }.join
15
16
  end
16
17
 
17
18
  def execute_command(command)
18
19
  o = ''
19
20
  process = shell.execute command
20
- process.on_output { |_, po| o = po }
21
+ process.on_output { |_, po| o += po }
21
22
  shell.wait!
22
23
  terminate(o) unless step['ignore_error'] == true || process.exit_status == 0
23
24
  o
24
25
  end
25
26
 
27
+ def silent
28
+ @silent ||= instructions['verbose'] ? false : step['silent']
29
+ end
30
+
26
31
  def output(o)
27
- puts o.gsub!(/^/, "#{host}#{INDENT * 2}") unless step['silent'] == true || o.blank?
32
+ log o, host: host, silent: silent, indent: 1
28
33
  o
29
34
  end
30
35
  end
@@ -14,12 +14,12 @@ class Foreplay::Engine::Remote
14
14
  def deploy
15
15
  output = ''
16
16
 
17
- puts "#{host}#{INDENT}Connecting to #{host} on port #{port}"
17
+ log "Connecting to #{host} on port #{port}", host: host
18
18
 
19
19
  # SSH connection
20
20
  session = start_session(host, user, options)
21
21
 
22
- puts "#{host}#{INDENT}Successfully connected to #{host} on port #{port}"
22
+ log "Successfully connected to #{host} on port #{port}", host: host
23
23
 
24
24
  session.shell do |sh|
25
25
  steps.each { |step| output += Foreplay::Engine::Remote::Step.new(host, sh, step, instructions).execute }
@@ -80,13 +80,13 @@ class Foreplay::Engine::Remote
80
80
  ) if keyfile.blank?
81
81
 
82
82
  # Get the key from the key file
83
- puts "#{INDENT}Using private key from #{keyfile}"
83
+ log "Using private key from #{keyfile}"
84
84
  File.read keyfile
85
85
  end
86
86
 
87
87
  def start_session(host, user, options)
88
88
  Net::SSH.start(host, user, options)
89
89
  rescue SocketError => e
90
- terminate "#{host}#{INDENT}There was a problem starting an ssh session on #{host}:\n#{e.message}"
90
+ terminate "There was a problem starting an ssh session on #{host}:\n#{e.message}"
91
91
  end
92
92
  end
@@ -1,3 +1,5 @@
1
+ require 'pp' # debug
2
+
1
3
  class Foreplay::Engine::Secrets
2
4
  attr_reader :environment, :secret_locations
3
5
 
@@ -15,6 +17,7 @@ class Foreplay::Engine::Secrets
15
17
  secrets.merge! fetch_from(secret_location) || {}
16
18
  end
17
19
 
20
+ pp secrets # debug
18
21
  secrets
19
22
  end
20
23
 
@@ -24,6 +27,7 @@ class Foreplay::Engine::Secrets
24
27
  headers = secret_location['headers']
25
28
  header_string = headers.map { |k, v| " -H \"#{k}: #{v}\"" }.join if headers.is_a? Hash
26
29
  command = "curl -k -L#{header_string} #{url}".fake_erb
30
+ puts command.magenta # debug
27
31
  secrets_all = YAML.load(`#{command}`)
28
32
  secrets = secrets_all[environment]
29
33
 
@@ -1,24 +1,32 @@
1
1
  class Foreplay::Engine::Step
2
- attr_reader :step, :instructions
2
+ include Foreplay
3
+ attr_reader :host, :step, :instructions
3
4
 
4
- def initialize(s, i)
5
+ def initialize(h, s, i)
6
+ @host = h
5
7
  @step = s
6
8
  @instructions = i
7
9
  end
8
10
 
9
- def build
11
+ def commands
12
+ return @commands if @commands
13
+
10
14
  # Each step can be (1) a command or (2) a series of values to add to a file
11
15
  if step.key?('key')
12
- instructions.key?(step['key']) ? commands : []
16
+ if instructions.key?(step['key'])
17
+ build_commands
18
+ else
19
+ @commands = []
20
+ end
13
21
  else
14
22
  # ...or just execute the command specified
15
- [step['command']]
23
+ @commands = [command]
16
24
  end
17
- end
18
25
 
19
- def commands
20
- return @commands if @commands
26
+ @commands
27
+ end
21
28
 
29
+ def build_commands
22
30
  step['silent'] = true
23
31
 
24
32
  if header?
@@ -33,8 +41,6 @@ class Foreplay::Engine::Step
33
41
  else
34
42
  build_commands_from_string
35
43
  end
36
-
37
- @commands
38
44
  end
39
45
 
40
46
  def build_commands_from_hash
@@ -56,6 +62,10 @@ class Foreplay::Engine::Step
56
62
  end
57
63
  end
58
64
 
65
+ def command
66
+ @command ||= step['command']
67
+ end
68
+
59
69
  def filename
60
70
  @filename ||= "#{path}#{prefix}#{key}#{suffix}"
61
71
  end
@@ -95,4 +105,13 @@ class Foreplay::Engine::Step
95
105
  def header?
96
106
  header.present?
97
107
  end
108
+
109
+ def silent
110
+ @silent ||= step['silent']
111
+ end
112
+
113
+ def announce
114
+ log "#{(step['commentary'] || command).yellow}", host: host, silent: silent
115
+ log command.cyan, host: host, silent: silent if instructions['verbose'] && step['commentary'] && command
116
+ end
98
117
  end
@@ -42,12 +42,12 @@
42
42
  commentary: 'Building config/resque.yml'
43
43
  before: environment
44
44
  path: 'config/'
45
- - command: 'if [ -d ../cache/vendor/bundle/bundle ] ; then rm -rf ../cache/vendor/bundle/bundle ; else echo No evidence of legacy copy bug ; fi'
46
- commentary: 'Fixing legacy copy bug'
47
45
  - command: 'if [ -d ../cache/vendor/bundle ] ; then rsync -aW --no-compress --delete --info=STATS1 ../cache/vendor/bundle/ vendor/bundle ; else echo No bundle to restore ; fi'
48
46
  commentary: 'Attempting to restore bundle from cache'
49
47
  - command: 'sudo ln -f `which bundle` /usr/bin/bundle || echo Using default version of bundle'
50
48
  commentary: 'Setting the current version of bundle to be the default'
49
+ - command: "gem install bundler -v '> 1.8'"
50
+ commentary: 'Updating the bundler version'
51
51
  - command: 'bundle install --deployment --clean --jobs 2 --without development test'
52
52
  commentary: 'Using bundler to install the required gems in deployment mode'
53
53
  - command: 'mkdir -p ../cache/vendor && rsync -aW --no-compress --delete --info=STATS1 vendor/bundle/ ../cache/vendor/bundle'
@@ -1,6 +1,7 @@
1
1
  require 'yaml'
2
2
  require 'string'
3
3
  require 'hash'
4
+ require 'pp' # debug
4
5
 
5
6
  class Foreplay::Engine
6
7
  include Foreplay
@@ -51,9 +52,10 @@ class Foreplay::Engine
51
52
  end
52
53
 
53
54
  def build_instructions(role, additional_instructions)
54
- instructions = defaults.supermerge(additional_instructions)
55
- instructions['role'] = role
56
- required_keys = %w(name environment role servers path repository)
55
+ instructions = defaults.supermerge(additional_instructions)
56
+ instructions['role'] = role
57
+ instructions['verbose'] = verbose
58
+ required_keys = %w(name environment role servers path repository)
57
59
 
58
60
  required_keys.each do |key|
59
61
  next if instructions.key? key
@@ -87,7 +89,7 @@ class Foreplay::Engine
87
89
 
88
90
  @defaults['env'].merge! secrets
89
91
  @defaults['application'] = secrets
90
-
92
+ pp @defaults # debug
91
93
  @defaults = @defaults.supermerge(roles_all[DEFAULTS_KEY]) if roles_all.key? DEFAULTS_KEY
92
94
  @defaults = @defaults.supermerge(roles[DEFAULTS_KEY]) if roles.key? DEFAULTS_KEY
93
95
  @defaults
@@ -98,6 +100,10 @@ class Foreplay::Engine
98
100
  @secrets ||= Foreplay::Engine::Secrets.new(environment, roles_all['secrets']).fetch || {}
99
101
  end
100
102
 
103
+ def verbose
104
+ @verbose ||= filters.key?('verbose')
105
+ end
106
+
101
107
  def roles
102
108
  @roles ||= roles_all[environment]
103
109
  end
@@ -1,5 +1,7 @@
1
1
  module Foreplay
2
- INDENT = "\t"
2
+ def log(message, options = {})
3
+ Foreplay::Engine::Logger.new(message, options)
4
+ end
3
5
 
4
6
  def terminate(message)
5
7
  fail message
@@ -3,9 +3,9 @@ require 'thor/group'
3
3
  class Foreplay::Launcher < Thor::Group
4
4
  include Thor::Actions
5
5
 
6
- argument :mode, type: :string, required: true
7
- argument :environment, type: :string, required: true
8
- argument :filters, type: :hash, required: false
6
+ argument :mode, type: :string, required: true
7
+ argument :environment, type: :string, required: true
8
+ argument :filters, type: :hash, required: false
9
9
 
10
10
  def parse
11
11
  Foreplay::Engine.new(environment, filters).__send__ mode
@@ -1,3 +1,3 @@
1
1
  module Foreplay
2
- VERSION = '0.9.9'
2
+ VERSION = '0.9.10'
3
3
  end
data/lib/foreplay.rb CHANGED
@@ -5,6 +5,7 @@ require 'foreplay/engine'
5
5
  require 'foreplay/engine/remote'
6
6
  require 'foreplay/engine/remote/check'
7
7
  require 'foreplay/engine/remote/step'
8
+ require 'foreplay/engine/logger'
8
9
  require 'foreplay/engine/port'
9
10
  require 'foreplay/engine/role'
10
11
  require 'foreplay/engine/secrets'
@@ -150,8 +150,6 @@ describe Foreplay::Launcher do
150
150
  'echo " host: TODO Put here the database host name" >> config/database.yml',
151
151
  'echo " username: TODO Put here the database user" >> config/database.yml',
152
152
  'echo " password: TODO Put here the database user\'s password" >> config/database.yml',
153
- 'if [ -d ../cache/vendor/bundle/bundle ] ; then rm -rf ../cache/vendor/bundle/bundle'\
154
- ' ; else echo No evidence of legacy copy bug ; fi',
155
153
  'if [ -d ../cache/vendor/bundle ] ; then '\
156
154
  'rsync -aW --no-compress --delete --info=STATS1 ../cache/vendor/bundle/ vendor/bundle'\
157
155
  ' ; else echo No bundle to restore ; fi',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreplay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
4
+ version: 0.9.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xenapto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-07 00:00:00.000000000 Z
11
+ date: 2015-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: foreman
@@ -222,6 +222,7 @@ files:
222
222
  - lib/foreplay.rb
223
223
  - lib/foreplay/cli.rb
224
224
  - lib/foreplay/engine.rb
225
+ - lib/foreplay/engine/logger.rb
225
226
  - lib/foreplay/engine/port.rb
226
227
  - lib/foreplay/engine/remote.rb
227
228
  - lib/foreplay/engine/remote/check.rb