github_heroku_deployer 0.0.4 → 0.0.5
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.
- data/README.md +3 -1
- data/lib/github_heroku_deployer/configuration.rb +3 -2
- data/lib/github_heroku_deployer/exceptions.rb +1 -0
- data/lib/github_heroku_deployer/git.rb +31 -15
- data/lib/github_heroku_deployer/heroku.rb +8 -7
- data/lib/github_heroku_deployer/version.rb +1 -1
- data/lib/github_heroku_deployer.rb +9 -1
- data/spec/lib/github_heroku_deployer_spec.rb +41 -14
- metadata +8 -2
data/README.md
CHANGED
|
@@ -40,12 +40,13 @@ Set defaults in an initializer, defaults are shown:
|
|
|
40
40
|
|
|
41
41
|
```ruby
|
|
42
42
|
GithubHerokuDeployer.configure do |config|
|
|
43
|
-
config.ssh = false
|
|
44
43
|
config.github_repo = ENV["GITHUB_REPO"]
|
|
45
44
|
config.heroku_api_key = ENV["HEROKU_API_KEY"]
|
|
46
45
|
config.heroku_app_name = ENV["HEROKU_APP_NAME"]
|
|
47
46
|
config.heroku_repo = ENV["HEROKU_REPO"]
|
|
48
47
|
config.heroku_username = ENV["HEROKU_USERNAME"]
|
|
48
|
+
config.id_rsa = ENV["ID_RSA"]
|
|
49
|
+
config.logger = Logger.new(STDOUT)
|
|
49
50
|
end
|
|
50
51
|
```
|
|
51
52
|
|
|
@@ -57,6 +58,7 @@ export HEROKU_API_KEY=heroku_api_key
|
|
|
57
58
|
export HEROKU_APP_NAME=heroku_app_name
|
|
58
59
|
export HEROKU_REPO=git@heroku.com:repo.git
|
|
59
60
|
export HEROKU_USERNAME=heroku_username
|
|
61
|
+
export ID_RSA=id_rsa
|
|
60
62
|
```
|
|
61
63
|
|
|
62
64
|
Deploy:
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
module GithubHerokuDeployer
|
|
2
2
|
class Configuration
|
|
3
3
|
OPTIONS = {
|
|
4
|
-
github_private_key: ENV["GITHUB_PRIVATE_KEY"],
|
|
5
4
|
github_repo: ENV["GITHUB_REPO"],
|
|
6
5
|
heroku_api_key: ENV["HEROKU_API_KEY"],
|
|
7
6
|
heroku_app_name: ENV["HEROKU_APP_NAME"],
|
|
8
7
|
heroku_repo: ENV["HEROKU_REPO"],
|
|
9
8
|
heroku_username: ENV["HEROKU_USERNAME"],
|
|
10
|
-
|
|
9
|
+
id_rsa: ENV["ID_RSA"],
|
|
10
|
+
logger: ::Logger.new(STDOUT),
|
|
11
|
+
repo_dir: ENV["REPO_DIR"]
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
# Defines accessors for all OPTIONS
|
|
@@ -5,16 +5,19 @@ module GithubHerokuDeployer
|
|
|
5
5
|
class Git
|
|
6
6
|
|
|
7
7
|
def initialize(options)
|
|
8
|
-
@ssh_enabled = options[:ssh_enabled]
|
|
9
8
|
@heroku_repo = options[:heroku_repo]
|
|
10
9
|
@github_repo = options[:github_repo]
|
|
11
|
-
@
|
|
10
|
+
@id_rsa = options[:id_rsa]
|
|
11
|
+
@logger = options[:logger]
|
|
12
|
+
@repo_dir = options[:repo_dir]
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
def push_app_to_heroku(remote="heroku", branch="master")
|
|
15
16
|
wrapper = ssh_wrapper
|
|
16
|
-
repo.
|
|
17
|
-
|
|
17
|
+
run "cd #{repo.dir}; git remote rm #{remote}" if repo.remote(remote).url
|
|
18
|
+
repo.add_remote(remote, @heroku_repo)
|
|
19
|
+
@logger.info "deploying #{repo.dir} to #{repo.remote(remote).url} from branch #{branch}"
|
|
20
|
+
run "cd #{repo.dir}; env #{wrapper.git_ssh} git push -f #{remote} #{branch}"
|
|
18
21
|
ensure
|
|
19
22
|
wrapper.unlink
|
|
20
23
|
end
|
|
@@ -24,17 +27,18 @@ module GithubHerokuDeployer
|
|
|
24
27
|
end
|
|
25
28
|
|
|
26
29
|
def setup_repo
|
|
27
|
-
# remove_folder
|
|
28
30
|
clone_or_pull
|
|
29
31
|
open
|
|
30
32
|
end
|
|
31
33
|
|
|
32
|
-
# def remove_folder
|
|
33
|
-
# `rm -r #{folder}`
|
|
34
|
-
# end
|
|
35
|
-
|
|
36
34
|
def folder
|
|
37
|
-
@folder ||=
|
|
35
|
+
@folder ||= setup_folder
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def setup_folder
|
|
39
|
+
folder = File.join(@repo_dir, Zlib.crc32(@github_repo).to_s)
|
|
40
|
+
FileUtils.mkdir_p(folder)
|
|
41
|
+
folder
|
|
38
42
|
end
|
|
39
43
|
|
|
40
44
|
def clone_or_pull
|
|
@@ -47,7 +51,8 @@ module GithubHerokuDeployer
|
|
|
47
51
|
|
|
48
52
|
def clone
|
|
49
53
|
wrapper = ssh_wrapper
|
|
50
|
-
|
|
54
|
+
@logger.info "cloning #{@github_repo} to #{folder}"
|
|
55
|
+
run "env #{wrapper.git_ssh} git clone #{@github_repo} #{folder}"
|
|
51
56
|
ensure
|
|
52
57
|
wrapper.unlink
|
|
53
58
|
end
|
|
@@ -55,7 +60,8 @@ module GithubHerokuDeployer
|
|
|
55
60
|
def pull
|
|
56
61
|
wrapper = ssh_wrapper
|
|
57
62
|
dir = Dir.pwd # need to cd back to here
|
|
58
|
-
|
|
63
|
+
@logger.info "pulling from #{folder}"
|
|
64
|
+
run "cd #{folder}; env #{wrapper.git_ssh} git pull; cd #{dir}"
|
|
59
65
|
ensure
|
|
60
66
|
wrapper.unlink
|
|
61
67
|
end
|
|
@@ -65,14 +71,24 @@ module GithubHerokuDeployer
|
|
|
65
71
|
end
|
|
66
72
|
|
|
67
73
|
def ssh_wrapper
|
|
68
|
-
GitSSHWrapper.new(private_key_path:
|
|
74
|
+
GitSSHWrapper.new(private_key_path: id_rsa_path)
|
|
69
75
|
end
|
|
70
76
|
|
|
71
|
-
def
|
|
77
|
+
def id_rsa_path
|
|
72
78
|
file = Tempfile.new("id_rsa")
|
|
73
|
-
file.write(@
|
|
79
|
+
file.write(@id_rsa)
|
|
74
80
|
file.rewind
|
|
75
81
|
file.path
|
|
76
82
|
end
|
|
83
|
+
|
|
84
|
+
def run(command)
|
|
85
|
+
result = `#{command} 2>&1`
|
|
86
|
+
status = $?.exitstatus
|
|
87
|
+
if status == 0
|
|
88
|
+
@logger.info result
|
|
89
|
+
else
|
|
90
|
+
raise GithubHerokuDeployer::CommandException, result
|
|
91
|
+
end
|
|
92
|
+
end
|
|
77
93
|
end
|
|
78
94
|
end
|
|
@@ -8,6 +8,7 @@ module GithubHerokuDeployer
|
|
|
8
8
|
@heroku_app_name = options[:heroku_app_name]
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
+
|
|
11
12
|
def heroku
|
|
12
13
|
@heroku ||= ::Heroku::API.new(api_key: @heroku_api_key)
|
|
13
14
|
end
|
|
@@ -30,9 +31,13 @@ module GithubHerokuDeployer
|
|
|
30
31
|
heroku.post_app(name: @heroku_app_name)
|
|
31
32
|
end
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
def run(command)
|
|
35
|
+
heroku.post_ps(@heroku_app_name, command)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def delete_app
|
|
39
|
+
heroku.delete_app(@heroku_app_name)
|
|
40
|
+
end
|
|
36
41
|
|
|
37
42
|
# def add_deployhooks_http(url)
|
|
38
43
|
# add_addon("deployhooks:http", url: url)
|
|
@@ -45,9 +50,5 @@ module GithubHerokuDeployer
|
|
|
45
50
|
# def delete_addon(addon)
|
|
46
51
|
# heroku.delete_addon(@heroku_app_name, addon)
|
|
47
52
|
# end
|
|
48
|
-
|
|
49
|
-
# def migrate
|
|
50
|
-
# heroku.post_ps(@heroku_app_name, "rake db:migrate")
|
|
51
|
-
# end
|
|
52
53
|
end
|
|
53
54
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require "logger"
|
|
1
2
|
require "github_heroku_deployer/exceptions"
|
|
2
3
|
require "github_heroku_deployer/configuration"
|
|
3
4
|
require "github_heroku_deployer/git"
|
|
@@ -28,7 +29,8 @@ module GithubHerokuDeployer
|
|
|
28
29
|
# config.heroku_app_name = ENV["HEROKU_APP_NAME"]
|
|
29
30
|
# config.heroku_repo = ENV["HEROKU_REPO"]
|
|
30
31
|
# config.heroku_username = ENV["HEROKU_USERNAME"]
|
|
31
|
-
# config.
|
|
32
|
+
# config.id_rsa = ENV["ID_RSA"]
|
|
33
|
+
# config.logger = Logger.new(STDOUT)
|
|
32
34
|
# end
|
|
33
35
|
def configure
|
|
34
36
|
yield(configuration)
|
|
@@ -42,6 +44,12 @@ module GithubHerokuDeployer
|
|
|
42
44
|
true
|
|
43
45
|
end
|
|
44
46
|
|
|
47
|
+
def heroku_run(command, options={})
|
|
48
|
+
options = configuration.merge(options)
|
|
49
|
+
validate_options(options)
|
|
50
|
+
Heroku.new(options).run(command)
|
|
51
|
+
end
|
|
52
|
+
|
|
45
53
|
def validate_options(options)
|
|
46
54
|
configuration.validate_presence(options)
|
|
47
55
|
end
|
|
@@ -42,32 +42,59 @@ describe GithubHerokuDeployer do
|
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
+
# TODO: how can I test these better?
|
|
45
46
|
context "when configured" do
|
|
46
47
|
before :each do
|
|
47
48
|
@deployer = mock("github_heroku_deployer")
|
|
48
49
|
@deployer.stub!(:deploy).and_return(true)
|
|
49
50
|
end
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
context "when repo does not exist locally" do
|
|
53
|
+
it "deploys public repos" do
|
|
54
|
+
public_repo = ENV["PUBLIC_GITHUB_REPO"]
|
|
55
|
+
public_repo_folder = Zlib.crc32(public_repo).to_s
|
|
56
|
+
repos_dir = GithubHerokuDeployer.configuration[:repo_dir]
|
|
57
|
+
full_path = File.join(repos_dir, public_repo_folder)
|
|
58
|
+
FileUtils.rm_r(full_path) if File.exists?(full_path)
|
|
59
|
+
GithubHerokuDeployer.configure do |config|
|
|
60
|
+
config.github_repo = public_repo
|
|
61
|
+
end
|
|
62
|
+
# GithubHerokuDeployer.deploy.should be true
|
|
63
|
+
@deployer.deploy.should be true
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "deploys private repos" do
|
|
67
|
+
private_repo = ENV["PRIVATE_GITHUB_REPO"]
|
|
68
|
+
private_repo_folder = Zlib.crc32(private_repo).to_s
|
|
69
|
+
repos_dir = GithubHerokuDeployer.configuration[:repo_dir]
|
|
70
|
+
full_path = File.join(repos_dir, private_repo_folder)
|
|
71
|
+
FileUtils.rm_r(full_path) if File.exists?(full_path)
|
|
72
|
+
GithubHerokuDeployer.configure do |config|
|
|
73
|
+
config.github_repo = private_repo
|
|
74
|
+
end
|
|
75
|
+
# GithubHerokuDeployer.deploy.should be true
|
|
76
|
+
@deployer.deploy.should be true
|
|
55
77
|
end
|
|
56
|
-
# GithubHerokuDeployer.deploy.should be true
|
|
57
|
-
@deployer.deploy.should be true
|
|
58
78
|
end
|
|
59
79
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
80
|
+
context "when repo exists locally" do
|
|
81
|
+
it "deploys public repos" do
|
|
82
|
+
GithubHerokuDeployer.configure do |config|
|
|
83
|
+
config.github_repo = ENV["PUBLIC_GITHUB_REPO"]
|
|
84
|
+
end
|
|
85
|
+
# GithubHerokuDeployer.deploy.should be true
|
|
86
|
+
@deployer.deploy.should be true
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "deploys private repos" do
|
|
90
|
+
GithubHerokuDeployer.configure do |config|
|
|
91
|
+
config.github_repo = ENV["PRIVATE_GITHUB_REPO"]
|
|
92
|
+
end
|
|
93
|
+
# GithubHerokuDeployer.deploy.should be true
|
|
94
|
+
@deployer.deploy.should be true
|
|
65
95
|
end
|
|
66
|
-
# GithubHerokuDeployer.deploy.should be true
|
|
67
|
-
@deployer.deploy.should be true
|
|
68
96
|
end
|
|
69
97
|
|
|
70
|
-
# TODO: how can I test this better?
|
|
71
98
|
it "overrides defaults" do
|
|
72
99
|
GithubHerokuDeployer.configure do |config|
|
|
73
100
|
config.github_repo = ""
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: github_heroku_deployer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.5
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-10-
|
|
12
|
+
date: 2012-10-31 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: heroku-api
|
|
@@ -160,12 +160,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
160
160
|
- - ! '>='
|
|
161
161
|
- !ruby/object:Gem::Version
|
|
162
162
|
version: '0'
|
|
163
|
+
segments:
|
|
164
|
+
- 0
|
|
165
|
+
hash: 3203415681699428382
|
|
163
166
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
167
|
none: false
|
|
165
168
|
requirements:
|
|
166
169
|
- - ! '>='
|
|
167
170
|
- !ruby/object:Gem::Version
|
|
168
171
|
version: '0'
|
|
172
|
+
segments:
|
|
173
|
+
- 0
|
|
174
|
+
hash: 3203415681699428382
|
|
169
175
|
requirements: []
|
|
170
176
|
rubyforge_project:
|
|
171
177
|
rubygems_version: 1.8.24
|