Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Rack support #1

Merged
merged 4 commits into from

2 participants

@xaviershay
Owner

@sconover what do you reckon? "If" check on existence of config/environment.rb is maybe a bit dodge, but it would be nice not to have to require an explicit configuration.

@xaviershay
Owner

@sconover I still think these commits are a good idea. Would love your thoughts.

@sconover
Owner

sweet, want me to click the button?

@xaviershay xaviershay merged commit 368ba8d into master
@cheister cheister referenced this pull request from a commit
Chris Heisterkamp This change does not work for rails projects if you do not run jetpac…
…k on the machine that you are deploying to since it uses app_root to determine if it is a rails project.

Revert "Merge pull request #1 from square/rack-support"

This reverts commit 368ba8d, reversing
changes made to e9631fe.
35ca1b4
@tamird tamird deleted the rack-support branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 23, 2012
  1. @xaviershay
  2. @xaviershay
Commits on Jan 25, 2012
  1. @xaviershay
  2. @xaviershay

    Only include RAILS_ENV for rails projects.

    xaviershay authored
    I can't figure out a good test for this, but can replicate on our app.
This page is out of date. Refresh to see the latest.
View
7 bin/jetpack
@@ -159,6 +159,13 @@ if @settings.jetty?
web_inf_dir = File.join(@path_to_project, "WEB-INF")
mkdir_p web_inf_dir
+ @listener = if @settings.rails?
+ "org.jruby.rack.rails.RailsServletContextListener"
+ else
+ # Rails does this for us, but jetty won't load if there is no log dir.
+ FileUtils.mkdir_p(File.join(@path_to_project, "log"))
+ "org.jruby.rack.RackServletContextListener"
+ end
overlay_files File.join(@jetpack_dir, "web_inf_files"), web_inf_dir
end
View
22 jetty_files/etc/jetty.xml.erb
@@ -47,16 +47,18 @@
</Arg>
</Call>
- <!-- set the rails.env java system property based on the RAILS_ENV environment variable -->
- <!-- this is used by jruby-rack to set Rails.env -->
- <Call class="java.lang.System" name="setProperty">
- <Arg>rails.env</Arg>
- <Arg>
- <Call class="java.lang.System" name="getenv">
- <Arg>RAILS_ENV</Arg>
- </Call>
- </Arg>
- </Call>
+ <% if @settings.rails? %>
+ <!-- set the rails.env java system property based on the RAILS_ENV environment variable -->
+ <!-- this is used by jruby-rack to set Rails.env -->
+ <Call class="java.lang.System" name="setProperty">
+ <Arg>rails.env</Arg>
+ <Arg>
+ <Call class="java.lang.System" name="getenv">
+ <Arg>RAILS_ENV</Arg>
+ </Call>
+ </Arg>
+ </Call>
+ <% end %>
<Set name="handler">
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
View
4 lib/jetpack/settings.rb
@@ -37,6 +37,10 @@ def jetty?
respond_to?(:jetty)
end
+ def rails?
+ File.exists?(File.join(app_root, "config/environment.rb"))
+ end
+
def jetty_pid_path
File.join(app_root, "/vendor/jetty/run/jetty.pid")
end
View
39 spec/rack_spec.rb
@@ -0,0 +1,39 @@
+require "spec_helper"
+require "yaml"
+
+describe "jetpack - web start for rack app" do
+ before(:all) do
+ reset
+ @result = x!("bin/jetpack spec/sample_projects/rack_19")
+ end
+
+ after(:all) do
+ reset
+ end
+
+ it "runs" do
+ pid_to_kill = run_app("spec/sample_projects/rack_19")
+
+ #HTTP 4443 - intended to be proxied to from something listening on 443
+ x!("curl https://localhost:10443/hello --insecure")[:stdout].split("<br/>").first.strip.should == "Hello World"
+
+ #HTTP 9080 - intended for internal health checking
+ x!("curl http://localhost:10080/hello --insecure")[:stdout].split("<br/>").first.strip.should == "Hello World"
+
+ system("kill -9 #{pid_to_kill}")
+ end
+
+ def run_app(app)
+ jetty_pid = Process.spawn({'RAILS_ENV' => 'development'}, 'java', '-jar', 'start.jar', {:chdir => "#{app}/vendor/jetty"})
+ start_time = Time.now
+ loop do
+ begin
+ TCPSocket.open("localhost", 10443)
+ return jetty_pid
+ rescue Errno::ECONNREFUSED
+ raise "it's taking too long to start the server, something might be wrong" if Time.now - start_time > 60
+ sleep 0.1
+ end
+ end
+ end
+end
View
3  spec/sample_projects/rack_19/Gemfile
@@ -0,0 +1,3 @@
+source :rubygems
+
+gem 'rack'
View
11 spec/sample_projects/rack_19/Gemfile.lock
@@ -0,0 +1,11 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ rack (1.4.1)
+
+PLATFORMS
+ java
+ ruby
+
+DEPENDENCIES
+ rack
View
8 spec/sample_projects/rack_19/config.ru
@@ -0,0 +1,8 @@
+hash_in_19_syntax = {
+ a: 1
+}
+
+run Proc.new {|env| [200,
+ {"Content-Type" => "application/json"},
+ ["Hello World"]
+]}
View
6 spec/sample_projects/rack_19/config/jetpack.yml
@@ -0,0 +1,6 @@
+jruby: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-complete-1.6.4.jar"
+jetty: "file://<%= File.expand_path('spec/local_mirror') %>/jetty-hightide-7.4.5.v20110725.zip"
+jruby-rack: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-rack-1.0.10.jar"
+http_port: 10080
+https_port: 10443
+ruby_version: 1.9
View
8 web_inf_files/web.xml.erb
@@ -12,6 +12,12 @@
</context-param>
<context-param>
+ <param-name>jruby.compat.version</param-name>
+ <param-value><%= @settings.ruby_version %></param-value>
+ </context-param>
+
+
+ <context-param>
<param-name>rails.root</param-name>
<param-value>.</param-value>
</context-param>
@@ -42,6 +48,6 @@
</filter-mapping>
<listener>
- <listener-class>org.jruby.rack.rails.RailsServletContextListener</listener-class>
+ <listener-class><%= @listener %></listener-class>
</listener>
</web-app>
Something went wrong with that request. Please try again.