heroku-forward 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -13,21 +13,20 @@ This gem implements a proxy using [em-proxy](https://github.com/igrigorik/em-pro
13
13
  Usage
14
14
  -----
15
15
 
16
- Add `heroku-forward` and `em-proxy` to your `Gemfile`. Curently requires HEAD of `em-proxy` because of [this pull request](https://github.com/igrigorik/em-proxy/pull/31).
16
+ Add `heroku-forward` to your `Gemfile`.
17
17
 
18
18
  ``` ruby
19
- gem "heroku-forward", "~> 0.1"
20
- gem "em-proxy", ">= 0.1.8"
19
+ gem "heroku-forward"
21
20
  ```
22
21
 
23
- Create an application rackup file, eg. `my_app.ru` that boots your application. Under Rails, this is the file that calls `run`.
22
+ Create a new application rackup file, eg. `my_app.ru` that boots your application. Under Rails, this is the file that calls `run`.
24
23
 
25
24
  ``` ruby
26
25
  require ::File.expand_path('../config/environment', __FILE__)
27
26
  run MyApp::Application
28
27
  ```
29
28
 
30
- Modify your rackup file as follows. Under Rails this file is called `config.ru`.
29
+ Modify your default rackup file as follows. Under Rails this file is called `config.ru`.
31
30
 
32
31
  ``` ruby
33
32
  require 'rubygems'
@@ -42,15 +41,16 @@ env = ENV['RACK_ENV'] || 'development'
42
41
  require 'em-proxy'
43
42
  require 'logger'
44
43
  require 'heroku-forward'
44
+ require 'heroku/forward/backends/thin'
45
45
 
46
46
  application = File.expand_path('../my_app.ru', __FILE__)
47
47
  backend = Heroku::Forward::Backends::Thin.new(application: application, env: env)
48
- proxy = Heroku::Forward::Proxy::Server.new(backend, { host: '0.0.0.0', port: port })
48
+ proxy = Heroku::Forward::Proxy::Server.new(backend, host: '0.0.0.0', port: port)
49
49
  proxy.logger = Logger.new(STDOUT)
50
50
  proxy.forward!
51
51
  ```
52
52
 
53
- This sets up a proxy on the port requested by Heroku and runs your application with Thin.
53
+ This sets up a proxy on the port requested by Heroku and runs your application with [Thin](http://code.macournoyer.com/thin). Other back-ends are also supported, see below.
54
54
 
55
55
  Foreman
56
56
  -------
@@ -88,27 +88,40 @@ Proxy Forwarding Options
88
88
 
89
89
  `Heroku::Forward::Proxy::Server.forward!` accepts the following options:
90
90
 
91
- * `delay`: number of seconds to sleep before launching the proxy, eg. `proxy.forward!(delay: 15)`. This prevents queuing of requests or reporting invalid `up` status to Heroku. It's recommended to set this value to as close as possible to the boot time of your application and less than the Heroku's 60s boot limit.
91
+ * **delay**: number of seconds to sleep before launching the proxy, eg. `proxy.forward!(delay: 15)`. This prevents queuing of requests or reporting invalid `up` status to Heroku. It's recommended to set this value to as close as possible to the boot time of your application and less than the Heroku's 60s boot limit. Also note that the proxy itself needs time to boot.
92
92
 
93
- SSL
94
- ---
95
- Heroku-forward has SSL support by forwarding SSL arguments to Thin. Know more about Thin & SSL:
93
+ Available Backends
94
+ ------------------
96
95
 
97
- ```sh
98
- thin -h
99
- SSL options:
100
- --ssl Enables SSL
101
- --ssl-key-file PATH Path to private key
102
- --ssl-cert-file PATH Path to certificate
103
- --ssl-verify Enables SSL certificate verification
96
+ ### Thin
97
+
98
+ For more information about Thin see [http://code.macournoyer.com/thin](http://code.macournoyer.com/thin).
99
+
100
+ ``` ruby
101
+ require 'heroku/forward/backends/thin'
102
+
103
+ application = File.expand_path('../my_app.ru', __FILE__)
104
+ backend = Heroku::Forward::Backends::Thin.new(application: application, env: env)
105
+ proxy = Heroku::Forward::Proxy::Server.new(backend, host: '0.0.0.0', port: port)
106
+ proxy.forward!
104
107
  ```
105
108
 
106
- In order to forward SSL arguments to thin update your config.ru
109
+ The Thin back-end supports the following options.
110
+
111
+ * **application**: application to load
112
+ * **env**: environment, eg. `:development`
113
+
114
+ SSL is also supported.
115
+
116
+ * **ssl**: enable SSL
117
+ * **ssl-key-file**: path to private key
118
+ * **ssl-cert-file**: path to certificate
119
+ * **ssl-verify**: enable SSL certificate verification
107
120
 
108
121
  ```ruby
109
122
  options = { application: File.expand_path('../my_app.ru', __FILE__) }
110
123
 
111
- # branch to desable SSL depending of your environment
124
+ # branch to disable SSL depending on your environment
112
125
  if ENV['THIN_SSL_ENABLED']
113
126
  options[:ssl] = true
114
127
  options[:ssl_verify] = true
@@ -119,10 +132,31 @@ end
119
132
  backend = Heroku::Forward::Backends::Thin.new(options)
120
133
  ```
121
134
 
135
+ ### Unicorn
136
+
137
+ For more information about Unicorn see [http://unicorn.bogomips.org](http://unicorn.bogomips.org/).
138
+
139
+ The Unicorn back-end supports the following options.
140
+
141
+ * **application**: application to load
142
+ * **env**: environment, eg. `:development`
143
+ * **config_file**: Unicorn configuration file
144
+
145
+ ```ruby
146
+ require 'heroku-forward'
147
+ require 'heroku/forward/backends/unicorn'
148
+
149
+ application = File.expand_path('../my_app.ru', __FILE__)
150
+ config_file = File.expand_path('../config/unicorn.rb', __FILE__)
151
+ backend = Heroku::Forward::Backends::Unicorn.new(application: application, env: env, config_file: config_file)
152
+ proxy = Heroku::Forward::Proxy::Server.new(backend, host: '0.0.0.0', port: port)
153
+ proxy.forward!
154
+ ```
155
+
122
156
  Fail-Safe
123
157
  ---------
124
158
 
125
- If you're worried about this implementation, consider building a fail-safe. Modify your `config.ru` to run without a proxy if `DISABLE_FORWARD_PROXY` is set as demonstrated in [this gist](https://gist.github.com/4263488). Add `DISABLE_FORWARD_PROXY` via `heroku config:add DISABLE_FORWARD_PROXY=1`.
159
+ If you're worried about always using heroku-forward, consider building a fail-safe. Modify your `config.ru` to run without a proxy if `DISABLE_FORWARD_PROXY` is set as demonstrated in [this gist](https://gist.github.com/4263488). Add `DISABLE_FORWARD_PROXY` via `heroku config:add DISABLE_FORWARD_PROXY=1`.
126
160
 
127
161
  Reading Materials
128
162
  -----------------
@@ -1 +1,6 @@
1
- require 'heroku/forward/backends/thin'
1
+ module Heroku
2
+ module Forward
3
+ module Backends
4
+ end
5
+ end
6
+ end
@@ -41,7 +41,7 @@ module Heroku
41
41
  spawn_with.push "--socket", @socket
42
42
  spawn_with.push "-e", @env.to_s
43
43
  spawn_with.push "--ssl" if @ssl
44
- spawn_with.push " --ssl-key-file", @ssl_key_file if @ssl_key_file
44
+ spawn_with.push "--ssl-key-file", @ssl_key_file if @ssl_key_file
45
45
  spawn_with.push "--ssl-cert-file", @ssl_cert_file if @ssl_cert_file
46
46
  spawn_with.push "--ssl-verify" if @ssl_verify
47
47
 
@@ -0,0 +1,54 @@
1
+ module Heroku
2
+ module Forward
3
+ module Backends
4
+ class Unicorn
5
+ attr_accessor :application, :socket, :environment, :pid, :config_file
6
+
7
+ def initialize(options = {})
8
+ @application = options[:application]
9
+ @socket = options[:socket] || tmp_filename('unicorn', '.sock')
10
+ @env = options[:env] || 'development'
11
+ @config_file = options[:config_file]
12
+ end
13
+
14
+ def spawn!
15
+ return false if spawned?
16
+ check!
17
+
18
+ args = ['unicorn']
19
+ args.push '--env', @env
20
+ args.push '--config-file', @config_file if @config_file
21
+ args.push '--listen', @socket
22
+ args.push @application
23
+
24
+ @pid = Spoon.spawnp(*args)
25
+ @spawned = true
26
+ end
27
+
28
+ def terminate!
29
+ return false unless spawned?
30
+ Process.kill 'QUIT', @pid
31
+ @spawned = false
32
+ true
33
+ end
34
+
35
+ def spawned?
36
+ !!@spawned
37
+ end
38
+
39
+ private
40
+
41
+ # Borrowed from ruby 1.9's Dir::Tmpname.make_tmpname for 1.8.7-compatibility.
42
+ def tmp_filename(prefix, suffix)
43
+ File.join Dir.tmpdir, "#{prefix}#{Time.now.strftime("%Y%m%d")}-#{$$}-#{rand(0x100000000).to_s(36)}#{suffix}"
44
+ end
45
+
46
+ def check!
47
+ raise Heroku::Forward::Errors::MissingBackendOptionError.new('application') unless @application && @application.length > 0
48
+ raise Heroku::Forward::Errors::MissingBackendApplicationError.new(@application) unless File.exists?(@application)
49
+ end
50
+
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,5 +1,5 @@
1
1
  module Heroku
2
2
  module Forward
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku-forward
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-15 00:00:00.000000000 Z
12
+ date: 2013-01-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: em-proxy
@@ -156,13 +156,13 @@ dependencies:
156
156
  - !ruby/object:Gem::Version
157
157
  version: '1.5'
158
158
  - !ruby/object:Gem::Dependency
159
- name: em-http-request
159
+ name: unicorn
160
160
  requirement: !ruby/object:Gem::Requirement
161
161
  none: false
162
162
  requirements:
163
163
  - - ~>
164
164
  - !ruby/object:Gem::Version
165
- version: '1.0'
165
+ version: '4.5'
166
166
  type: :development
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
@@ -170,23 +170,23 @@ dependencies:
170
170
  requirements:
171
171
  - - ~>
172
172
  - !ruby/object:Gem::Version
173
- version: '1.0'
173
+ version: '4.5'
174
174
  - !ruby/object:Gem::Dependency
175
- name: mocha
175
+ name: em-http-request
176
176
  requirement: !ruby/object:Gem::Requirement
177
177
  none: false
178
178
  requirements:
179
- - - ! '>='
179
+ - - ~>
180
180
  - !ruby/object:Gem::Version
181
- version: '0'
181
+ version: '1.0'
182
182
  type: :development
183
183
  prerelease: false
184
184
  version_requirements: !ruby/object:Gem::Requirement
185
185
  none: false
186
186
  requirements:
187
- - - ! '>='
187
+ - - ~>
188
188
  - !ruby/object:Gem::Version
189
- version: '0'
189
+ version: '1.0'
190
190
  description:
191
191
  email: dblock@dblock.org
192
192
  executables: []
@@ -199,6 +199,7 @@ files:
199
199
  - lib/heroku/forward.rb
200
200
  - lib/heroku/forward/backends.rb
201
201
  - lib/heroku/forward/backends/thin.rb
202
+ - lib/heroku/forward/backends/unicorn.rb
202
203
  - lib/heroku/forward/config/locales/en.yml
203
204
  - lib/heroku/forward/errors.rb
204
205
  - lib/heroku/forward/errors/backend_failed_to_start_error.rb
@@ -225,7 +226,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
225
226
  version: '0'
226
227
  segments:
227
228
  - 0
228
- hash: -1460208060339317613
229
+ hash: -4102819039813777077
229
230
  required_rubygems_version: !ruby/object:Gem::Requirement
230
231
  none: false
231
232
  requirements: