heroku-forward 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  Heroku::Forward [![Build Status](https://travis-ci.org/dblock/heroku-forward.png?branch=master)](https://travis-ci.org/dblock/heroku-forward)
2
2
  ===============
3
3
 
4
- Beat Heroku's 60 seconds timeout with a forward proxy.
4
+ Beat Heroku's 60 seconds timeout with a proxy.
5
5
 
6
6
  What's this?
7
7
  ------------
8
8
 
9
9
  [Heroku](http://www.heroku.com/) will report an application crashing and yield an `R10 Boot Timeout` error when a web process took longer than 60 seconds to bind to its assigned `$PORT`. This error is often caused by a process being unable to reach an external resource, such as a database or because Heroku is pretty slow and you have a lot of gems in your `Gemfile`.
10
10
 
11
- This gem implements a forward proxy using [em-proxy](https://github.com/igrigorik/em-proxy). This proxy is booted almost immediately, binding to the port assigned by Heroku. Heroku now reports the dyno up. The proxy then spawns your application's web server and establishes a connection over a unix domain socket (a file) between the proxy and the application. Once the application is ready, it will be able to serve HTTP requests normally. Until then requests may queue and some may timeout depending on how long it actually takes to start.
11
+ This gem implements a proxy using [em-proxy](https://github.com/igrigorik/em-proxy). This proxy is booted almost immediately, binding to the port assigned by Heroku. Heroku now reports the dyno up. The proxy then spawns your application's web server and establishes a connection over a unix domain socket (a file) between the proxy and the application. Once the application is ready, it will be able to serve HTTP requests normally. Until then requests may queue and some may timeout depending on how long it actually takes to start.
12
12
 
13
13
  Usage
14
14
  -----
@@ -16,8 +16,8 @@ Usage
16
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).
17
17
 
18
18
  ``` ruby
19
- gem "heroku-forward", :git => "https://github.com/dblock/heroku-forward.git"
20
- gem "em-proxy", :git => "https://github.com/igrigorik/em-proxy.git"
19
+ gem "heroku-forward", "~> 0.1"
20
+ gem "em-proxy", ">= 0.1.8"
21
21
  ```
22
22
 
23
23
  Create an application rackup file, eg. `my_app.ru` that boots your application. Under Rails, this is the file that calls `run`.
@@ -90,6 +90,35 @@ Proxy Forwarding Options
90
90
 
91
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.
92
92
 
93
+ SSL
94
+ ---
95
+ Heroku-forward has SSL support by forwarding SSL arguments to Thin. Know more about Thin & SSL:
96
+
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
104
+ ```
105
+
106
+ In order to forward SSL arguments to thin update your config.ru
107
+
108
+ ```ruby
109
+ options = { application: File.expand_path('../my_app.ru', __FILE__) }
110
+
111
+ # branch to desable SSL depending of your environment
112
+ if ENV['THIN_SSL_ENABLED']
113
+ options[:ssl] = true
114
+ options[:ssl_verify] = true
115
+ options[:ssl_cert_file] = ENV['THIN_SSL_CERT_FILE']
116
+ options[:ssl_key_file] = ENV['THIN_SSL_KEY_FILE']
117
+ end
118
+
119
+ backend = Heroku::Forward::Backends::Thin.new(options)
120
+ ```
121
+
93
122
  Fail-Safe
94
123
  ---------
95
124
 
@@ -103,6 +132,7 @@ Reading Materials
103
132
  * [Fighting the Unicorns: Becoming a Thin Wizard on Heroku](http://jgwmaxwell.com/fighting-the-unicorns-becoming-a-thin-wizard-on-heroku/) by JGW Maxwell
104
133
  * [eventmachine](https://github.com/eventmachine/eventmachine)
105
134
  * [em-proxy](https://github.com/igrigorik/em-proxy)
135
+ * [Setup rails 3.2 & heroku-forward with SSL](https://gist.github.com/4540602)
106
136
 
107
137
  Contributing
108
138
  ------------
@@ -1,7 +1,8 @@
1
1
  require 'i18n'
2
2
  require 'tempfile'
3
3
  require 'em-proxy'
4
- require 'posix/spawn'
4
+ require 'ffi'
5
+ require 'spoon'
5
6
 
6
7
  I18n.load_path << File.join(File.dirname(__FILE__), "heroku", "forward", "config", "locales", "en.yml")
7
8
 
@@ -2,27 +2,50 @@ module Heroku
2
2
  module Forward
3
3
  module Backends
4
4
  class Thin
5
- include POSIX::Spawn
6
-
7
5
  attr_accessor :application
8
6
  attr_accessor :socket
9
7
  attr_accessor :environment
10
8
  attr_accessor :pid
11
9
 
10
+ attr_accessor :ssl
11
+ attr_accessor :ssl_key_file
12
+ attr_accessor :ssl_cert_file
13
+ attr_accessor :ssl_verify
14
+
12
15
  # options:
13
- # application: passed with -R, eg. app.ru
14
- # socket: passed with --socket, eg. /tmp/thin.sock
15
- # env: passed with -e, defaults to 'development'
16
+ # application: passed with -R, eg. app.ru
17
+ # socket: passed with --socket, eg. /tmp/thin.sock
18
+ # env: passed with -e, defaults to 'development'
19
+ # ssl: activated with --ssl
20
+ # ssl_key_file: passed with ssl_key_file PATH
21
+ # ssl_cert_file: passed with ssl_cert_file PATH
22
+ # ssl_verify: activated with ssl_verify
16
23
  def initialize(options = {})
17
24
  @application = options[:application]
18
25
  @socket = options[:socket] || new_socket
19
26
  @env = options[:env] || :development
27
+
28
+ @ssl = options[:ssl] || false
29
+ @ssl_key_file = options[:ssl_key_file] || false
30
+ @ssl_cert_file = options[:ssl_cert_file] || false
31
+ @ssl_verify = options[:ssl_verify] || false
20
32
  end
21
33
 
22
34
  def spawn!
23
35
  return false if spawned?
24
36
  check!
25
- @pid = spawn("thin start -R #{@application} --socket #{@socket} -e #{@env}")
37
+
38
+ spawn_with = [ "thin" ]
39
+ spawn_with.push "start"
40
+ spawn_with.push "-R", @application
41
+ spawn_with.push "--socket", @socket
42
+ spawn_with.push "-e", @env.to_s
43
+ spawn_with.push "--ssl" if @ssl
44
+ spawn_with.push " --ssl-key-file", @ssl_key_file if @ssl_key_file
45
+ spawn_with.push "--ssl-cert-file", @ssl_cert_file if @ssl_cert_file
46
+ spawn_with.push "--ssl-verify" if @ssl_verify
47
+
48
+ @pid = Spoon.spawnp(* spawn_with)
26
49
  @spawned = true
27
50
  end
28
51
 
@@ -1,5 +1,5 @@
1
1
  module Heroku
2
2
  module Forward
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.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.1.0
4
+ version: 0.2.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: 2012-12-13 00:00:00.000000000 Z
12
+ date: 2013-01-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: em-proxy
@@ -44,13 +44,29 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0.6'
46
46
  - !ruby/object:Gem::Dependency
47
- name: posix-spawn
47
+ name: ffi
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: spoon
48
64
  requirement: !ruby/object:Gem::Requirement
49
65
  none: false
50
66
  requirements:
51
67
  - - ~>
52
68
  - !ruby/object:Gem::Version
53
- version: '0.3'
69
+ version: 0.0.1
54
70
  type: :runtime
55
71
  prerelease: false
56
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +74,7 @@ dependencies:
58
74
  requirements:
59
75
  - - ~>
60
76
  - !ruby/object:Gem::Version
61
- version: '0.3'
77
+ version: 0.0.1
62
78
  - !ruby/object:Gem::Dependency
63
79
  name: rake
64
80
  requirement: !ruby/object:Gem::Requirement
@@ -155,6 +171,22 @@ dependencies:
155
171
  - - ~>
156
172
  - !ruby/object:Gem::Version
157
173
  version: '1.0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: mocha
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
158
190
  description:
159
191
  email: dblock@dblock.org
160
192
  executables: []
@@ -193,7 +225,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
193
225
  version: '0'
194
226
  segments:
195
227
  - 0
196
- hash: 394519437
228
+ hash: -1460208060339317613
197
229
  required_rubygems_version: !ruby/object:Gem::Requirement
198
230
  none: false
199
231
  requirements: