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 +4 -4
- data/.gitignore +2 -0
- data/README.md +150 -5
- data/heroku_builder.gemspec +2 -2
- data/lib/heroku_builder/base.rb +3 -0
- data/lib/heroku_builder/service.rb +7 -2
- data/lib/heroku_builder/version.rb +1 -1
- data/lib/tasks/heroku_builder.rake +55 -13
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c1e7fd65d5f00bcf2611a0aad7c978cf51013ce
|
4
|
+
data.tar.gz: 62612b981eb174f5e068cd6d1172341931d36f92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01dc148cbead348ac82d0a560797e11491ec23cf4a1b5cc5b784740fa8b7d3116b7adc43d702257de9a359dd16f0b468df0f09472de5ce4df5a80dee69df6a32
|
7
|
+
data.tar.gz: dc7af0370b374cc85c75d3b0374fbe44aa1b46e2fba02ac1902243604188befe5e454f9bcb31599b91f25a608b8d16be856018c8bf3cd0cebf393cc2f6e5f93d
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# Heroku Builder
|
2
2
|
|
3
|
-
|
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
|
-
|
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
|
|
data/heroku_builder.gemspec
CHANGED
@@ -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{
|
13
|
-
spec.description = %q{
|
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
|
|
data/lib/heroku_builder/base.rb
CHANGED
@@ -32,7 +32,12 @@ module HerokuBuilder
|
|
32
32
|
Resource.new.set_resources(name, resources)
|
33
33
|
end
|
34
34
|
|
35
|
-
def self.
|
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
|
-
|
51
|
+
run_deployment(name, environment)
|
47
52
|
|
48
53
|
# find or create addons
|
49
54
|
update_addons(name, environment)
|
@@ -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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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.
|
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-
|
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:
|
98
|
-
|
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:
|
152
|
-
configurations.
|
153
|
+
summary: Generate and manage multi-environment Heroku application and simple deployment.
|
153
154
|
test_files: []
|