Ruby And The Cloud
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Ruby And The Cloud

  • 5,562 views
Uploaded on

How to deploy Ruby Sinatra applications on Heroku and Google App Engine for Java

How to deploy Ruby Sinatra applications on Heroku and Google App Engine for Java

More in: Technology , Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
5,562
On Slideshare
5,532
From Embeds
30
Number of Embeds
9

Actions

Shares
Downloads
63
Comments
0
Likes
6

Embeds 30

http://www.slideshare.net 9
http://tknv.onsugar.com 5
http://www.linkedin.com 4
https://www.linkedin.com 4
http://tknv.posterous.com 3
http://phichyudebow.blogspot.com 2
http://yet-another-problem.blogspot.com 1
http://phichyudebow.blogspot.jp 1
http://yet-another-problem.blogspot.in 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • Pre-requisites – you should know Ruby. This is an intermediate level presentation, if you don’t know Ruby it will be hard for you to follow
  • Also talk a bit about myself
  • as of writing, TinyURL is still the king of the hill in the Twitter micro-market of URL shorteners. In June 2009, lexicographers of Oxford University Press sampled 1.5 million tweets and came up with the 500 most frequently used words on Twitter. With a little bit of further analysis, I extracted the numbers that are related to the various URL shorteners mentioned and came up with the approximate market share of the various URL shorteners in Twitter.
  • Do demo here.

Transcript

  • 1. How to deploy Ruby Sinatra applications to the Heroku and Google AppEngine cloud platforms Ruby and the Cloud Chang Sau Sheong Geekcamp SG 22 Aug 2009
  • 2. Beginner/Intermediate
  • 3. What I am going to show here
    • Use Sinatra to write a TinyURL clone (Snip)
    • Deploy Snip to Heroku
    • Deploy Snip to Google AppEngine
    • Disclaimer – No affiliation with Heroku or Google, all opinions are my own
  • 4. Clone TinyURL in 40 lines of Ruby code
  • 5. URL Shorteners
    • First successful one was TinyURL, started in 2002
    • Generate a short URL for any URL, going to short URL will redirect to the original
    • Usage exploded with popularity of Twitter
    • Biggest market share today – TinyURL, used to be default for Twitter, second is bit.ly
    • Twitter switched to bit.ly early May 2009
  • 6.  
  • 7.  
  • 8. Sinatra
    • Rack-based minimalist Ruby web application framework
    require ‘rubygems’ require ‘sinatra’ get ‘/hi’ do “ Hello Geekcamp!” end
    • Designed and developed by Blake Mizerany, financial support by Heroku
  • 9.  
  • 10. http://github.com/sausheong/snip
  • 11. Some notes
    • Base 36 conversion to reduce number of characters used
      • Ruby provides conversion with to_i and to_s
    • DataMapper
      • ActiveRecord, Sequel also supported
      • Use DATABASE_URL environment variable
    • Embedded view template with use_in_file_templates!
  • 12. QUESTIONS? (BEFORE CONTINUING)
  • 13. Deploying Sinatra apps to Heroku
  • 14.
    • Ruby cloud platform
    • Hosted on Amazon’s Elastic Compute Cloud (EC2)
    • Fully managed, developer only needs to deploy, all else taken care of
    • Full set of command line tools to manage deployment
    • Deploy to your own domain or *.heroku.com
  • 15. Architecture Nginx Varnish Custom made from Erlang Your code runs here Postgres Memcached
  • 16. Inside each dyno Debian MRI Rails, Sinatra etc Thin
  • 17. 6 steps to deploy
    • Install Heroku gem
    • Create a Rackup file (config.ru)
  • 18. 6 steps to deploy
    • Create empty git repository, add all files and commit the files
  • 19. 6 steps to deploy
    • Create the Heroku application using the Heroku gem
  • 20. 6 steps to deploy
    • Push code to git repository
  • 21. 6 steps to deploy
    • Go into the Heroku console to create the database
    Done!
  • 22. QUESTIONS? (BEFORE CONTINUING)
  • 23. Deploying Sinatra apps to Google AppEngine with JRuby
  • 24.
    • Lets you run your web applications on Google's infrastructure
    • Fully managed, only deploy and runs
    • Can use own domain name or *.appspot.com
    • First released April 2008, first language used Python
    • April 2009, Java support released
    Google App Engine
  • 25. App Engine for Java
    • Java 6 virtual machine (JVM), App Engine SDK supports Java 5 and later
    • Servlet classes, JSPs, static files and data files, deployment descriptor (web.xml), configuration files, in a standard WAR directory structure (not WAR file)
    • Persistence using DataStore with JDO and JPA
    • Caching using App Engine’s memcache with JCache
    • Use Mail service with JavaMail
    • Image service, Google Accounts for authentication
  • 26.
    • JRuby is the Java implementation of the Ruby programming language
    • Tightly integrated with Java, able to call Java classes, Ruby 1.8.6 compatible
    • Is what we’re going to use to deploy Snip to App Engine
  • 27. First, some code differences http://github.com/sausheong/snip-appengine No base 36 conversion Using Ola Bini’s Bumble DataStore adapter, Using DataStore key instead of id
  • 28. What we need to deploy
    • JRuby 1.3 RC1 (at least)
      • Need to split into 2 files because of App Engine’s 10MB file size limit
    • Google App Engine for Java SDK
    • Warbler – the JRuby WAR packager
      • Includes JRuby-Rack
  • 29. Steps to deploy
    • Install necessary gems (remember to use JRuby and not C Ruby)
    • Create a config directory and create the Warbler configuration
  • 30. Steps to deploy
    • Replace it with this file
    This is important – your app name We can’t use the default full JRuby library it is too large for GAE/J – max 10MB
  • 31. Steps to deploy
    • Create a lib folder and add the following library files:
      • App Engine Java library - appengine-api-1.0-sdk-1.2.0.jar
      • Split jruby-complete-1.3.0RC1.jar to:
        • jruby-core-1.3.0RC1.jar and
        • jruby-stdlib-1.3.0RC1.jar
      • (JRuby-Rack will be added by Warbler later)
    • Create an appengine-web.xml deployment configuration file
  • 32. Steps to deploy Remember this? Your app name before You might want to do this for debugging
  • 33. Steps to deploy
    • Create a Rackup configuration file config.ru
      • Preparation complete!
  • 34. Steps to deploy
    • Generate the war file and directory using Warble
  • 35. Steps to deploy
    • Output:
  • 36. Steps to deploy
    • Go into Sinatra code at tmp/war/WEB-INF/gems/gems/sinatra-0.9.1.1/lib/sinatra.rb and remove use_in_file_templates!
  • 37. Steps to deploy
    • Deploy to App Engine!
  • 38. Steps to deploy
  • 39. QUESTIONS?
  • 40. http://tinyclone.saush.com
  • 41.  
  • 42. [email_address] http://blog.saush.com http://github.com/sausheong