Skip to content

Commit

Permalink
Added JRuby on Heroku support:
Browse files Browse the repository at this point in the history
  - Jemfile
  - Procfile
  - pom.xml
  - script/jruby
  - requisite changes for config/database.yml
  • Loading branch information
Khaless committed Aug 7, 2011
1 parent 3f0c2e0 commit 49d94b5
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 40 deletions.
35 changes: 0 additions & 35 deletions Gemfile

This file was deleted.

14 changes: 14 additions & 0 deletions Jemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
source 'http://rubygems.org'

gem 'rails', '3.0.0'
gem "will_paginate"
gem "acts-as-taggable-on"
gem "gchartrb"

group :development, :test do
gem 'activerecord-jdbcsqlite3-adapter'
end

group :production do
gem 'activerecord-jdbcpostgresql-adapter'
end
4 changes: 4 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
web: sh script/jruby script/rails server -p $PORT
console: sh script/jruby script/rails console
rake: sh script/jruby -S rake
jruby: sh script/jruby
11 changes: 6 additions & 5 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
# gem install sqlite3
development:
adapter: sqlite3
adapter: jdbcsqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
Expand All @@ -10,13 +10,14 @@ development:
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
adapter: jdbcsqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000

production:
adapter: sqlite3
database: db/production.sqlite3
adapter: jdbcpostgresql
url: <%= ENV["DATABASE_URL"].gsub(/postgres:\/\/(.*):(.*)@(.*)/) { "jdbc:postgresql://#{$3}?user=#{$1}&password=#{$2}" } rescue "unknown" %>
pool: 5
timeout: 5000

53 changes: 53 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>au.com.mathew</groupId>
<artifactId>jruby-heroku</artifactId>
<version>1.0</version>
<name>webapp</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-complete</artifactId>
<version>1.6.3</version>
</dependency>
<dependency>
<groupId>org.jruby.plugins</groupId>
<artifactId>jruby-rake-plugin</artifactId>
<version>1.6.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jruby.plugins</groupId>
<artifactId>jruby-rake-plugin</artifactId>
<version>1.6.3</version>
<executions>
<execution>
<id>install-bundler</id>
<phase>process-resources</phase>
<goals>
<goal>jruby</goal>
</goals>
<configuration>
<args>-S gem install bundler --no-ri --no-rdoc --install-dir .gems</args>
</configuration>
</execution>
<execution>
<id>bundle-install</id>
<phase>process-resources</phase>
<goals>
<goal>jruby</goal>
</goals>
<configuration>
<args>
-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
</args>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
115 changes: 115 additions & 0 deletions script/jruby
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/bin/sh
# ----------------------------------------------------------------------------
# Copyright 2001-2006 The Apache Software Foundation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------

# Copyright (c) 2001-2002 The Apache Software Foundation. All rights
# reserved.

APPDIR=`pwd`
BASEDIR=`dirname $0`/..
BASEDIR=`(cd "$BASEDIR"; pwd)`

# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
case "`uname`" in
CYGWIN*) cygwin=true ;;
Darwin*) darwin=true
if [ -z "$JAVA_VERSION" ] ; then
JAVA_VERSION="CurrentJDK"
else
echo "Using Java version: $JAVA_VERSION"
fi
if [ -z "$JAVA_HOME" ] ; then
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home
fi
;;
esac

if [ "$darwin" = "false" ] && [ $cygwin = "false" ]; then
APPDIR="$(dirname $(dirname $(readlink -fn "$0")))"
fi

if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi

# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi

# If a specific java binary isn't specified search for the standard 'java' binary
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD=`which java`
fi
fi

if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly."
echo " We cannot execute $JAVACMD"
exit 1
fi

if [ -z "$REPO" ]
then
REPO="$BASEDIR"/repo
fi

CLASSPATH=$CLASSPATH_PREFIX:"$BASEDIR"/etc:"$REPO"/org/jruby/jruby-complete/1.6.3/jruby-complete-1.6.3.jar
EXTRA_JVM_ARGUMENTS=""

# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$HOME" ] && HOME=`cygpath --path --windows "$HOME"`
[ -n "$BASEDIR" ] && BASEDIR=`cygpath --path --windows "$BASEDIR"`
[ -n "$REPO" ] && REPO=`cygpath --path --windows "$REPO"`
fi

export GEM_HOME="$APPDIR"/.gems
export GEM_PATH=$GEM_HOME
export PATH="$GEM_PATH"/bin:$PATH
export BUNDLE_GEMFILE="$APPDIR"/Jemfile

# Test if Heroku's environment variables are set.
# If they are, we're running on Heroku and should
# set our RAILS_ENV to production

This comment has been minimized.

Copy link
@will

will Aug 28, 2011

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

if [ -n "${DATABASE_URL}" ] && [ -n ${PORT} ] && [ "${APPDIR}" = "/app" ]; then
echo "Detected that we are running on Heroku. Setting RAILS_ENV=production"
export RAILS_ENV=production
fi

exec "$JAVACMD" $JAVA_OPTS \
$EXTRA_JVM_ARGUMENTS \
-classpath "$CLASSPATH" \
-Dbasedir="$BASEDIR" \
-Xmx256m \
-Xss2048k \
org.jruby.Main \
"$@"

0 comments on commit 49d94b5

Please sign in to comment.