ssp 0.6.2 → 0.6.3

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.
@@ -25,20 +25,53 @@ class SSP::App::Chef < Thor
25
25
 
26
26
  desc "deploy APP", "Runs chef-client with deployment enabled for the application on the right node"
27
27
  method_options %w( production -P ) => false, %w( migrate -m ) => true,
28
- %w( rollback -r ) => false, %w( force -f ) => false
28
+ %w( rollback -r) => false, %w( force -f ) => false
29
+ method_option :revision, :aliases => "-R",
30
+ :desc => "Revision to deploy to. Previous relative release (1..4) or specific revision. In rollback mode (-r) this defaults to 1."
29
31
  def deploy(app)
30
32
  if options[:ssh_user] == "root"
31
33
  raise Thor::Error, "You cannot deploy directly with the root user, use the -u option to specify your user"
32
34
  end
33
35
  chef_config
34
36
  node = "#{options[:production] ? "#{app}-app-01" : "sage"}.sspti.me"
35
- command = "sudo chef-client -V -l debug -L /tmp/#{app}_deploy_chef_run.#{Time.now.strftime("%Y%m%d%H%M")}.log | grep --line-buffered '\\[[^]]*\\] [A-Z]*:' | grep -v DEBUG:"
37
+ debug_log = "/tmp/#{app}_deploy_chef_run.#{Time.now.strftime("%Y%m%d%H%M")}.log"
38
+ command = "sudo chef-client -V -l debug -L #{debug_log} | grep --line-buffered '\\[[^]]*\\] [A-Z]*:' | grep -v DEBUG:"
36
39
 
37
40
  env = options[:production] ? "production" : "staging"
38
- deploy_action = options[:rollback] ? "rollback" : options[:force] ? "force_deploy" : "deploy"
39
- with_updated_bag(app, env, :deploy_action => deploy_action, :migrate => options[:migrate]) do
41
+ bag_override = { :migrate => options[:migrate] }
42
+ case rev = options[:revision] || ("1" if options[:rollback])
43
+ when *%w(1 2 3 4)
44
+ all_releases = JSON.parse(%x{ssh #{options[:ssh_user]}@#{node} cat /srv/chef/cache/revision-deploys/#{app}}) rescue []
45
+ all_releases.map! {|r| File.basename(r)}
46
+ bag_override[:revision] = all_releases[-rev.to_i-1]
47
+ raise Thor::Error, "Couldn't find revision #{options[:revision]}" unless bag_override[:revision]
48
+ when String
49
+ bag_override[:revision] = options[:revision]
50
+ end
51
+ bag_override[:deploy_action] =
52
+ if options[:rollback]
53
+ "rollback"
54
+ elsif options[:force]
55
+ "force_deploy"
56
+ else
57
+ "deploy"
58
+ end
59
+
60
+ with_updated_bag(app, env, bag_override) do |bag|
61
+ say <<-EOS.gsub(/\s+/, ' ').strip
62
+ #{bag_override[:deploy_action].tr('_', ' ').capitalize}ing
63
+ #{shell.set_color(app, :green)}
64
+ #{'to' if options[:rollback]} revision
65
+ #{shell.set_color(bag_override[:revision] || bag['revision'][env], :yellow)}
66
+ as #{shell.set_color(options[:ssh_user], :blue)}
67
+ on #{shell.set_color(node, :cyan)}
68
+ EOS
69
+
40
70
  ssh_run(node, command)
41
71
  end
72
+
73
+ ensure
74
+ say "Debug log of Chef run written to #{node}:#{debug_log}"
42
75
  end
43
76
 
44
77
  private
@@ -86,11 +119,13 @@ class SSP::App::Chef < Thor
86
119
  end
87
120
  bag.save
88
121
 
89
- yield
90
-
91
- attributes.each do |key, value|
92
- bag.raw_data[key.to_s] = original_values[key.to_s]
122
+ begin
123
+ yield(bag)
124
+ ensure
125
+ attributes.each do |key, value|
126
+ bag.raw_data[key.to_s] = original_values[key.to_s]
127
+ end
128
+ bag.save
93
129
  end
94
- bag.save
95
130
  end
96
131
  end
@@ -79,7 +79,7 @@ class SSP::App::Remote < Thor
79
79
  def log(logfile)
80
80
  @working_dir = options[:cwd] || options[:node] == "dtm-db-2" ? "/srv/rsyslog" : "/var/log"
81
81
  @working_dir += '/' + options[:host] if options[:host]
82
- @working_dir += '/' + options[:date].tr('-', '/')
82
+ @working_dir += '/' + options[:date].tr('-', '/') if options[:node] == "dtm-db-2"
83
83
 
84
84
  @dont_print_hosts = true
85
85
  tail = "-f " if options[:date] == Time.now.utc.strftime("%Y-%m-%d")
data/lib/ssp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SSP
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 6
8
- - 2
9
- version: 0.6.2
8
+ - 3
9
+ version: 0.6.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - "L\xC3\xA1szl\xC3\xB3 B\xC3\xA1csi"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-22 00:00:00 +02:00
17
+ date: 2010-10-25 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency