rack_heroku_meta 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/Gemfile +2 -0
- data/LICENSE +21 -0
- data/README.md +61 -0
- data/Rakefile +6 -0
- data/lib/rack/heroku_meta.rb +40 -0
- data/lib/rack/heroku_meta/version.rb +5 -0
- data/rack_heroku_meta.gemspec +24 -0
- data/spec/rack_heroku_meta_spec.rb +63 -0
- data/spec/spec_helper.rb +8 -0
- metadata +107 -0
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2012 Brendon Murphy
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
Rack::HerokuMeta
|
2
|
+
================
|
3
|
+
|
4
|
+
Rack middleware for checking the process commit hash on Heroku
|
5
|
+
|
6
|
+
Why
|
7
|
+
---
|
8
|
+
|
9
|
+
On Heroku deployments, a dyno ENV has PS and COMMIT_HASH values
|
10
|
+
that are useful for viewing the state of the deploy. The commit
|
11
|
+
hash contains the short sha1 from the most recent deploy, while
|
12
|
+
ps contains the process name of the dyno.
|
13
|
+
|
14
|
+
Sometimes when deploying to Heroku, a dyno gets "stuck" and
|
15
|
+
continues serving up the previous deploy. This can cause
|
16
|
+
problems. The middleware provides one way of quickly checking.
|
17
|
+
|
18
|
+
How
|
19
|
+
---
|
20
|
+
|
21
|
+
In your gemfile:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem "rack_heroku_meta", :require => "rack/heroku_meta"
|
25
|
+
```
|
26
|
+
|
27
|
+
In your rackup:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
use Rack::HerokuMeta # defaults to /heroku_meta
|
31
|
+
```
|
32
|
+
|
33
|
+
or with a configured route
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
use Rack::HerokuMeta, :route => "/foo_bar"
|
37
|
+
```
|
38
|
+
|
39
|
+
You can then hit the route with an http client of your choice
|
40
|
+
and parse the returned JSON data.
|
41
|
+
|
42
|
+
Security
|
43
|
+
--------
|
44
|
+
|
45
|
+
The endpoint exposes information about your current Heroku deploy.
|
46
|
+
While the information is probably benign, if you are concerned,
|
47
|
+
either deploy authentication middleware to protect the route, or
|
48
|
+
simply configure the route randomly like "/meta_6960VYT6vU0mK"
|
49
|
+
|
50
|
+
Alternatives
|
51
|
+
------------
|
52
|
+
|
53
|
+
The Heroku PS API is a more detailed way to view process data
|
54
|
+
about your entire application stack. However, if you want quick
|
55
|
+
and dirty, especially if you have minimal dynos running, this gem
|
56
|
+
can be of help.
|
57
|
+
|
58
|
+
#### Copyright
|
59
|
+
|
60
|
+
Copyright (c) (2012) Brendon Murphy. See LICENSE for details.
|
61
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "rack/heroku_meta/version"
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
class HerokuMeta
|
5
|
+
DEFAULT_ROUTE = "/heroku_meta"
|
6
|
+
|
7
|
+
def initialize(app, options = {})
|
8
|
+
@app = app
|
9
|
+
@route = options.fetch(:route, DEFAULT_ROUTE)
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
dup._call(env)
|
14
|
+
end
|
15
|
+
|
16
|
+
def _call(env)
|
17
|
+
if env["PATH_INFO"] == @route
|
18
|
+
env["REQUEST_METHOD"] == "GET" ? serve_meta : not_found
|
19
|
+
else
|
20
|
+
@app.call(env)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def not_found
|
27
|
+
[404, { "Content-Type" => "plain/text" }, ["Not Found"]]
|
28
|
+
end
|
29
|
+
|
30
|
+
def meta
|
31
|
+
ps = ENV["PS"]
|
32
|
+
commit_hash = ENV["COMMIT_HASH"]
|
33
|
+
%Q({"ps":"#{ps}","commit_hash":"#{commit_hash}"})
|
34
|
+
end
|
35
|
+
|
36
|
+
def serve_meta
|
37
|
+
[200, { "Content-Type" => "application/json" }, [meta]]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rack/heroku_meta/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rack_heroku_meta"
|
7
|
+
s.version = Rack::HerokuMeta::VERSION
|
8
|
+
s.authors = ["Brendon Murphy"]
|
9
|
+
s.email = ["xternal1+github@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Rack middleware for checking the process commit hash on Heroku}
|
12
|
+
s.description = s.summary
|
13
|
+
|
14
|
+
s.rubyforge_project = "rack_heroku_meta"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_dependency "rack"
|
21
|
+
s.add_development_dependency "rake"
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
s.add_development_dependency "json"
|
24
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Requests using Rack::HerokuMeta" do
|
4
|
+
let(:app) {
|
5
|
+
Rack::Builder.new do
|
6
|
+
use Rack::HerokuMeta
|
7
|
+
run lambda { |env| [200, { 'Content-Type' => "text/plain" }, ["bar"]]}
|
8
|
+
end
|
9
|
+
}
|
10
|
+
|
11
|
+
context "for a GET to the default /heroku_meta route" do
|
12
|
+
let(:response) {
|
13
|
+
Rack::MockRequest.new(app).get('/heroku_meta')
|
14
|
+
}
|
15
|
+
|
16
|
+
it "returns content-type of application/json" do
|
17
|
+
response.headers["Content-Type"].should == "application/json"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "includes ENV['PS']" do
|
21
|
+
ENV["PS"] = "web.42"
|
22
|
+
JSON.parse(response.body)["ps"].should == "web.42"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "includes ENV['COMMIT_HASH']" do
|
26
|
+
ENV["COMMIT_HASH"] = "ab123f"
|
27
|
+
JSON.parse(response.body)["commit_hash"].should == "ab123f"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "for a POST to the default route" do
|
32
|
+
it "is status 404" do
|
33
|
+
response = Rack::MockRequest.new(app).post('/heroku_meta')
|
34
|
+
response.status.should == 404
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "for another route" do
|
39
|
+
it "passes it through the app stack" do
|
40
|
+
response = Rack::MockRequest.new(app).get('/foo')
|
41
|
+
response.status.should == 200
|
42
|
+
response.body.should == "bar"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "for a configured meta route" do
|
47
|
+
let(:app) {
|
48
|
+
Rack::Builder.new do
|
49
|
+
use Rack::HerokuMeta, :route => "/foo_bar_321"
|
50
|
+
run lambda { |env| [200, { 'Content-Type' => "text/plain" }, ["bar"]]}
|
51
|
+
end
|
52
|
+
}
|
53
|
+
|
54
|
+
it "returns the meta info" do
|
55
|
+
ENV["PS"] = "web.77"
|
56
|
+
ENV["COMMIT_HASH"] = "123456"
|
57
|
+
response = Rack::MockRequest.new(app).get('/foo_bar_321')
|
58
|
+
meta = JSON.parse(response.body)
|
59
|
+
meta["ps"].should == "web.77"
|
60
|
+
meta["commit_hash"].should == "123456"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack_heroku_meta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brendon Murphy
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-07 00:00:00.000000000 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rack
|
17
|
+
requirement: &2156434620 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2156434620
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rake
|
28
|
+
requirement: &2156433980 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *2156433980
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
requirement: &2156433460 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *2156433460
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: json
|
50
|
+
requirement: &2156432680 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *2156432680
|
59
|
+
description: Rack middleware for checking the process commit hash on Heroku
|
60
|
+
email:
|
61
|
+
- xternal1+github@gmail.com
|
62
|
+
executables: []
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- .gitignore
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- lib/rack/heroku_meta.rb
|
72
|
+
- lib/rack/heroku_meta/version.rb
|
73
|
+
- rack_heroku_meta.gemspec
|
74
|
+
- spec/rack_heroku_meta_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
has_rdoc: true
|
77
|
+
homepage: ''
|
78
|
+
licenses: []
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
hash: -2478329712318999610
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
hash: -2478329712318999610
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project: rack_heroku_meta
|
103
|
+
rubygems_version: 1.6.2
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: Rack middleware for checking the process commit hash on Heroku
|
107
|
+
test_files: []
|