heroku_builder 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5220d5a1b120ff0b29b32536875d540c791ec88d
4
- data.tar.gz: 31a7b6b0d8367547d9bb14ca37a7d4010399a767
3
+ metadata.gz: 9c1e7fd65d5f00bcf2611a0aad7c978cf51013ce
4
+ data.tar.gz: 62612b981eb174f5e068cd6d1172341931d36f92
5
5
  SHA512:
6
- metadata.gz: 827062c1314073cd9a5457c64aa4b7ae26613fa3dc2719426d77c42b7ad0c8ff81c9c8760039f6a1b38e37e80b2d0a2d3768b1750818d7141bf6f95adbbcac9b
7
- data.tar.gz: f0c6419243f65a0a31f081f13935d78b75a2ddf6135c3eca631db8879cc4566a97ee26b747ae4c45953490f17d9324d8e1274c39a96be0172d8994b6bfcb5c79
6
+ metadata.gz: 01dc148cbead348ac82d0a560797e11491ec23cf4a1b5cc5b784740fa8b7d3116b7adc43d702257de9a359dd16f0b468df0f09472de5ce4df5a80dee69df6a32
7
+ data.tar.gz: dc7af0370b374cc85c75d3b0374fbe44aa1b46e2fba02ac1902243604188befe5e454f9bcb31599b91f25a608b8d16be856018c8bf3cd0cebf393cc2f6e5f93d
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+
11
+ *.gem
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
- # HerokuBuilder
1
+ # Heroku Builder
2
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
3
+ Heroku Builder allows for straight forward configuration of your multi (or single) stage Heroku application as well as dead simple deployment. It uses a YAML configuration to manage a multi-environment configuration, including: configuration variables, resources, add-ons, and git based deployment.
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,7 +20,154 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ ### Getting Started
24
+
25
+ To get started, generate a new configuration file:
26
+
27
+ $ rake builder:init
28
+
29
+ This will place a file `config/heroku.yml with some basic configuration options. You'll want update the configuration files as you see fit for your particular setup. The configuration file is the meat of this tool, so let's take a look at what we can do with it.
30
+
31
+ ### Configuration
32
+
33
+ When you open `config/heroku.yml`, you'll see something like this:
34
+
35
+ ```yaml
36
+ staging:
37
+ app:
38
+ name: my-heroku-app-name-staging
39
+ git_repo: git@github.com:foo/my-heroku-app-name
40
+ git_branch: staging
41
+ config_vars: []
42
+ addons: []
43
+ resources:
44
+ web:
45
+ count: 1
46
+ type: Free
47
+ production:
48
+ app:
49
+ name: my-heroku-app-name
50
+ git_repo: git@github.com:foo/my-heroku-app-name
51
+ git_branch: master
52
+ config_vars: []
53
+ addons: []
54
+ resources:
55
+ web:
56
+ count: 1
57
+ type: Free
58
+
59
+ ```
60
+
61
+ Let's start from the outside and work our way in.
62
+
63
+ `staging` and `production` are references to the environments you maintain for a particular application. You can add as many of these as you'd like. These environments also determine the environment a Rake task targets. For example:
64
+
65
+ $ rake builder:staging:apply
66
+
67
+ Would apply the configuration for the `staging` environment.
68
+
69
+ The `app` sections provides settings particular to the application.
70
+ * `name` - the Heroku application name. The application will be created unless it already exists on Heroku.
71
+ * `git_repo` - the repository the project code is kept in. Code will be checked out from this repository as part of the deploy process, so you'll need at least read permission on the repo to deploy code to Heroku.
72
+ * `git_branch` - the branch of the `git_repo` repo that you wish to deploy from.
73
+
74
+ The `config_vars` setting allows you to set Config Vars for a particular environment. These can be applied as follows:
75
+
76
+ ```yaml
77
+ config_vars:
78
+ FOO: bar
79
+ BAZ: <%= ENV['BAZ'] %>
80
+ ```
81
+
82
+ Variables can be set with either a string or ERB tags. ERB tags allow sensitive information to be kept out of code that is committed. It's important to know that Heroku Builder only adds or updates variables that are defined in the configuration. Variables that are set in the Heroku console, but not defined in your configuration will not be removed.
83
+
84
+ The `addons` section allows you to define the Add-ons for a particular application. Add-ons are defined as an array:
85
+
86
+ ```yaml
87
+ addons:
88
+ - papertrail
89
+ - heroku-postgresql:hobby-dev
90
+ - heroku-redis:hobby-dev
91
+ - scheduler:standard
92
+ ```
93
+
94
+ As with other sections, be aware that removing add-on items will not cause them to be deleted from Heroku. Removing add-ons should be handled through the Heroku Dashboard.
95
+
96
+ The `resources` section allows a user to define the resource types and counts. An example of a resource section for a side project might look like:
97
+
98
+ ```yaml
99
+ resources:
100
+ web:
101
+ count: 1
102
+ type: Free
103
+ worker:
104
+ count: 1
105
+ type: Free
106
+ ```
107
+
108
+ For a production website, it might look more like:
109
+ ```yaml
110
+ resources:
111
+ web:
112
+ count: 8
113
+ type: 2X
114
+ worker:
115
+ count: 4
116
+ type: 1X
117
+ ```
118
+
119
+ ### Heroku API Key
120
+
121
+ Heroku Builder requires a Heroku API key. Directions for generating a key are here: [Heroku API Key](https://devcenter.heroku.com/articles/platform-api-quickstart)
122
+
123
+ The gem will look for the key in the HEROKU_API_KEY environment variable. The key can be set either in your environment variable library (ex. dotenv):
124
+
125
+ ```
126
+ # .env.local
127
+ HEROKU_API_KEY=xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxxx
128
+ ```
129
+
130
+ or in front of the rake task:
131
+
132
+ ```
133
+ HEROKU_API_KEY=xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxxx rake builder:staging:apply
134
+ ```
135
+
136
+
137
+
138
+ ### Running Rake Tasks
139
+
140
+ Heroku Builder currently has two actions: `apply` and `deploy`. Apply will:
141
+
142
+ * Create the application, if it has not been created
143
+ * Set Config-vars (if there are changes)
144
+ * Deploy code (if there are changes)
145
+ * Configure Add-ons (if there are changes)
146
+ * Configure Resources (if there are changes)
147
+
148
+ As `apply` only adds or updates when your `heroku.yml` file has changes, it's safe to always use `apply` to deploy code. Alternatively, you can just run the `deploy` portion. Deploy will:
149
+
150
+ * Switch to the branch for that environment
151
+ * Pull down any remote changes
152
+ * Create a remote for Heroku, if the remote is not present
153
+ * Push to that remote
154
+
155
+ The environments defined in your `heroku.yml` file provide scope for the Heroku Builder rake tasks. If you have the following:
156
+
157
+ ```yaml
158
+ foo:
159
+ ...
160
+ bar:
161
+ ...
162
+ ```
163
+
164
+ The four rake options would be:
165
+
166
+ $ rake builder:foo:apply
167
+ $ rake builder:foo:deploy
168
+ $ rake builder:bar:apply
169
+ $ rake builder:bar:deploy
170
+
26
171
 
27
172
  ## Development
28
173
 
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['Jason Vanderhoof']
10
10
  spec.email = ['jvanderhoof (at) google mail']
11
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.}
12
+ spec.summary = %q{Generate and manage multi-environment Heroku application and simple deployment.}
13
+ spec.description = %q{Heroku Builder allows for straight forward configuration of your multi (or single) stage Heroku application as well as dead simple deployment. It uses a YAML configuration to manage a multi-environment configuration, including: configuration variables, resources, add-ons, and git based deployment.}
14
14
  spec.homepage = 'https://github.com/jvanderhoof/heroku_builder.'
15
15
  spec.license = 'MIT'
16
16
 
@@ -1,6 +1,9 @@
1
1
  module HerokuBuilder
2
2
  class Base
3
3
  def conn
4
+ unless ENV['HEROKU_API_KEY']
5
+ fail 'No Heroku API Key found, please set it using the HEROKU_API_KEY environment variable'
6
+ end
4
7
  @conn ||= ::PlatformAPI.connect_oauth(ENV['HEROKU_API_KEY'])
5
8
  end
6
9
  end
@@ -32,7 +32,12 @@ module HerokuBuilder
32
32
  Resource.new.set_resources(name, resources)
33
33
  end
34
34
 
35
- def self.process(environment)
35
+ def self.deploy(environment)
36
+ name = config_from_environment(environment)['app']['name']
37
+ run_deployment(name, environment)
38
+ end
39
+
40
+ def self.apply(environment)
36
41
  config = config_from_environment(environment)
37
42
  name = config['app']['name']
38
43
 
@@ -43,7 +48,7 @@ module HerokuBuilder
43
48
  update_env_vars(name, environment)
44
49
 
45
50
  # deploy code
46
- # run_deployment(name, environment)
51
+ run_deployment(name, environment)
47
52
 
48
53
  # find or create addons
49
54
  update_addons(name, environment)
@@ -1,3 +1,3 @@
1
1
  module HerokuBuilder
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -1,27 +1,69 @@
1
1
  require 'heroku_builder'
2
2
 
3
3
  namespace :builder do
4
- # Utility functions from development
5
- # These may be removed...
4
+ # Utility functions from development. These may be removed...
6
5
  def pretty_print(hsh)
7
6
  hsh.keys.sort.each do |key|
8
7
  puts "#{key}: #{hsh[key].inspect}"
9
8
  end
10
9
  end
11
10
 
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
11
+ def config_file
12
+ 'config/heroku.yml'
13
+ end
14
+
15
+ # Rake setup per environment
16
+ if File.exist?(config_file)
17
+ HerokuBuilder::Service.config_file.keys.each do |env|
18
+ namespace env.to_sym do
19
+ task :apply do
20
+ HerokuBuilder::Service.apply(env)
21
+ end
18
22
 
19
- # task :plan do
20
- # changes('backstage').each do |change|
21
- # puts change
22
- # end
23
- # end
23
+ task :deploy do
24
+ HerokuBuilder::Service.deploy(env)
25
+ end
26
+
27
+ # task :plan do
28
+ # changes('backstage').each do |change|
29
+ # puts change
30
+ # end
31
+ # end
32
+ end
24
33
  end
25
34
  end
26
35
 
36
+ desc 'Initial yaml file setup'
37
+ task :init do
38
+ if File.exist?(config_file)
39
+ puts "Heroku Builder configaration file alread exists: `#{config_file}`. Please remove it if you want to generate a new configaration file."
40
+ exit
41
+ end
42
+
43
+ env_config = {
44
+ 'app' => {
45
+ 'name' => 'my-heroku-app-name',
46
+ 'git_repo' => 'git@github.com:foo/my-heroku-app-name',
47
+ 'git_branch' => 'master'
48
+ },
49
+ 'config_vars' => [],
50
+ 'addons' => [],
51
+ 'resources' => {
52
+ 'web' => {
53
+ 'count' => 1,
54
+ 'type' => 'Free'
55
+ }
56
+ }
57
+ }
58
+ config = {
59
+ 'staging' => Marshal.load(Marshal.dump(env_config)),
60
+ 'production' => Marshal.load(Marshal.dump(env_config))
61
+ }
62
+ config['staging']['app']['name'] = config['staging']['app']['name']+'-staging'
63
+ config['staging']['app']['git_branch'] = 'staging'
64
+
65
+ FileUtils.mkdir_p('config')
66
+ File.open(config_file, 'w') { |f| f.write(config.to_yaml) }
67
+ puts "Heroku Builder configuration file generated in `#{config_file}`"
68
+ end
27
69
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Vanderhoof
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-12 00:00:00.000000000 Z
11
+ date: 2015-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: platform-api
@@ -94,8 +94,10 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3.3'
97
- description: Add the ability to generate multiple heroku application environments
98
- and configurations.
97
+ description: 'Heroku Builder allows for straight forward configuration of your multi
98
+ (or single) stage Heroku application as well as dead simple deployment. It uses
99
+ a YAML configuration to manage a multi-environment configuration, including: configuration
100
+ variables, resources, add-ons, and git based deployment.'
99
101
  email:
100
102
  - jvanderhoof (at) google mail
101
103
  executables: []
@@ -148,6 +150,5 @@ rubyforge_project:
148
150
  rubygems_version: 2.4.5.1
149
151
  signing_key:
150
152
  specification_version: 4
151
- summary: Add the ability to generate multiple heroku application environments and
152
- configurations.
153
+ summary: Generate and manage multi-environment Heroku application and simple deployment.
153
154
  test_files: []