wizarddev-heroku 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +78 -0
- data/Rakefile +2 -0
- data/lib/wizarddev.rb +4 -0
- data/lib/wizarddev/heroku.rb +12 -0
- data/lib/wizarddev/heroku/deploy.rb +122 -0
- data/lib/wizarddev/heroku/platform_client.rb +67 -0
- data/lib/wizarddev/heroku/railtie.rb +13 -0
- data/lib/wizarddev/heroku/tasks/deploy.rb +44 -0
- data/lib/wizarddev/heroku/version.rb +5 -0
- data/wizarddev-heroku.gemspec +26 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 98d42486e642ab72a26ef05ce761504e608a1b5c
|
4
|
+
data.tar.gz: ce7a6ef47f1f41478e708210dbb67a4e7077c4ce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4b2cd1dd48b0177c822a6d4a8d922ad8b84afec694bb53c3b891a427b7db62f5291f9778cd469e11457377aae20dd8bbe9be9d31cec9772373c8d37c9a0cd46b
|
7
|
+
data.tar.gz: 92bffd015a204c4a2d24e85d5a1e36f498d68f73362ae55bde5dafe6da71926077eba4145d5e409d1c192311955431d4832a242343e45aac7c578e60d6873d16
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Francis Gulotta
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Wizarddev::Heroku
|
2
|
+
|
3
|
+
Deploys rails apps to heroku
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'wizarddev-heroku'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install wizarddev-heroku
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
From `rake wizarddev:deploy`
|
23
|
+
|
24
|
+
```
|
25
|
+
Deploys the currently checked out revision to Heroku.
|
26
|
+
Reads the project's app.json file to determine tasks for a target.
|
27
|
+
Tasks include:
|
28
|
+
Tag the release and pushes it to github
|
29
|
+
Deploy the release to Heroku
|
30
|
+
Execute commands remotely eg 'rake db:migrate'
|
31
|
+
Restart the app
|
32
|
+
|
33
|
+
Uses the ~/.netrc file for authentication per the Heroku toolbelt.
|
34
|
+
|
35
|
+
usage: rake wizarddev:deploy TARGET=target_name
|
36
|
+
usage: rake wizarddev:deploy:{staging|production}
|
37
|
+
```
|
38
|
+
|
39
|
+
## Example app.json
|
40
|
+
|
41
|
+
This is very similar and compatible with Heroku's `app.json`.
|
42
|
+
|
43
|
+
```json
|
44
|
+
{
|
45
|
+
"name": "Our Cool App",
|
46
|
+
"description": "Great app to use all the time.",
|
47
|
+
"website": "https://www.ourcoolapp.com",
|
48
|
+
"heroku-environments": {
|
49
|
+
"staging": {
|
50
|
+
"app-name": "ourcoolapp-staging",
|
51
|
+
"tag-name": false,
|
52
|
+
"force-push": true,
|
53
|
+
"scripts": [
|
54
|
+
{ "cmd": "rake db:migrate", "restart": true }
|
55
|
+
]
|
56
|
+
},
|
57
|
+
"production": {
|
58
|
+
"app-name": "ourcoolapp-production",
|
59
|
+
"force-push": false,
|
60
|
+
"tag-name": "prod",
|
61
|
+
"scripts": [
|
62
|
+
{ "cmd": "rake db:migrate", "restart": true, "remote": true },
|
63
|
+
{ "cmd": "say 'deploy complete'"}
|
64
|
+
]
|
65
|
+
}
|
66
|
+
},
|
67
|
+
"source-repo": "git@github.com:wizarddevelopment/ourcoolapp.git"
|
68
|
+
}
|
69
|
+
```
|
70
|
+
|
71
|
+
|
72
|
+
## Contributing
|
73
|
+
|
74
|
+
1. Fork it ( https://github.com/[my-github-username]/wizarddev-heroku/fork )
|
75
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
76
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
77
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
78
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/wizarddev.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Wizarddev
|
4
|
+
module Heroku
|
5
|
+
class Deploy
|
6
|
+
attr_reader :target, :heroku
|
7
|
+
|
8
|
+
def self.check_auth_config
|
9
|
+
unless auth = PlatformClient.load_auth
|
10
|
+
puts "Please make sure you have an up to date version of the heroku toolbelt and it's logged in"
|
11
|
+
end
|
12
|
+
|
13
|
+
unless config = File.exist?('app.json')
|
14
|
+
puts "Please include an app.json in the root of this project."
|
15
|
+
puts "`rails g wizarddev:app_json` will make one for you."
|
16
|
+
end
|
17
|
+
|
18
|
+
exit(1) unless auth && config
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(target)
|
22
|
+
@target = target.to_s
|
23
|
+
@app_config = load_config
|
24
|
+
@heroku = PlatformClient.local_auth(app_name)
|
25
|
+
end
|
26
|
+
|
27
|
+
def deploy!
|
28
|
+
force_push? ? force_push : push
|
29
|
+
tag_deploy
|
30
|
+
run_scripts
|
31
|
+
end
|
32
|
+
|
33
|
+
def push
|
34
|
+
puts "Pushing HEAD to Heroku ..."
|
35
|
+
execute "git push git@heroku.com:#{app_name}.git HEAD:master"
|
36
|
+
end
|
37
|
+
|
38
|
+
def force_push
|
39
|
+
puts "Force pushing HEAD to Heroku ..."
|
40
|
+
execute "git push -f git@heroku.com:#{app_name}.git HEAD:master"
|
41
|
+
end
|
42
|
+
|
43
|
+
def run_scripts
|
44
|
+
scripts.each { |script| run_script(script) }
|
45
|
+
end
|
46
|
+
|
47
|
+
def tag_deploy
|
48
|
+
return unless tag_name
|
49
|
+
version = heroku.latest_release['version']
|
50
|
+
release_name = "#{tag_name}/v#{version}"
|
51
|
+
puts "Tagging release with #{release_name}"
|
52
|
+
execute "git tag -a #{release_name} -m 'Tagged release'"
|
53
|
+
execute "git push #{source_repo} #{release_name}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def execute_remote(cmd)
|
57
|
+
print "Executing '#{cmd}' on #{app_name}\n"
|
58
|
+
output, code = heroku.run_with_code(cmd)
|
59
|
+
puts output.gsub(/^/, "#\t")
|
60
|
+
return true if code == 0
|
61
|
+
puts "Failed to Execute #{cmd} with code #{code}"
|
62
|
+
exit(1)
|
63
|
+
end
|
64
|
+
|
65
|
+
def execute(cmd)
|
66
|
+
print "Executing '#{cmd}'\n"
|
67
|
+
success = system(cmd)
|
68
|
+
return true if success
|
69
|
+
code = $CHILD_STATUS.to_i
|
70
|
+
puts "Failed to Execute #{cmd} with code #{code}"
|
71
|
+
exit(1)
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def run_script(script)
|
77
|
+
if script["remote"]
|
78
|
+
execute_remote script["cmd"]
|
79
|
+
else
|
80
|
+
execute script["cmd"]
|
81
|
+
end
|
82
|
+
restart if script["restart"]
|
83
|
+
end
|
84
|
+
|
85
|
+
def restart
|
86
|
+
puts "Restarting #{app_name}"
|
87
|
+
heroku.restart_all
|
88
|
+
end
|
89
|
+
|
90
|
+
def load_config
|
91
|
+
JSON.parse(File.read('app.json'))
|
92
|
+
end
|
93
|
+
|
94
|
+
def source_repo
|
95
|
+
@app_config["source-repo"]
|
96
|
+
end
|
97
|
+
|
98
|
+
def tag_name
|
99
|
+
config["tag-name"]
|
100
|
+
end
|
101
|
+
|
102
|
+
def force_push?
|
103
|
+
!!config["force-push"]
|
104
|
+
end
|
105
|
+
|
106
|
+
def app_name
|
107
|
+
config["app-name"]
|
108
|
+
end
|
109
|
+
|
110
|
+
def scripts
|
111
|
+
config["scripts"]
|
112
|
+
end
|
113
|
+
|
114
|
+
def config
|
115
|
+
c = @app_config["heroku-environments"][target]
|
116
|
+
raise "No configuration for #{target} in app.js" unless c
|
117
|
+
c
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'rendezvous'
|
3
|
+
require 'netrc'
|
4
|
+
|
5
|
+
module Wizarddev
|
6
|
+
module Heroku
|
7
|
+
class PlatformClient
|
8
|
+
include HTTParty
|
9
|
+
attr_reader :app
|
10
|
+
base_uri 'https://api.heroku.com'
|
11
|
+
|
12
|
+
def self.local_auth(app)
|
13
|
+
new(load_auth.password, app)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.load_auth
|
17
|
+
auth = Netrc.read['api.heroku.com']
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(oauth_key, app)
|
21
|
+
@app = app
|
22
|
+
self.class.headers(
|
23
|
+
'Accept' => 'application/vnd.heroku+json; version=3',
|
24
|
+
'Authorization' => "Bearer #{oauth_key}"
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def latest_release
|
29
|
+
resp = self.class.get(
|
30
|
+
"/apps/#{app}/releases",
|
31
|
+
headers: {
|
32
|
+
'Range' => 'version ..; order=desc, max=1;'
|
33
|
+
}
|
34
|
+
)
|
35
|
+
raise "Error fetching latest release: #{response.body}" unless resp.success?
|
36
|
+
resp.first
|
37
|
+
end
|
38
|
+
|
39
|
+
def restart_all
|
40
|
+
self.class.delete("/apps/#{app}/dynos")
|
41
|
+
end
|
42
|
+
|
43
|
+
def run(cmd)
|
44
|
+
cmdstr = { attach: 'true', command: cmd }.to_json
|
45
|
+
opt = {
|
46
|
+
body: cmdstr,
|
47
|
+
headers: { 'Content-Type' => 'application/json' }
|
48
|
+
}
|
49
|
+
response = self.class.post("/apps/#{app}/dynos", opt)
|
50
|
+
session = Rendezvous.new(
|
51
|
+
input: StringIO.new,
|
52
|
+
output: StringIO.new,
|
53
|
+
url: response['attach_url']
|
54
|
+
)
|
55
|
+
session.start
|
56
|
+
session.output.rewind
|
57
|
+
session.output.read
|
58
|
+
end
|
59
|
+
|
60
|
+
def run_with_code(cmd)
|
61
|
+
cmd = "#{cmd}; echo $?"
|
62
|
+
*output, code = run(cmd).split("\n")
|
63
|
+
[output.join("\n"), code.to_i]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
namespace :wizarddev do
|
2
|
+
task :deploy do
|
3
|
+
if ENV['TARGET']
|
4
|
+
Wizarddev::Heroku.load
|
5
|
+
Wizarddev::Heroku::Deploy.new(ENV['TARGET']).deploy!
|
6
|
+
else
|
7
|
+
Rake::Task["wizarddev:deploy:help"].invoke
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
namespace :deploy do
|
12
|
+
desc 'Deploy script usage information'
|
13
|
+
task :help do
|
14
|
+
puts 'Deploys the currently checked out revision to heroku.'
|
15
|
+
puts 'Reads the project\'s app.json file to determine tasks for a target.'
|
16
|
+
puts 'Tasks include:'
|
17
|
+
puts "\t Tag the release and pushes it to github"
|
18
|
+
puts "\t Deploy the release to Heroku"
|
19
|
+
puts "\t Execute commands remotely eg 'rake db:migrate'"
|
20
|
+
puts "\t Restart the app"
|
21
|
+
puts "\nUses the ~/.netrc file for authentication per the heroku toolbelt."
|
22
|
+
puts "\nusage: rake wizarddev:deploy TARGET=target_name"
|
23
|
+
puts "usage: rake wizarddev:deploy:{staging|production}"
|
24
|
+
|
25
|
+
Wizarddev::Heroku.load
|
26
|
+
Wizarddev::Heroku::Deploy.check_auth_config
|
27
|
+
exit 0
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'Deploy to Production'
|
31
|
+
task :production do
|
32
|
+
Wizarddev::Heroku.load
|
33
|
+
Wizarddev::Heroku::Deploy.new(:production).deploy!
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'Deploy to Staging'
|
37
|
+
task :staging do
|
38
|
+
Wizarddev::Heroku.load
|
39
|
+
Wizarddev::Heroku::Deploy.new(:staging).deploy!
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wizarddev/heroku/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'wizarddev-heroku'
|
8
|
+
spec.version = Wizarddev::Heroku::VERSION
|
9
|
+
spec.authors = ['Francis Gulotta']
|
10
|
+
spec.email = ['francis@wizarddevelopment.com']
|
11
|
+
spec.summary = %q{Deploys rails apps to heroku}
|
12
|
+
# spec.description = %q{TODO: Write a longer description. Optional.}
|
13
|
+
spec.homepage = 'https://www.wizarddevelopment.com'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_dependency 'netrc'
|
24
|
+
spec.add_dependency 'rendezvous'
|
25
|
+
spec.add_dependency 'httparty'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wizarddev-heroku
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Francis Gulotta
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: netrc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rendezvous
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: httparty
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- francis@wizarddevelopment.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- lib/wizarddev.rb
|
96
|
+
- lib/wizarddev/heroku.rb
|
97
|
+
- lib/wizarddev/heroku/deploy.rb
|
98
|
+
- lib/wizarddev/heroku/platform_client.rb
|
99
|
+
- lib/wizarddev/heroku/railtie.rb
|
100
|
+
- lib/wizarddev/heroku/tasks/deploy.rb
|
101
|
+
- lib/wizarddev/heroku/version.rb
|
102
|
+
- wizarddev-heroku.gemspec
|
103
|
+
homepage: https://www.wizarddevelopment.com
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.4.5
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Deploys rails apps to heroku
|
127
|
+
test_files: []
|