Skip to content

Instantly share code, notes, and snippets.

@auser
Created February 19, 2010 22:32
Show Gist options
  • Select an option

  • Save auser/309297 to your computer and use it in GitHub Desktop.

Select an option

Save auser/309297 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'sinatra'
get '/' do
"hello world"
end
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>getbeehive</application>
<version>1</version>
<static-files />
<resource-files />
<sessions-enabled>false</sessions-enabled>
<system-properties>
<property name="jruby.management.enabled" value="false" />
<property name="os.arch" value="" />
<property name="jruby.compile.mode" value="JIT"/> <!-- JIT|FORCE|OFF -->
<property name="jruby.compile.fastest" value="true"/>
<property name="jruby.compile.frameless" value="true"/>
<property name="jruby.compile.positionless" value="true"/>
<property name="jruby.compile.threadless" value="false"/>
<property name="jruby.compile.fastops" value="false"/>
<property name="jruby.compile.fastcase" value="false"/>
<property name="jruby.compile.chainsize" value="500"/>
<property name="jruby.compile.lazyHandles" value="false"/>
<property name="jruby.compile.peephole" value="true"/>
</system-properties>
</appengine-web-app>
require "rubygems"
require "poolparty"
require "open-uri"
pool "larubyconf" do
cloud "demo" do
using :ec2
instances 1..1 # no autoscaling
image_id "ami-f9608c90" #alestic
user "ubuntu"
availability_zones ['us-east-1c']
security_group do
%w(22 80).each {|port| authorize :from_port => port, :to_port => port}
end
elastic_ip "75.101.164.90"
user_data open("#{File.dirname(__FILE__)}/apache.setup").read
end
end
export JAVA_HOME="/usr"
export EC2_HOME=~/.ec2
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
export PATH=$EC2_HOME/bin:$PATH
export EC2_CONFIG_DIR=$EC2_HOME/keys
. ~/.ec2/environment
export AWS_ACCESS_KEY="your access key"
export AWS_SECRET_ACCESS_KEY="your secret key"
export EC2_ACCESS_KEY=$AWS_ACCESS_KEY
export EC2_SECRET_KEY=$AWS_SECRET_ACCESS_KEY
export EC2_PRIVATE_KEY=$(ls ~/.ec2/pk-*.pem)
export EC2_CERT=$(ls ~/.ec2/cert-*.pem)
export EC2_CONFIG_DIR=~/.ec2
unset EC2_URL
unset S3_URL
cd ~/.ec2
ec2-add-keypair demo > demo
# remove the first line
chmod 600 demo
ec2-run-instances ami-6743ae0e -k demo
ec2-authorize -p 22 default
ec2-describe-instances | grep demo
ssh ubuntu@[IP] -i ~/.ec2/demo
# log into the machine
# check out the meta-data server
curl http://169.54.169.254/latest
# do more fun stuff
exit
ec2-describe-instances | grep demo
ec2-terminate-instances i-[ID]
ec2-add-group larubyconf
ec2-authorize -p22 larubyconf
ec2-authorize -p 80 larubyconf
ec2-run-instances ami-6743ae0e -k demo -g larubyconf
# log in
ssh [email protected] -i ~/.ec2/larubyconf-demo
# now to start the instance with a script:
ec2-run-instances ami-6743ae0e -k demo --user-data-file /path/to/file
#!/bin/bash
set -e -x
apt-get update
apt-get install -y apache2 apache2-prefork-dev build-essential git-core libyaml-ruby libzlib-ruby rdoc ruby ruby1.8-dev rubygems sqlite3 libopenssl-ruby
gem install daemons fastthread json mime-types open4 passenger rack rake sqlite3-ruby --no-rdoc --no-ri
GEM_PATH=$(gem env | grep EXECUTABLE\ DIRECTORY | awk '{print $4}' | xargs echo)
export PATH=$PATH:$GEM_PATH
yes '' | passenger-install-apache2-module
PASSENGER_VERSION=$(gem list passenger | grep "passenger " | cut -b12- | awk '{sub(/\)/, "");print}')
cd /etc/apache2/
a2enmod deflate
echo "<VirtualHost *>
ServerName projectname.com
DocumentRoot /webapps/projectname/static_page
</VirtualHost>" > sites-available/placeholder
echo "<VirtualHost *>
ServerName rackexample.com
DocumentRoot /webapps/rackexample/public
CustomLog /var/log/apache2/rackexample.com-access.log combined
ErrorLog /var/log/apache2/rackexample.com-error.log
LogLevel warn
</VirtualHost>
" > sites-available/rackexample
echo "LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-$PASSENGER_VERSION/ext/apache2/mod_passenger.so" > /etc/apache2/mods-available/passenger.load
echo "PassengerRoot /var/lib/gems/1.8/gems/passenger-$PASSENGER_VERSION
PassengerRuby /usr/bin/ruby1.8" > /etc/apache2/mods-available/passenger.conf
a2dissite default
a2enmod passenger
a2ensite rackexample
apache2ctl restart
# Make the app
mkdir -p /webapps/rackexample/{public,tmp}
echo "app = proc do |env|
[200, {\"Content-Type\" => \"text/html\"}, [\"Hello </b>World</b>\"]]
end
run app
" > /webapps/rackexample/config.ru
apt-get install libshadow-ruby1.8 curl
gem install chef ohai --no-ri --no-rdoc --source http://gems.opscode.com --source http://gems.rubyforge.org
# create a volume (size is in GB)
ec2-create-volume --availability-zone 'us-east-1b' --size '5'
# associate with an instance
ec2-attach-volume vol-[ID] --device '/dev/sdk' --instance i-[ID]
ssh ubuntu@[ip] -i [keypair]
sudo su
mkdir /data
mkfs -t ext3 /dev/sdk
# add to fstab
/dev/sdk /data ext3 defaults 0 0
# mount
sudo mount -a
# create a root block device
ec2-describe-volumes | grep /dev/sda
# create the snapsshot of your block device
ec2-create-snapshot vol-[ID] -d 'larubyconf volume demo'
# get the root snapshot
ec2-create-snapshot vol-[ID] -d "Base root drive"
ec2-register --snapshot snap-[root-snap] --kernel aki-5f15f636 --ramdisk ari-d5709dbc --description="New snapshot" --name="Demo instance with data" --architecture "i386" --root-device-name /dev/sda1 -b /dev/sdb=ephemeral0 -b /dev/sdk=snap-[BLOCK ID]::true
# kill all running instances
ec2-describe-instances | grep running | awk '{print $2}' | xargs ec2-terminate-instances
# Clone jruby
git clone git://kenai.com/jruby~main
cd jruby~main
ant && ant jar-complete
export JRUBY_BIN=$(pwd)/bin
$JRUBY_BIN/jruby -v
$JRUBY_BIN/jruby -S gem install rake rack sinatra warbler
# Clone jruby-rack
git clone git://github.com/nicksieger/jruby-rack.git
cd jruby-rack
$JRUBY_BIN/jruby -S rake SKIP_SPECS=true
mkdir sinatra-app
cd sinatra-app
touch config.ru app.rb appengine-web.xml
mkdir views public config lib
Add config.ru
require 'rubygems'
require 'sinatra'
root_dir = File.dirname(__FILE__)
set :environment, :production
set :root, root_dir
set :app_file, File.join(root_dir, 'app.rb')
disable :run
require 'app'
run Sinatra::Application
Add appengine-web.xml
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>getbeehive</application>
<version>1</version>
<static-files />
<resource-files />
<sessions-enabled>false</sessions-enabled>
<system-properties>
<property name="jruby.management.enabled" value="false" />
<property name="os.arch" value="" />
<property name="jruby.compile.mode" value="JIT"/> <!-- JIT|FORCE|OFF -->
<property name="jruby.compile.fastest" value="true"/>
<property name="jruby.compile.frameless" value="true"/>
<property name="jruby.compile.positionless" value="true"/>
<property name="jruby.compile.threadless" value="false"/>
<property name="jruby.compile.fastops" value="false"/>
<property name="jruby.compile.fastcase" value="false"/>
<property name="jruby.compile.chainsize" value="500"/>
<property name="jruby.compile.lazyHandles" value="false"/>
<property name="jruby.compile.peephole" value="true"/>
</system-properties>
</appengine-web-app>
Add config/warble.rb
# Disable automatic framework detection by uncommenting/setting to false
# Warbler.framework_detection = false
# Warbler web application assembly configuration file
Warbler::Config.new do |config|
# Temporary directory where the application is staged
# config.staging_dir = "tmp/war"
# Application directories to be included in the webapp.
config.dirs = %w(lib public views)
# Additional files/directories to include, above those in config.dirs
# config.includes = FileList["db"]
config.includes = FileList["appengine-web.xml", "app.rb", "config.ru"]
# Additional files/directories to exclude
# config.excludes = FileList["lib/tasks/*"]
# Additional Java .jar files to include. Note that if .jar files are placed
# in lib (and not otherwise excluded) then they need not be mentioned here.
# JRuby and JRuby-Rack are pre-loaded in this list. Be sure to include your
# own versions if you directly set the value
# config.java_libs += FileList["lib/java/*.jar"]
# Loose Java classes and miscellaneous files to be placed in WEB-INF/classes.
# config.java_classes = FileList["target/classes/**.*"]
# One or more pathmaps defining how the java classes should be copied into
# WEB-INF/classes. The example pathmap below accompanies the java_classes
# configuration above. See http://rake.rubyforge.org/classes/String.html#M000017
# for details of how to specify a pathmap.
# config.pathmaps.java_classes << "%{target/classes/,}p"
# Gems to be included. You need to tell Warbler which gems your application needs
# so that they can be packaged in the war file.
# The Rails gems are included by default unless the vendor/rails directory is present.
# config.gems += ["activerecord-jdbcmysql-adapter", "jruby-openssl"]
# config.gems << "tzinfo"
config.gems = ['sinatra']
# Uncomment this if you don't want to package rails gem.
# config.gems -= ["rails"]
# The most recent versions of gems are used.
# You can specify versions of gems by using a hash assignment:
# config.gems["rails"] = "2.0.2"
# You can also use regexps or Gem::Dependency objects for flexibility or
# fine-grained control.
# config.gems << /^merb-/
# config.gems << Gem::Dependency.new("merb-core", "= 0.9.3")
# Include gem dependencies not mentioned specifically
config.gem_dependencies = true
# Files to be included in the root of the webapp. Note that files in public
# will have the leading 'public/' part of the path stripped during staging.
# config.public_html = FileList["public/**/*", "doc/**/*"]
# Pathmaps for controlling how public HTML files are copied into the .war
# config.pathmaps.public_html = ["%{public/,}p"]
# Name of the war file (without the .war) -- defaults to the basename
# of RAILS_ROOT
config.war_name = "test"
# Name of the MANIFEST.MF template for the war file. Defaults to the
# MANIFEST.MF normally generated by `jar cf`.
# config.manifest_file = "config/MANIFEST.MF"
# Value of RAILS_ENV for the webapp -- default as shown below
# config.webxml.rails.env = ENV['RAILS_ENV'] || 'production'
# Application booter to use, one of :rack, :rails, or :merb. (Default :rails)
# config.webxml.booter = :rack
config.webxml.booter = :rack
# When using the :rack booter, "Rackup" script to use.
# The script is evaluated in a Rack::Builder to load the application.
# Examples:
# config.webxml.rackup = %{require './lib/demo'; run Rack::Adapter::Camping.new(Demo)}
# config.webxml.rackup = require 'cgi' && CGI::escapeHTML(File.read("config.ru"))
# Control the pool of Rails runtimes. Leaving unspecified means
# the pool will grow as needed to service requests. It is recommended
# that you fix these values when running a production server!
# config.webxml.jruby.min.runtimes = 2
# config.webxml.jruby.max.runtimes = 4
config.webxml.jruby.min.runtimes = 1
config.webxml.jruby.max.runtimes = 1
config.webxml.jruby.init.serial = true
# JNDI data source name
# config.webxml.jndi = 'jdbc/rails'
config.java_libs = []
end
#!/bin/sh
rm -rf jruby-core.jar
rm -rf ruby-stdlib.jar
rm -rf tmp_unpack
mkdir tmp_unpack
cd tmp_unpack
jar xf ../jruby-complete.jar
cd ..
mkdir jruby-core
mv tmp_unpack/org jruby-core/
mv tmp_unpack/com jruby-core/
mv tmp_unpack/jline jruby-core/
mv tmp_unpack/jay jruby-core/
mv tmp_unpack/jruby jruby-core/
cd jruby-core
jar cf ../jruby-core.jar .
cd ../tmp_unpack
jar cf ../ruby-stdlib.jar .
cd ..
rm -rf jruby-core
rm -rf tmp_unpack
rm -rf jruby-complete.jar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment