heroku_builder 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5220d5a1b120ff0b29b32536875d540c791ec88d
4
+ data.tar.gz: 31a7b6b0d8367547d9bb14ca37a7d4010399a767
5
+ SHA512:
6
+ metadata.gz: 827062c1314073cd9a5457c64aa4b7ae26613fa3dc2719426d77c42b7ad0c8ff81c9c8760039f6a1b38e37e80b2d0a2d3768b1750818d7141bf6f95adbbcac9b
7
+ data.tar.gz: f0c6419243f65a0a31f081f13935d78b75a2ddf6135c3eca631db8879cc4566a97ee26b747ae4c45953490f17d9324d8e1274c39a96be0172d8994b6bfcb5c79
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in heroku_builder.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 TODO: Write your name
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
+ # HerokuBuilder
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_builder`. 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_builder'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install heroku_builder
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/[USERNAME]/heroku_builder. 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
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "heroku_builder"
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,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'heroku_builder/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'heroku_builder'
8
+ spec.version = HerokuBuilder::VERSION
9
+ spec.authors = ['Jason Vanderhoof']
10
+ spec.email = ['jvanderhoof (at) google mail']
11
+
12
+ spec.summary = %q{Add the ability to generate multiple heroku application environments and configurations.}
13
+ spec.description = %q{Add the ability to generate multiple heroku application environments and configurations.}
14
+ spec.homepage = 'https://github.com/jvanderhoof/heroku_builder.'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_runtime_dependency 'platform-api', '~> 0.3.0'
31
+ spec.add_runtime_dependency 'hashdiff', '~> 0.2.2'
32
+ spec.add_runtime_dependency 'git', '~> 1.2'
33
+
34
+ spec.add_development_dependency 'bundler', '~> 1.10'
35
+ spec.add_development_dependency 'rake', '~> 10.0'
36
+ spec.add_development_dependency 'rspec', '~> 3.3'
37
+ end
@@ -0,0 +1,14 @@
1
+ require 'platform-api'
2
+
3
+ require 'heroku_builder/version'
4
+ require 'heroku_builder/base'
5
+ require 'heroku_builder/service'
6
+ require 'heroku_builder/app'
7
+ require 'heroku_builder/env_vars'
8
+ require 'heroku_builder/add_ons'
9
+ require 'heroku_builder/deployment'
10
+ require 'heroku_builder/resource'
11
+
12
+ module HerokuBuilder
13
+ require 'railtie' if defined?(Rails)
14
+ end
@@ -0,0 +1,25 @@
1
+ # Add Ons
2
+ module HerokuBuilder
3
+ class AddOns < Base
4
+ def addons(name)
5
+ conn.addon.list_by_app(name)
6
+ end
7
+
8
+ def addon_exists?(name, addon_name)
9
+ conn.addon.list_by_app(name).any? do |a|
10
+ # names appear to be stored in two different locations depending on the type
11
+ (!addon_name.include?(':') && a['addon_service']['name'] == addon_name) ||
12
+ a['plan']['name'] == addon_name
13
+ end
14
+ end
15
+
16
+ def set_addons(name, addons)
17
+ addons.each do |addon|
18
+ unless addon_exists?(name, addon)
19
+ puts "... adding #{addon}"
20
+ conn.addon.create(name, 'plan' => addon)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ module HerokuBuilder
2
+ class App < Base
3
+ def app_exists?(name)
4
+ !conn.app.list.detect { |a| a['name'] == name }.nil?
5
+ end
6
+
7
+ def find_or_create_app(name)
8
+ return if app_exists?(name)
9
+ conn.app.create(name: name, region: 'us', stack: 'cedar')
10
+ end
11
+
12
+ def app(name)
13
+ @app ||= conn.app.info(name)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ module HerokuBuilder
2
+ class Base
3
+ def conn
4
+ @conn ||= ::PlatformAPI.connect_oauth(ENV['HEROKU_API_KEY'])
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,32 @@
1
+ # Deployment
2
+ module HerokuBuilder
3
+ class Deployment < Base
4
+ def remote_exists?(branch)
5
+ git.remotes.detect { |remote| remote.name == branch }.nil?
6
+ end
7
+
8
+ def push(name, branch, environment)
9
+ remote_branch = "heroku-#{environment}"
10
+ if remote_exists?(remote_branch)
11
+ git.add_remote(remote_branch, app(name)['git_url'])
12
+ end
13
+ git.push(remote_branch, "#{branch}:master")
14
+ puts "remotes: #{git.remotes.map(&:name)}"
15
+ end
16
+
17
+ def git
18
+ @git ||= Git.open('.', log: Logger.new(STDOUT))
19
+ end
20
+
21
+ def deploy(name, branch, environment)
22
+ checkout(branch)
23
+ push(name, branch, environment)
24
+ end
25
+
26
+ def checkout(branch)
27
+ git.fetch
28
+ git.checkout(branch)
29
+ git.pull('origin', branch)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,27 @@
1
+ # ENV variables
2
+ module HerokuBuilder
3
+ class EnvVars < Base
4
+ def config_vars(name)
5
+ @config_vars ||= conn.config_var.info(name)
6
+ end
7
+
8
+ def set_config_vars(name, config_vars)
9
+ conn.config_var.update(name, config_vars)
10
+ end
11
+
12
+ def diff_config_vars(current, proposed)
13
+ diffs = HashDiff.diff(current, proposed)
14
+ diffs.select { |i| i.first.match(/~|\+/) }.map do |diff|
15
+ if diff.first == '~'
16
+ "Updating #{diff[1]} from: '#{diff[2]}' to: '#{diff[3]}'"
17
+ else
18
+ "Adding #{diff[1]} with: '#{diff[2]}'"
19
+ end
20
+ end
21
+ end
22
+
23
+ def config_env_changes(name, config_vars)
24
+ diff_config_vars(config_vars(name), config_vars)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ # Resources
2
+ module HerokuBuilder
3
+ class Resource < Base
4
+ def update_resource(name, type, size, count)
5
+ config_hsh = {
6
+ 'size' => size.capitalize,
7
+ 'quantity' => count.to_i
8
+ }
9
+ conn.formation.update(name, type, config_hsh)
10
+ end
11
+
12
+ def get_formation(name, type)
13
+ conn.formation.list(name).detect { |formation| formation['type'] == type }
14
+ end
15
+
16
+ def set_resources(name, resources)
17
+ resources.each do |type, config|
18
+ h_resource = get_formation(name, type)
19
+ if h_resource['size'] != config['type'].capitalize ||
20
+ h_resource['quantity'].to_i != config['count'].to_i
21
+ update_resource(name, type, config['type'], config['count'])
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,55 @@
1
+ module HerokuBuilder
2
+ class Service
3
+ def self.config_file
4
+ @config_file ||= YAML.load(ERB.new(File.read('config/heroku.yml')).result)
5
+ end
6
+
7
+ def self.config_from_environment(environment)
8
+ @config_from_environment ||= config_file[environment]
9
+ end
10
+
11
+ def self.update_app(name)
12
+ App.new.find_or_create_app(name)
13
+ end
14
+
15
+ def self.update_env_vars(name, environment)
16
+ env_vars = config_from_environment(environment)['config_vars']
17
+ EnvVars.new.set_config_vars(name, env_vars)
18
+ end
19
+
20
+ def self.run_deployment(name, environment)
21
+ git_branch = config_from_environment(environment)['app']['git_branch']
22
+ Deployment.new.deploy(name, git_branch, environment)
23
+ end
24
+
25
+ def self.update_addons(name, environment)
26
+ addons = config_from_environment(environment)['addons']
27
+ AddOns.new.set_addons(name, addons)
28
+ end
29
+
30
+ def self.update_resources(name, environment)
31
+ resources = config_from_environment(environment)['resources']
32
+ Resource.new.set_resources(name, resources)
33
+ end
34
+
35
+ def self.process(environment)
36
+ config = config_from_environment(environment)
37
+ name = config['app']['name']
38
+
39
+ # find or create app
40
+ update_app(name)
41
+
42
+ # set env variables
43
+ update_env_vars(name, environment)
44
+
45
+ # deploy code
46
+ # run_deployment(name, environment)
47
+
48
+ # find or create addons
49
+ update_addons(name, environment)
50
+
51
+ # find or create resource
52
+ update_resources(name, environment)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module HerokuBuilder
2
+ VERSION = "0.1.0"
3
+ end
data/lib/railtie.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'heroku_builder'
2
+ require 'rails'
3
+
4
+ module HerokuBuilder
5
+ class Railtie < Rails::Railtie
6
+ rake_tasks do
7
+ spec = Gem::Specification.find_by_name 'heroku_builder'
8
+ load "#{spec.gem_dir}/lib/tasks/heroku_builder.rake"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ require 'heroku_builder'
2
+
3
+ namespace :builder do
4
+ # Utility functions from development
5
+ # These may be removed...
6
+ def pretty_print(hsh)
7
+ hsh.keys.sort.each do |key|
8
+ puts "#{key}: #{hsh[key].inspect}"
9
+ end
10
+ end
11
+
12
+ # Rake setup
13
+ HerokuBuilder::Service.config_file.keys.each do |env|
14
+ namespace env.to_sym do
15
+ task :update do
16
+ HerokuBuilder::Service.process(env)
17
+ end
18
+
19
+ # task :plan do
20
+ # changes('backstage').each do |change|
21
+ # puts change
22
+ # end
23
+ # end
24
+ end
25
+ end
26
+
27
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: heroku_builder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Vanderhoof
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: platform-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: hashdiff
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: git
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.3'
97
+ description: Add the ability to generate multiple heroku application environments
98
+ and configurations.
99
+ email:
100
+ - jvanderhoof (at) google mail
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - heroku_builder.gemspec
116
+ - lib/heroku_builder.rb
117
+ - lib/heroku_builder/add_ons.rb
118
+ - lib/heroku_builder/app.rb
119
+ - lib/heroku_builder/base.rb
120
+ - lib/heroku_builder/deployment.rb
121
+ - lib/heroku_builder/env_vars.rb
122
+ - lib/heroku_builder/resource.rb
123
+ - lib/heroku_builder/service.rb
124
+ - lib/heroku_builder/version.rb
125
+ - lib/railtie.rb
126
+ - lib/tasks/heroku_builder.rake
127
+ homepage: https://github.com/jvanderhoof/heroku_builder.
128
+ licenses:
129
+ - MIT
130
+ metadata:
131
+ allowed_push_host: https://rubygems.org
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.4.5.1
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: Add the ability to generate multiple heroku application environments and
152
+ configurations.
153
+ test_files: []