heploy 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -7
- data/bin/heploy +10 -0
- data/heploy.gemspec +3 -0
- data/lib/heploy.rb +16 -2
- data/lib/heploy/cli.rb +20 -1
- data/lib/heploy/command.rb +3 -0
- data/lib/heploy/command/deploy.rb +140 -0
- data/lib/heploy/configuration.rb +26 -0
- data/lib/heploy/version.rb +1 -1
- data/test/configuration_test.rb +2 -0
- metadata +45 -7
data/README.md
CHANGED
@@ -20,19 +20,33 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
$ gem install heploy
|
22
22
|
|
23
|
+
Then run the installer:
|
24
|
+
|
25
|
+
$ rails g heploy:install
|
26
|
+
|
27
|
+
You'll have to fill out the configuration file with some application details and your Heroku information.
|
28
|
+
|
29
|
+
Bonus! Add an alias:
|
30
|
+
|
31
|
+
alias deploy='bundle exec heploy'
|
32
|
+
|
33
|
+
Enjoy typing `$ deploy staging` instead of `$ bundle exec heploy staging` all the time.
|
34
|
+
|
23
35
|
## Usage
|
24
36
|
|
37
|
+
I'm trying to keep this is simple as possible.
|
38
|
+
|
25
39
|
### Basic usage
|
26
40
|
|
27
|
-
Heploy defaults to you using a "dev", "staging" and "production" branch.
|
41
|
+
Heploy defaults to you using a "dev", "staging" and "production" branch. You can change the defaults in the configuration file. But for now, here we go.
|
28
42
|
|
29
43
|
Deploying to staging:
|
30
44
|
|
31
|
-
$ heploy staging
|
45
|
+
$ bundle exec heploy staging
|
32
46
|
|
33
47
|
Deploying to production:
|
34
48
|
|
35
|
-
$ heploy production
|
49
|
+
$ bundle exec heploy production
|
36
50
|
|
37
51
|
Simple.
|
38
52
|
|
@@ -51,10 +65,6 @@ Let's start with `$ heploy staging`. When you run it, you:
|
|
51
65
|
|
52
66
|
As you might have guessed, `$ heploy production` does pretty much the same thing, except merges the "staging" branch into "production".
|
53
67
|
|
54
|
-
### Changing the defaults
|
55
|
-
|
56
|
-
I'm looking into the best way to do this now.
|
57
|
-
|
58
68
|
### Other things
|
59
69
|
|
60
70
|
Heploy can also help set up your staging and production environments.
|
data/bin/heploy
CHANGED
@@ -1,2 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
# resolve bin path, ignoring symlinks
|
4
|
+
require "pathname"
|
5
|
+
bin_file = Pathname.new(__FILE__).realpath
|
6
|
+
|
7
|
+
# add self to libpath
|
8
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", bin_file)
|
9
|
+
|
10
|
+
require 'heploy/cli'
|
11
|
+
Heploy::CLI.start
|
12
|
+
|
data/heploy.gemspec
CHANGED
@@ -14,6 +14,9 @@ Gem::Specification.new do |gem|
|
|
14
14
|
|
15
15
|
gem.add_dependency "thor"
|
16
16
|
gem.add_dependency "git"
|
17
|
+
gem.add_dependency "heroku"
|
18
|
+
gem.add_dependency "rake"
|
19
|
+
gem.add_development_dependency "minitest"
|
17
20
|
|
18
21
|
gem.files = `git ls-files`.split($/)
|
19
22
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
data/lib/heploy.rb
CHANGED
@@ -1,5 +1,19 @@
|
|
1
|
-
require
|
1
|
+
require 'git'
|
2
|
+
require 'heroku'
|
3
|
+
|
4
|
+
require 'heploy/version'
|
5
|
+
require 'heploy/configuration'
|
6
|
+
require 'heploy/command'
|
7
|
+
require 'heploy/command/deploy'
|
2
8
|
|
3
9
|
module Heploy
|
4
|
-
|
10
|
+
class << self
|
11
|
+
attr_accessor :configuration
|
12
|
+
|
13
|
+
def configure
|
14
|
+
self.configuration ||= Configuration.new
|
15
|
+
yield(configuration) if block_given?
|
16
|
+
configuration
|
17
|
+
end
|
18
|
+
end
|
5
19
|
end
|
data/lib/heploy/cli.rb
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
-
|
1
|
+
require 'thor'
|
2
|
+
require 'heploy'
|
2
3
|
|
4
|
+
module Heploy
|
5
|
+
class CLI < Thor
|
6
|
+
|
7
|
+
method_option :verbose, type: :boolean, aliases: "-v", default: false
|
8
|
+
|
9
|
+
desc 'staging', 'Deploys your application to your staging server.'
|
10
|
+
def staging
|
11
|
+
config = Heploy::Configuration.find
|
12
|
+
Heploy::Command::Deploy.staging config, options['verbose']
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'production', 'Deploys your application to your production server.'
|
16
|
+
def production
|
17
|
+
config = Heploy::Configuration.find
|
18
|
+
Heploy::Command::Deploy.production config, options['verbose']
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
3
22
|
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'git'
|
2
|
+
require 'heroku-api'
|
3
|
+
require 'rake'
|
4
|
+
require 'logger'
|
5
|
+
|
6
|
+
class Heploy::Command::Deploy
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def staging(config, verbose)
|
10
|
+
deploy_to config.staging_app_name,
|
11
|
+
config.development_branch,
|
12
|
+
config.staging_branch,
|
13
|
+
config,
|
14
|
+
verbose
|
15
|
+
end
|
16
|
+
|
17
|
+
def production(config, verbose)
|
18
|
+
print "Server you're deploying to: "
|
19
|
+
input = STDIN.gets.chomp
|
20
|
+
if config.production_app_name == input
|
21
|
+
deploy_to config.production_app_name,
|
22
|
+
config.staging_branch,
|
23
|
+
config.production_branch,
|
24
|
+
config,
|
25
|
+
verbose
|
26
|
+
else
|
27
|
+
abandon_ship "That is not the correct server."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def deploy_to(app_name, from_branch_name, to_branch_name, config, verbose)
|
34
|
+
if verbose
|
35
|
+
@repo = Git.open Dir.pwd, :log => Logger.new(STDOUT)
|
36
|
+
else
|
37
|
+
@repo = Git.open Dir.pwd
|
38
|
+
end
|
39
|
+
@dev_branch = @repo.branch config.development_branch
|
40
|
+
@from_branch_name = from_branch_name
|
41
|
+
@to_branch_name = to_branch_name
|
42
|
+
@from_branch = @repo.branch @from_branch_name
|
43
|
+
@to_branch = @repo.branch @to_branch_name
|
44
|
+
@heroku = heroku_client config.heroku_api_key
|
45
|
+
@app_name = app_name
|
46
|
+
|
47
|
+
@repo.checkout @to_branch
|
48
|
+
@repo.merge @from_branch
|
49
|
+
turn_maintenance_on
|
50
|
+
tag_latest_commit
|
51
|
+
push_to_heroku
|
52
|
+
migrate_database
|
53
|
+
restart_application
|
54
|
+
turn_maintenance_off
|
55
|
+
@repo.checkout @dev_branch
|
56
|
+
end
|
57
|
+
|
58
|
+
def heroku_client(api_key)
|
59
|
+
Heroku::API.new api_key: api_key
|
60
|
+
rescue
|
61
|
+
abandon_ship "Could not set up your Heroku client."
|
62
|
+
end
|
63
|
+
|
64
|
+
def turn_maintenance_on
|
65
|
+
@heroku.post_app_maintenance @app_name, '1'
|
66
|
+
if @heroku.get_app_maintenance(@app_name).body['maintenance']
|
67
|
+
puts "Turned maintenance mode on."
|
68
|
+
else
|
69
|
+
abandon_ship "Maintenance mode did not turn on."
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def turn_maintenance_off
|
74
|
+
@heroku.post_app_maintenance @app_name, '0'
|
75
|
+
if !@heroku.get_app_maintenance(@app_name).body['maintenance']
|
76
|
+
puts "Turned maintenance mode off."
|
77
|
+
else
|
78
|
+
abandon_ship "Maintenance mode did not turn off."
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def tag_name
|
83
|
+
release = @heroku.get_releases(@app_name).body.last["name"].gsub(/[[:alpha:]]/, "").to_i + 1
|
84
|
+
"#{@to_branch_name}-#{release}"
|
85
|
+
end
|
86
|
+
|
87
|
+
def tag_latest_commit
|
88
|
+
commit = @repo.add_tag(tag_name).inspect
|
89
|
+
puts "Tagged commit #{commit[0,7]} as #{tag_name}."
|
90
|
+
rescue Git::GitExecuteError => details
|
91
|
+
abandon_ship "#{details.message.split(": ").last.capitalize}."
|
92
|
+
end
|
93
|
+
|
94
|
+
def delete_tag
|
95
|
+
system "git tag #{tag_name} -d"
|
96
|
+
end
|
97
|
+
|
98
|
+
def push_to_heroku
|
99
|
+
puts "Pushing #{@to_branch_name} branch to #{@app_name}."
|
100
|
+
@repo.push @to_branch_name, "#{@to_branch_name}:master", true
|
101
|
+
confirm_codebase_push
|
102
|
+
rescue Git::GitExecuteError => details
|
103
|
+
abandon_ship "Could not push to #{@to_branch_name}." do
|
104
|
+
delete_tag
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def confirm_codebase_push
|
109
|
+
latest_local_commit = @repo.log.first.inspect[0,7]
|
110
|
+
latest_heroku_commit = @heroku.get_releases(@app_name).body.last['commit']
|
111
|
+
if latest_local_commit == latest_heroku_commit
|
112
|
+
puts "Completed push successfully."
|
113
|
+
else
|
114
|
+
abandon_ship "Pushing to #{@app_name} wasn't successful.\n------ Latest local commit: #{latest_local_commit}\n------ Latest Heroku commit: #{latest_heroku_commit}" do
|
115
|
+
delete_tag
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def migrate_database
|
121
|
+
@heroku.post_ps @app_name, "rake db:migrate"
|
122
|
+
rescue
|
123
|
+
abandon_ship "Could not migrate your database."
|
124
|
+
end
|
125
|
+
|
126
|
+
def restart_application
|
127
|
+
@heroku.post_ps_restart @app_name
|
128
|
+
rescue
|
129
|
+
abandon_ship "Could not restart #{@app_name}."
|
130
|
+
end
|
131
|
+
|
132
|
+
def abandon_ship(message, &block)
|
133
|
+
puts "-- Abandoning ship: #{message}"
|
134
|
+
block.call unless block == nil
|
135
|
+
@repo.checkout @dev_branch unless @repo == nil
|
136
|
+
exit
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Heploy
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
attr_accessor :development_branch,
|
5
|
+
:staging_branch,
|
6
|
+
:production_branch,
|
7
|
+
:staging_app_name,
|
8
|
+
:production_app_name,
|
9
|
+
:heroku_api_key
|
10
|
+
|
11
|
+
def self.find
|
12
|
+
load Dir["config/heploy.rb"].first
|
13
|
+
Heploy.configuration
|
14
|
+
rescue TypeError
|
15
|
+
puts "Error: You don't have a configuration file."
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@development_branch = "dev"
|
21
|
+
@staging_branch = "staging"
|
22
|
+
@production_branch = "production"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/lib/heploy/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
16
|
-
requirement: &
|
16
|
+
requirement: &70124576997920 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70124576997920
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: git
|
27
|
-
requirement: &
|
27
|
+
requirement: &70124576997460 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,40 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70124576997460
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: heroku
|
38
|
+
requirement: &70124568621400 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70124568621400
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: &70124568620580 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70124568620580
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: minitest
|
60
|
+
requirement: &70124568619440 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70124568619440
|
36
69
|
description: Heploy deploys your application to Heroku, using a bunch of best practices
|
37
70
|
and other nice things.
|
38
71
|
email:
|
@@ -52,7 +85,11 @@ files:
|
|
52
85
|
- heploy.gemspec
|
53
86
|
- lib/heploy.rb
|
54
87
|
- lib/heploy/cli.rb
|
88
|
+
- lib/heploy/command.rb
|
89
|
+
- lib/heploy/command/deploy.rb
|
90
|
+
- lib/heploy/configuration.rb
|
55
91
|
- lib/heploy/version.rb
|
92
|
+
- test/configuration_test.rb
|
56
93
|
homepage: ''
|
57
94
|
licenses: []
|
58
95
|
post_install_message:
|
@@ -77,4 +114,5 @@ rubygems_version: 1.8.10
|
|
77
114
|
signing_key:
|
78
115
|
specification_version: 3
|
79
116
|
summary: Deploy your application to Heroku, even easier.
|
80
|
-
test_files:
|
117
|
+
test_files:
|
118
|
+
- test/configuration_test.rb
|