heroku-platform-helper 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 +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/heroku-platform-helper.gemspec +28 -0
- data/lib/heroku_helper/app.rb +130 -0
- data/lib/heroku_helper/version.rb +3 -0
- data/lib/heroku_helper.rb +5 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: faef574d9cf7c298abaa592f291b001aad6d272b
|
4
|
+
data.tar.gz: f4aa49af6cf443eb88c10fa79f5c94e8e96fb04e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a1c96e0675c4cfc89e1108a3f3c3a0d6e9d0998fe8627c19051846e4f9eb73fdd2bd47fbb960b46fcba89884ad5691d12f872715c8ec152ba6548dc404ee54ec
|
7
|
+
data.tar.gz: 73ed5c9ba4e9f6383481b989560b12dd1ac48620c6200e56cfddf2667f775b3ded96a9e33cdf2c02c1d3a9c39898a1f5f4024257a97fba99a61ff335273e61ba
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Paul Robertson
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# HerokuHelper
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/heroku_helper`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'heroku-platform-helper'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install heroku-platform-helper
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/perobertson/heroku-platform-helper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "heroku/helper"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'heroku_helper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'heroku-platform-helper'
|
8
|
+
spec.version = HerokuHelper::VERSION
|
9
|
+
spec.authors = ['Paul Robertson']
|
10
|
+
spec.email = ['t.paulrobertson@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'A helper library for managing Heroku apps.'
|
13
|
+
spec.homepage = "https://github.com/perobertson/heroku-platform-helper"
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
|
25
|
+
spec.add_dependency 'platform-api', '~> 0.3'
|
26
|
+
spec.add_dependency 'rendezvous', '~> 0.1'
|
27
|
+
spec.add_dependency 'colorize'
|
28
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'platform-api'
|
2
|
+
require 'rendezvous'
|
3
|
+
require 'colorize'
|
4
|
+
|
5
|
+
module HerokuHelper
|
6
|
+
class App
|
7
|
+
def initialize(api_key, app_name)
|
8
|
+
@api_key = api_key
|
9
|
+
@app_name = app_name
|
10
|
+
end
|
11
|
+
|
12
|
+
def deploy(branch:, worker: nil, clock: nil)
|
13
|
+
remote = @app_name
|
14
|
+
heroku = PlatformAPI.connect_oauth @api_key
|
15
|
+
|
16
|
+
git_url = heroku.app.info(@app_name)['git_url']
|
17
|
+
fail 'Cannot determine git url' if git_url.blank?
|
18
|
+
|
19
|
+
# Fetch whats currently deployed
|
20
|
+
system "[ \"$(git remote | grep -e ^#{remote})\" != '' ] && git remote rm #{remote}"
|
21
|
+
unless system "git remote add #{remote} #{git_url}"
|
22
|
+
fail "Could not add #{remote} remote #{git_url}"
|
23
|
+
end
|
24
|
+
unless system "git fetch #{remote} master"
|
25
|
+
fail "Could not fetch master from #{remote}"
|
26
|
+
end
|
27
|
+
|
28
|
+
scale worker: 0, clock: 0
|
29
|
+
maintenance true
|
30
|
+
|
31
|
+
unless system "git push #{remote} #{branch}:master"
|
32
|
+
fail "Failed to push branch(#{branch}) to remote(#{remote})"
|
33
|
+
end
|
34
|
+
|
35
|
+
migrate
|
36
|
+
maintenance false
|
37
|
+
scale worker: worker, clock: clock
|
38
|
+
end
|
39
|
+
|
40
|
+
def maintenance(enabled)
|
41
|
+
heroku = PlatformAPI.connect_oauth @api_key
|
42
|
+
if enabled
|
43
|
+
puts "Enabling maintenance for #{@app_name}".cyan
|
44
|
+
else
|
45
|
+
puts "Disabling maintenance for #{@app_name}".cyan
|
46
|
+
end
|
47
|
+
heroku.app.update(@app_name, maintenance: enabled)
|
48
|
+
end
|
49
|
+
|
50
|
+
def migrate
|
51
|
+
heroku = PlatformAPI.connect_oauth @api_key
|
52
|
+
payload = {
|
53
|
+
attach: true,
|
54
|
+
command: 'rake db:migrate'
|
55
|
+
}
|
56
|
+
response = heroku.dyno.create(@app_name, payload)
|
57
|
+
|
58
|
+
begin
|
59
|
+
puts 'Running migrations'.cyan
|
60
|
+
# set an activity timeout so it doesn't block forever
|
61
|
+
Rendezvous.start(url: response['attach_url'], activity_timeout: 600)
|
62
|
+
rescue => e
|
63
|
+
log.error("Error capturing output for dyno\n#{e.message}")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def scale(worker: nil, clock: nil)
|
68
|
+
heroku = PlatformAPI.connect_oauth @api_key
|
69
|
+
|
70
|
+
payload = {
|
71
|
+
updates: []
|
72
|
+
}
|
73
|
+
|
74
|
+
formations = heroku.formation.list(@app_name)
|
75
|
+
formations.each do |formation|
|
76
|
+
size = formation['size']
|
77
|
+
if !worker.nil? && formation['type'] == 'worker'
|
78
|
+
if formation['quantity'] != worker
|
79
|
+
payload[:updates] << {
|
80
|
+
process: 'worker',
|
81
|
+
quantity: worker,
|
82
|
+
size: size
|
83
|
+
}
|
84
|
+
puts "Scaling worker to #{worker}".cyan
|
85
|
+
else
|
86
|
+
puts "Worker is already scaled to #{worker}".yellow
|
87
|
+
end
|
88
|
+
elsif !clock.nil? && formation['type'] == 'clock'
|
89
|
+
if formation['quantity'] != clock
|
90
|
+
payload[:updates] << {
|
91
|
+
process: 'clock',
|
92
|
+
quantity: clock,
|
93
|
+
size: size
|
94
|
+
}
|
95
|
+
puts "Scaling clock to #{clock}".cyan
|
96
|
+
else
|
97
|
+
puts "Clock is already scaled to #{clock}".yellow
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
if payload[:updates].empty?
|
103
|
+
puts 'Warning: nothing to scale. Please check your configurations'.yellow
|
104
|
+
else
|
105
|
+
if payload[:updates].map { |u| u[:size] }.uniq.include? 'Free'
|
106
|
+
puts 'Warning: you can only run 2 dynos on the free tier'.yellow
|
107
|
+
updates = payload[:updates].sort { |a, b| a[:quantity] <=> b[:quantity] }
|
108
|
+
updates.each do |update|
|
109
|
+
type = update[:process]
|
110
|
+
quantity = update[:quantity]
|
111
|
+
heroku.formation.update(@app_name, type, quantity: quantity)
|
112
|
+
end
|
113
|
+
else
|
114
|
+
heroku.formation.batch_update(@app_name, payload)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def restart
|
120
|
+
heroku = PlatformAPI.connect_oauth @api_key
|
121
|
+
heroku.dyno.restart_all @app_name
|
122
|
+
end
|
123
|
+
|
124
|
+
def version
|
125
|
+
heroku = PlatformAPI.connect_oauth @api_key
|
126
|
+
build = heroku.build.list(@app_name).last
|
127
|
+
build['source_blob']['version']
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: heroku-platform-helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
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: platform-api
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.3'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rendezvous
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.1'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: colorize
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- t.paulrobertson@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/console
|
112
|
+
- bin/setup
|
113
|
+
- heroku-platform-helper.gemspec
|
114
|
+
- lib/heroku_helper.rb
|
115
|
+
- lib/heroku_helper/app.rb
|
116
|
+
- lib/heroku_helper/version.rb
|
117
|
+
homepage: https://github.com/perobertson/heroku-platform-helper
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.4.8
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: A helper library for managing Heroku apps.
|
141
|
+
test_files: []
|