Skip to content

Instantly share code, notes, and snippets.

@threez
Created April 25, 2012 18:27
Show Gist options
  • Save threez/2491947 to your computer and use it in GitHub Desktop.
Save threez/2491947 to your computer and use it in GitHub Desktop.
A rake task to help provisioning jruby based deployments
#
# PROVISIONING OF JRUBY BASED DEPLOYMENTS
#
# Copyright (c) 2012 Vincent Landgraf
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
REV = "1.6.7"
URL = "http://jruby.org.s3.amazonaws.com/downloads/#{REV}/jruby-bin-#{REV}.tar.gz"
FILENAME = File.basename(URL)
DIRNAME = "jruby-#{REV}"
def remove_native_lib(name)
puts "removing native libs related to #{name}..."
Dir[File.join(DIRNAME, "lib", "native", "*#{name}*")].each do |path|
rm_rf path
end
end
def jruby(cmd)
chdir DIRNAME do
sh "./bin/jruby #{cmd}"
end
end
namespace :jruby do
desc "download jruby environment from remote peer (Amazon S3)"
task :fetch do
if File.exist? FILENAME
puts "File #{FILENAME} already exist and will not be downloaded again"
else
if sh "curl #{URL} > #{FILENAME}"
puts "File downloaded"
else
raise "Failed to download file!"
end
end
end
desc "unpack the fetched jruby version into directory"
task :unpack => :fetch do
if File.exist? DIRNAME
puts "Already unpacked and will not unpack again"
else
if sh "tar zxvf #{FILENAME}"
puts "unpacked successfully"
else
raise "Failed to unpack"
end
end
end
namespace :clean do
desc "remove help, sample and documentation files"
task :help do
files = %w(README LICENSE.RUBY COPYING)
folders = %w(share samples tool docs)
for path in files + folders do
full_path = File.join(DIRNAME, path)
rm_rf full_path if File.exist? full_path
end
end
for arch in %w(FreeBSD Linux OpenBSD SunOS Windows AIX Darwin) do
lambda do |architecture|
desc "remove native libraries related to #{arch}"
task "#{architecture}lib".downcase do
remove_native_lib architecture
end
end.call(arch)
end
desc "remove folders and that are realted to windows"
task :exe_win do
bin_ext = %w(bat dll exe)
bin_ext.each do |ext|
Dir[File.join(DIRNAME, "bin", "*.#{ext}")].each { |path| rm path }
end
end
end
desc "create an rc file that can be easily sourced in bash scripts"
task :create_rc do
template = File.read(__FILE__).split("__END__\n").last
File.open(File.join(DIRNAME, "jrubyrc"), "w") do |f|
f.write template
end
end
namespace :linux do
desc "optimize the package for the linux environment"
task :optimize => [:unpack, "clean:help", "clean:aixlib", "clean:darwinlib",
"clean:exe_win", "clean:freebsdlib", "clean:openbsdlib",
"clean:sunoslib", "clean:sunoslib", "clean:windowslib"]
desc "install jruby-openssl and bundler"
task :bootstrap => [:optimize, :create_rc] do
jruby "./bin/gem install jruby-openssl bundler"
end
end
end
__END__
SCRIPT_DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export JRUBY_HOME=$SCRIPT_DIR
export PATH=$JRUBY_HOME/bin:$PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment