0
How to deploy Ruby Sinatra applications to the Heroku and Google AppEngine cloud platforms  Ruby and the Cloud Chang Sau S...
Beginner/Intermediate
What I am going to show here <ul><li>Use Sinatra to write a TinyURL clone (Snip) </li></ul><ul><li>Deploy Snip to Heroku <...
Clone TinyURL in 40 lines of Ruby code
URL Shorteners <ul><li>First successful one was TinyURL, started in 2002 </li></ul><ul><li>Generate a short URL for any UR...
 
 
Sinatra <ul><li>Rack-based minimalist Ruby web application framework </li></ul>require ‘rubygems’ require ‘sinatra’ get ‘/...
 
http://github.com/sausheong/snip
Some notes <ul><li>Base 36 conversion to reduce number of characters used </li></ul><ul><ul><li>Ruby provides conversion w...
QUESTIONS?  (BEFORE CONTINUING)
Deploying Sinatra apps to Heroku
<ul><li>Ruby cloud platform </li></ul><ul><li>Hosted on Amazon’s Elastic Compute Cloud (EC2)  </li></ul><ul><li>Fully mana...
Architecture Nginx Varnish Custom made from Erlang Your code runs here Postgres Memcached
Inside each dyno Debian MRI Rails, Sinatra etc Thin
6 steps to deploy <ul><li>Install Heroku gem </li></ul><ul><li>Create a Rackup file (config.ru) </li></ul>
6 steps to deploy <ul><li>Create empty git repository, add all files and commit the files  </li></ul>
6 steps to deploy <ul><li>Create the Heroku application using the Heroku gem </li></ul>
6 steps to deploy <ul><li>Push code to git repository </li></ul>
6 steps to deploy <ul><li>Go into the Heroku console to create the database </li></ul>Done!
QUESTIONS?  (BEFORE CONTINUING)
Deploying Sinatra apps to Google AppEngine with JRuby
<ul><li>Lets you run your web applications on Google's infrastructure </li></ul><ul><li>Fully managed, only deploy and run...
App Engine for Java <ul><li>Java 6 virtual machine (JVM), App Engine SDK supports Java 5 and later </li></ul><ul><li>Servl...
<ul><li>JRuby is the Java implementation of the Ruby programming language </li></ul><ul><li>Tightly integrated with Java, ...
First, some code differences http://github.com/sausheong/snip-appengine No base 36 conversion Using Ola Bini’s Bumble Data...
What we need to deploy <ul><li>JRuby 1.3 RC1 (at least) </li></ul><ul><ul><li>Need to split into 2 files because of App En...
Steps to deploy <ul><li>Install necessary gems (remember to use JRuby and not C Ruby) </li></ul><ul><li>Create a config di...
Steps to deploy <ul><li>Replace it with this file </li></ul>This is important – your app name We can’t use the default ful...
Steps to deploy <ul><li>Create a lib folder and add the following library files: </li></ul><ul><ul><li>App Engine Java lib...
Steps to deploy Remember this? Your app  name before You might want to do this for debugging
Steps to deploy <ul><li>Create a Rackup configuration file config.ru </li></ul><ul><ul><li>Preparation complete! </li></ul...
Steps to deploy <ul><li>Generate the war file and directory using Warble </li></ul>
Steps to deploy <ul><li>Output: </li></ul>
Steps to deploy <ul><li>Go into Sinatra code at  tmp/war/WEB-INF/gems/gems/sinatra-0.9.1.1/lib/sinatra.rb  and remove  use...
Steps to deploy <ul><li>Deploy to App Engine! </li></ul>
Steps to deploy
QUESTIONS?
http://tinyclone.saush.com
 
[email_address] http://blog.saush.com http://github.com/sausheong
Upcoming SlideShare
Loading in...5
×

Ruby And The Cloud

3,596

Published on

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

Published in: Technology, Education
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,596
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
66
Comments
0
Likes
6
Embeds 0
No embeds

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 of "Ruby And The Cloud"

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

      Recortar slides é uma maneira fácil de colecionar informações para acessar mais tarde.

    ×