Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added JRuby on Heroku support:

  - Jemfile
  - Procfile
  - pom.xml
  - script/jruby
  - requisite changes for config/database.yml
  • Loading branch information...
commit 49d94b5759ca32ff93c6d66c89187f86d9a816c6 1 parent 3f0c2e0
Mathew Rodley authored August 07, 2011
35  Gemfile
... ...
@@ -1,35 +0,0 @@
1  
-source 'http://rubygems.org'
2  
-
3  
-gem 'rails', '3.0.0'
4  
-
5  
-# Bundle edge Rails instead:
6  
-# gem 'rails', :git => 'git://github.com/rails/rails.git'
7  
-
8  
-# gem 'sqlite3-ruby', :require => 'sqlite3'
9  
-
10  
-# Use unicorn as the web server
11  
-# gem 'unicorn'
12  
-
13  
-# Deploy with Capistrano
14  
-# gem 'capistrano'
15  
-
16  
-# To use debugger
17  
-# gem 'ruby-debug'
18  
-
19  
-# Bundle the extra gems:
20  
-# gem 'bj'
21  
-# gem 'nokogiri', '1.4.1'
22  
-gem 'sqlite3-ruby', :require => 'sqlite3', :group => :development
23  
-# gem 'aws-s3', :require => 'aws/s3'
24  
-gem "will_paginate"
25  
-gem "acts-as-taggable-on"
26  
-gem "gchartrb"
27  
-
28  
-
29  
-# Bundle gems for certain environments:
30  
-# gem 'rspec', :group => :test
31  
-# group :test do
32  
-#   gem 'webrat'
33  
-# end
34  
-
35  
-
14  Jemfile
... ...
@@ -0,0 +1,14 @@
  1
+source 'http://rubygems.org'
  2
+
  3
+gem 'rails', '3.0.0'
  4
+gem "will_paginate"
  5
+gem "acts-as-taggable-on"
  6
+gem "gchartrb"
  7
+
  8
+group :development, :test do
  9
+	gem 'activerecord-jdbcsqlite3-adapter'
  10
+end
  11
+
  12
+group :production do
  13
+	gem 'activerecord-jdbcpostgresql-adapter'
  14
+end
4  Procfile
... ...
@@ -0,0 +1,4 @@
  1
+web:			sh script/jruby script/rails server -p $PORT
  2
+console:	sh script/jruby script/rails console
  3
+rake:			sh script/jruby -S rake
  4
+jruby:		sh script/jruby
11  config/database.yml
... ...
@@ -1,7 +1,7 @@
1 1
 # SQLite version 3.x
2  
-#   gem install sqlite3-ruby (not necessary on OS X Leopard)
  2
+#   gem install sqlite3
3 3
 development:
4  
-  adapter: sqlite3
  4
+  adapter: jdbcsqlite3
5 5
   database: db/development.sqlite3
6 6
   pool: 5
7 7
   timeout: 5000
@@ -10,13 +10,14 @@ development:
10 10
 # re-generated from your development database when you run "rake".
11 11
 # Do not set this db to the same as development or production.
12 12
 test:
13  
-  adapter: sqlite3
  13
+  adapter: jdbcsqlite3
14 14
   database: db/test.sqlite3
15 15
   pool: 5
16 16
   timeout: 5000
17 17
 
18 18
 production:
19  
-  adapter: sqlite3
20  
-  database: db/production.sqlite3
  19
+  adapter: jdbcpostgresql
  20
+  url: <%= ENV["DATABASE_URL"].gsub(/postgres:\/\/(.*):(.*)@(.*)/) { "jdbc:postgresql://#{$3}?user=#{$1}&password=#{$2}" } rescue "unknown" %>
21 21
   pool: 5
22 22
   timeout: 5000
  23
+
53  pom.xml
... ...
@@ -0,0 +1,53 @@
  1
+<project>
  2
+  <modelVersion>4.0.0</modelVersion>
  3
+  <groupId>au.com.mathew</groupId>
  4
+  <artifactId>jruby-heroku</artifactId>
  5
+	<version>1.0</version>
  6
+	<name>webapp</name>
  7
+	<packaging>jar</packaging>
  8
+  <dependencies>
  9
+		<dependency>
  10
+				<groupId>org.jruby</groupId>
  11
+				<artifactId>jruby-complete</artifactId>
  12
+				<version>1.6.3</version>
  13
+		</dependency>
  14
+		<dependency>
  15
+				<groupId>org.jruby.plugins</groupId>
  16
+				<artifactId>jruby-rake-plugin</artifactId>
  17
+				<version>1.6.3</version>
  18
+		</dependency>
  19
+  </dependencies>
  20
+	<build>
  21
+		<plugins>
  22
+			<plugin>
  23
+				<groupId>org.jruby.plugins</groupId>
  24
+				<artifactId>jruby-rake-plugin</artifactId>
  25
+				<version>1.6.3</version>
  26
+				<executions>
  27
+					<execution>
  28
+						<id>install-bundler</id>
  29
+						<phase>process-resources</phase>
  30
+						<goals>
  31
+							<goal>jruby</goal>
  32
+						</goals>
  33
+						<configuration>
  34
+						 <args>-S gem install bundler --no-ri --no-rdoc --install-dir .gems</args>
  35
+						</configuration>
  36
+					</execution>
  37
+					<execution>
  38
+						<id>bundle-install</id>
  39
+						<phase>process-resources</phase>
  40
+						<goals>
  41
+							<goal>jruby</goal>
  42
+						</goals>
  43
+						<configuration>
  44
+							<args>
  45
+								-e ENV['GEM_HOME']=File.join(Dir.pwd,'.gems');ENV['GEM_PATH']=File.join(Dir.pwd,'.gems');ENV['BUNDLE_GEMFILE']=File.join(Dir.pwd,'Jemfile');require'rubygems';require'bundler';require'bundler/cli';cli=Bundler::CLI.new;cli.install
  46
+							</args>
  47
+						</configuration>
  48
+					</execution>
  49
+				 </executions>
  50
+			 </plugin>
  51
+		</plugins>
  52
+  </build>
  53
+</project>
115  script/jruby
... ...
@@ -0,0 +1,115 @@
  1
+#!/bin/sh
  2
+# ----------------------------------------------------------------------------
  3
+#  Copyright 2001-2006 The Apache Software Foundation.
  4
+#
  5
+#  Licensed under the Apache License, Version 2.0 (the "License");
  6
+#  you may not use this file except in compliance with the License.
  7
+#  You may obtain a copy of the License at
  8
+#
  9
+#       http://www.apache.org/licenses/LICENSE-2.0
  10
+#
  11
+#  Unless required by applicable law or agreed to in writing, software
  12
+#  distributed under the License is distributed on an "AS IS" BASIS,
  13
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14
+#  See the License for the specific language governing permissions and
  15
+#  limitations under the License.
  16
+# ----------------------------------------------------------------------------
  17
+
  18
+#   Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
  19
+#   reserved.
  20
+
  21
+APPDIR=`pwd`
  22
+BASEDIR=`dirname $0`/..
  23
+BASEDIR=`(cd "$BASEDIR"; pwd)`
  24
+
  25
+# OS specific support.  $var _must_ be set to either true or false.
  26
+cygwin=false;
  27
+darwin=false;
  28
+case "`uname`" in
  29
+  CYGWIN*) cygwin=true ;;
  30
+  Darwin*) darwin=true
  31
+           if [ -z "$JAVA_VERSION" ] ; then
  32
+             JAVA_VERSION="CurrentJDK"
  33
+           else
  34
+             echo "Using Java version: $JAVA_VERSION"
  35
+           fi
  36
+           if [ -z "$JAVA_HOME" ] ; then
  37
+             JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home
  38
+           fi
  39
+           ;;
  40
+esac
  41
+
  42
+if [ "$darwin" = "false" ] && [ $cygwin = "false" ]; then
  43
+	APPDIR="$(dirname $(dirname $(readlink -fn "$0")))"
  44
+fi
  45
+
  46
+if [ -z "$JAVA_HOME" ] ; then
  47
+  if [ -r /etc/gentoo-release ] ; then
  48
+    JAVA_HOME=`java-config --jre-home`
  49
+  fi
  50
+fi
  51
+
  52
+# For Cygwin, ensure paths are in UNIX format before anything is touched
  53
+if $cygwin ; then
  54
+  [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  55
+  [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
  56
+fi
  57
+
  58
+# If a specific java binary isn't specified search for the standard 'java' binary
  59
+if [ -z "$JAVACMD" ] ; then
  60
+  if [ -n "$JAVA_HOME"  ] ; then
  61
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
  62
+      # IBM's JDK on AIX uses strange locations for the executables
  63
+      JAVACMD="$JAVA_HOME/jre/sh/java"
  64
+    else
  65
+      JAVACMD="$JAVA_HOME/bin/java"
  66
+    fi
  67
+  else
  68
+    JAVACMD=`which java`
  69
+  fi
  70
+fi
  71
+
  72
+if [ ! -x "$JAVACMD" ] ; then
  73
+  echo "Error: JAVA_HOME is not defined correctly."
  74
+  echo "  We cannot execute $JAVACMD"
  75
+  exit 1
  76
+fi
  77
+
  78
+if [ -z "$REPO" ]
  79
+then
  80
+  REPO="$BASEDIR"/repo
  81
+fi
  82
+
  83
+CLASSPATH=$CLASSPATH_PREFIX:"$BASEDIR"/etc:"$REPO"/org/jruby/jruby-complete/1.6.3/jruby-complete-1.6.3.jar
  84
+EXTRA_JVM_ARGUMENTS=""
  85
+
  86
+# For Cygwin, switch paths to Windows format before running java
  87
+if $cygwin; then
  88
+  [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  89
+  [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
  90
+  [ -n "$HOME" ] && HOME=`cygpath --path --windows "$HOME"`
  91
+  [ -n "$BASEDIR" ] && BASEDIR=`cygpath --path --windows "$BASEDIR"`
  92
+  [ -n "$REPO" ] && REPO=`cygpath --path --windows "$REPO"`
  93
+fi
  94
+
  95
+export GEM_HOME="$APPDIR"/.gems
  96
+export GEM_PATH=$GEM_HOME
  97
+export PATH="$GEM_PATH"/bin:$PATH
  98
+export BUNDLE_GEMFILE="$APPDIR"/Jemfile
  99
+
  100
+# Test if Heroku's environment variables are set.
  101
+# If they are, we're running on Heroku and should 
  102
+# set our RAILS_ENV to production
  103
+if [ -n "${DATABASE_URL}" ] && [ -n ${PORT} ] && [ "${APPDIR}" = "/app" ]; then
  104
+	echo "Detected that we are running on Heroku. Setting RAILS_ENV=production"
  105
+	export RAILS_ENV=production
  106
+fi
  107
+
  108
+exec "$JAVACMD" $JAVA_OPTS \
  109
+  $EXTRA_JVM_ARGUMENTS \
  110
+  -classpath "$CLASSPATH" \
  111
+  -Dbasedir="$BASEDIR" \
  112
+  -Xmx256m \
  113
+  -Xss2048k \
  114
+  org.jruby.Main \
  115
+  "$@"

0 notes on commit 49d94b5

Will Leinweber

You should consider just doing heroku config:add RAILS_ENV=production instead of this

Please sign in to comment.
Something went wrong with that request. Please try again.