heroku-bartender 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,9 +13,17 @@ Server options:
13
13
  -t, --target=TARGET The target is the git remote in which you want to deploy (default heroku)
14
14
  --user=USER The user to login using HTTP Basic Auth
15
15
  --password=PASSWORD The password to login using HTTP Basic Auth
16
-
16
+ -c, --commits=COUNT The maximum number of commits to display (default 100)
17
17
 
18
18
  For now you must run `heroku-bartender` inside your repo dir
19
+
20
+ ## Specifying a Pre-Deploy Command
21
+
22
+ You can specify a command to run before deployment.
23
+
24
+ git config --add remote.master.predeploy "rake test"
25
+
26
+
19
27
  # Features
20
28
  1. You can rollback your heroku app to a specific commit hash
21
29
  2. You can secure your heroku-bartender server using HTTP Basic Auth
@@ -25,7 +33,7 @@ For now you must run `heroku-bartender` inside your repo dir
25
33
  6. Shows colors/status for old deployed versions (only the versions that are deployed from the start)
26
34
 
27
35
  # TODO
28
- 1. Keep update the repo
36
+ 1. Keep the repo up-to-date
29
37
  2. Handle branches/tags
30
38
  3. DB Rollback
31
39
  4. Styling view
@@ -27,13 +27,13 @@ Choice.options do
27
27
  end
28
28
 
29
29
  option :user do
30
- d = ''
30
+ d = nil
31
31
  long '--user=USER'
32
32
  desc "The user to login using HTTP Basic Auth"
33
33
  default d
34
34
  end
35
35
  option :password do
36
- d = ''
36
+ d = nil
37
37
  long '--password=PASSWORD'
38
38
  desc "The password to login using HTTP Basic Auth"
39
39
  end
@@ -48,6 +48,15 @@ Choice.options do
48
48
  desc "The target is the git remote in which you want to deploy (default #{d})"
49
49
  default d
50
50
  end
51
+
52
+ option :commits do
53
+ d = 100
54
+ short '-c'
55
+ long '--commits=COUNT'
56
+ desc "The maximum number of commits to show (default #{d})"
57
+ default d
58
+ end
59
+
51
60
  option :help do
52
61
  long '--help'
53
62
  desc 'Show this message'
@@ -66,9 +75,5 @@ end
66
75
 
67
76
  options = Choice.choices
68
77
 
78
+ Heroku::Bartender::Server.start(options)
69
79
 
70
- Heroku::Bartender::Server.start(options[:host],
71
- options[:port],
72
- options[:target],
73
- options[:user],
74
- options[:password])
@@ -1,3 +1,4 @@
1
+ require "heroku/bartender/config"
1
2
  require "heroku/bartender/commit"
2
3
  require "heroku/bartender/log"
3
4
  require "heroku/bartender/command"
@@ -2,7 +2,7 @@ require 'grit'
2
2
  module Heroku
3
3
  module Bartender
4
4
  class Command
5
-
5
+
6
6
  def self.current_version(heroku_remote)
7
7
  repo = Grit::Repo.new('.')
8
8
  if repo.remote_list.include?(heroku_remote)
@@ -10,20 +10,33 @@ module Heroku
10
10
  end
11
11
  nil
12
12
  end
13
+
13
14
  def self.sha_exist?(sha)
14
15
  if sha and not `git show #{sha}`.empty?
15
16
  return true
16
17
  end
17
18
  false
18
19
  end
19
- # move to an specific commit
20
- def self.move_to release, heroku_remote
20
+
21
+ def self.move_to release, predeploy, heroku_remote
22
+ @@last_error = nil
23
+ if ! predeploy.nil?
24
+ rc = system(predeploy)
25
+ if rc.nil? || ! rc
26
+ raise "Error executing '#{predeploy}': #{$?}"
27
+ end
28
+ end
21
29
  repo = Grit::Repo.new('.')
22
- if repo.remote_list.include?(heroku_remote) && sha_exist?(release)
23
- `git push -f #{heroku_remote} #{release}:master`
24
- return true
30
+ if ! repo.remote_list.include?(heroku_remote)
31
+ raise "No such remote `#{heroku_remote}`"
32
+ end
33
+ if ! sha_exist?(release)
34
+ raise "No such commit `#{release}"
35
+ end
36
+ rc = system("git push -f #{heroku_remote} #{release}:master")
37
+ if rc.nil? || ! rc
38
+ raise "Error in `git push -f #{heroku_remote} #{release}:master`: #{$?}"
25
39
  end
26
- false
27
40
  end
28
41
  end
29
42
  end
@@ -0,0 +1,48 @@
1
+ # heavily inspired by https://github.com/defunkt/cijoe/blob/master/lib/cijoe/config.rb
2
+ module Heroku
3
+ module Bartender
4
+ class Config
5
+
6
+ def self.method_missing(command, *args)
7
+ new(command, *args)
8
+ end
9
+
10
+ def initialize(command, project_path = nil, parent = nil)
11
+ @command = command
12
+ @parent = parent
13
+ @project_path = project_path || File.join(File.dirname(__FILE__), '../../')
14
+ end
15
+
16
+ def method_missing(command, *args)
17
+ Config.new(command, @project_path, self)
18
+ end
19
+
20
+ def to_s
21
+ git_command = "cd #{@project_path} && git config #{config_string}"
22
+ result = `#{git_command} 2>&1`.chomp
23
+ process_status = $?
24
+
25
+ if successful_command?(process_status) || config_command_with_empty_value?(result,process_status)
26
+ return result
27
+ else
28
+ raise "Error calling git config, is a recent version of git installed? Command: #{git_command.inspect}, Error: #{result.inspect}, Status: #{process_status.inspect}"
29
+ end
30
+ end
31
+
32
+ def config_string
33
+ @parent ? "#{@parent.config_string}.#{@command}" : @command
34
+ end
35
+
36
+ private
37
+
38
+ def successful_command?(process_status)
39
+ process_status.exitstatus.to_i == 0
40
+ end
41
+
42
+ def config_command_with_empty_value?(result, process_status)
43
+ process_status.exitstatus.to_i == 1 && result.empty?
44
+ end
45
+ end
46
+ end
47
+ end
48
+
@@ -2,11 +2,11 @@ require "grit"
2
2
  module Heroku
3
3
  module Bartender
4
4
  class Log
5
- def self.get_log
6
- Grit::Repo.new('.').log
5
+ def self.get_log(options = {})
6
+ Grit::Repo.new('.').log('master', nil, options)
7
7
  end
8
- def self.generate_commits
9
- get_log.map do |item|
8
+ def self.generate_commits(options = {})
9
+ get_log(options).map do |item|
10
10
  Commit.new({ :sha => item.sha , :author => item.author.name,
11
11
  :email => item.author.email, :message => item.message,
12
12
  :date => item.date
@@ -3,47 +3,96 @@ require 'erb'
3
3
  module Heroku
4
4
  module Bartender
5
5
  class Server < Sinatra::Base
6
- @@heroku_remote
7
- @@user
8
- @@pass
6
+
9
7
  @@deployed_versions = {}
10
8
  @@status = nil
9
+ @@options = {}
10
+
11
11
  dir = File.dirname(File.expand_path(__FILE__))
12
12
  set :views, "#{dir}/views"
13
+ set :public, "#{dir}/public"
14
+
15
+ def self.commits
16
+ @@options[:commits]
17
+ end
18
+
19
+ def self.user
20
+ @@options[:user]
21
+ end
22
+
23
+ def self.password
24
+ @@options[:password]
25
+ end
26
+
27
+ def self.target
28
+ @@options[:target] || 'heroku'
29
+ end
30
+
31
+ def self.host
32
+ @@options[:host]
33
+ end
34
+
35
+ def self.port
36
+ @@options[:port]
37
+ end
38
+
39
+ def self.config
40
+ Config.send("remote.#{Server.target}")
41
+ end
42
+
43
+ def self.predeploy
44
+ config.predeploy.to_s
45
+ end
46
+
47
+ def self.log_options
48
+ options = { }
49
+ options.merge({ :max_count => Server.commits }) if (Server.commits > 0)
50
+ options
51
+ end
52
+
13
53
  get "/" do
14
- erb(:template, {}, :commits => Log.generate_commits,
15
- :current_version => Command.current_version(@@heroku_remote),
54
+ erb(:template, {}, :commits => Log.generate_commits(Server.log_options),
55
+ :current_version => Command.current_version(Server.target),
16
56
  :deployed_versions => @@deployed_versions,
17
57
  :status => @@status
18
58
  )
19
59
  end
60
+
20
61
  post "/" do
21
62
  if params[:sha]
22
- @@status = Command.move_to params[:sha], @@heroku_remote
23
- @@deployed_versions[params[:sha]] = [Time.now, @@status]
63
+ begin
64
+ Command.move_to params[:sha], predeploy, target
65
+ @@status = true
66
+ @@deployed_versions[params[:sha]] = [Time.now, @@status, nil]
67
+ rescue Exception => e
68
+ @@status = false
69
+ @@deployed_versions[params[:sha]] = [Time.now, @@status, e]
70
+ end
24
71
  end
25
- erb(:template, {}, :commits => Log.generate_commits,
26
- :current_version => Command.current_version(@@heroku_remote),
72
+ erb(:template, {}, :commits => Log.generate_commits(Server.log_options),
73
+ :current_version => Command.current_version(Server.target),
27
74
  :deployed_versions => @@deployed_versions,
28
75
  :status => @@status
29
76
  )
30
77
  end
31
- def self.start(host, port, heroku_remote, user, pass)
32
- @@heroku_remote = heroku_remote
33
- authorize(user, pass)
34
- Heroku::Bartender::Server.run!(:host => host, :port => port)
78
+
79
+ def self.start(options = {})
80
+ @@options = options
81
+ authorize(user, password)
82
+ run!(:host => host, :port => port)
35
83
  end
36
84
 
37
- def self.authorize(user, pass)
38
- if user != '' && pass != ''
39
- use Rack::Auth::Basic, "Restricted Area" do |username, password|
40
- [username, password] == [user, pass]
85
+ def self.authorize(user, password)
86
+ if ! user.nil?
87
+ use Rack::Auth::Basic, "Restricted Area" do |u, p|
88
+ [u, p] == [user, password]
41
89
  end
42
90
  end
43
91
  end
44
92
 
45
93
  helpers do
46
94
  include Rack::Utils
95
+
47
96
  def current_class(current_version_sha, sha)
48
97
  sha == current_version_sha ? 'current' : ''
49
98
  end
@@ -60,6 +109,7 @@ module Heroku
60
109
  end
61
110
  ''
62
111
  end
112
+
63
113
  def state(status)
64
114
  if status == true
65
115
  return 'OK'
@@ -68,6 +118,15 @@ module Heroku
68
118
  end
69
119
  'UNKNOWN'
70
120
  end
121
+
122
+ def target
123
+ Server.target
124
+ end
125
+
126
+ def predeploy
127
+ Server.predeploy
128
+ end
129
+
71
130
  end
72
131
  end
73
132
  end
@@ -1,5 +1,5 @@
1
1
  module Heroku
2
2
  module Bartender
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
4
4
  end
5
5
  end
@@ -22,11 +22,17 @@
22
22
  </head>
23
23
  <body>
24
24
  <div class='title'>
25
- <h1> Heroku Bartender </h1>
25
+ <h1> Heroku Bartender</h1>
26
26
  </div>
27
- <a href="#<%= current_version %>">
27
+ <div>
28
+ <ul>
29
+ <li><a href="#<%= current_version %>">
28
30
  Current version status: <%= state(status) %>
29
- </a>
31
+ </a></li>
32
+ <li>Remote: <b><%= target %></b></li>
33
+ <li>Pre-deploy: <b><%= predeploy %></b></li>
34
+ </ul>
35
+ </div>
30
36
  <div class="site">
31
37
  <div id="home">
32
38
  <ul class="posts">
@@ -46,10 +52,15 @@
46
52
  <strong> Deployed date </strong>
47
53
  <%= deployed_versions[commit.sha][0] %>
48
54
  </p>
55
+ <div>
56
+ <small>
57
+ <%= deployed_versions[commit.sha][2] %>
58
+ </small>
59
+ </div>
49
60
  <% end %>
50
61
  <form method="POST">
51
62
  <input type="hidden" value="<%= commit.sha %>" name="sha"/>
52
- <input type="submit" value="Build"/>
63
+ <input type="submit" value="Deploy"/>
53
64
  </form>
54
65
 
55
66
  </li>
@@ -64,7 +75,7 @@
64
75
  Unknown: No deployed version, or problems contacting heroku
65
76
  </div>
66
77
  <div class="red">
67
- Fail: The deploy goes wrong
78
+ Fail: The deploy went wrong
68
79
  </div>
69
80
  </div>
70
81
  </div>
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: heroku-bartender
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.0
5
+ version: 0.3.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sebastian Arcila-Valenzuela
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-15 00:00:00 -05:00
13
+ date: 2011-04-11 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -71,7 +71,9 @@ files:
71
71
  - LICENSE
72
72
  - lib/heroku/bartender/command.rb
73
73
  - lib/heroku/bartender/commit.rb
74
+ - lib/heroku/bartender/config.rb
74
75
  - lib/heroku/bartender/log.rb
76
+ - lib/heroku/bartender/public/favicon.ico
75
77
  - lib/heroku/bartender/server.rb
76
78
  - lib/heroku/bartender/version.rb
77
79
  - lib/heroku/bartender/views/template.erb