deployment with ruby on rails
DESCRIPTION
Introduction to deployment with Ruby on Rails presented at JAX09 in Mainz by Jonathan Weiss.Learn about the deployment architectures and setups (web and app tier) and using Capistrano/Webistrano.TRANSCRIPT
![Page 1: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/1.jpg)
Advanced Deployment with Rails JAX 2009
Jonathan Weiss, 21 April 2009
Peritor GmbH
![Page 2: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/2.jpg)
2
Who am I?
Jonathan Weiss
• Consultant for Peritor GmbH in Berlin
• Specialized in Rails, Scaling, Deployment, and Code Review
• Webistrano - Rails deployment tool
• FreeBSD Rubygems and Ruby on Rails maintainer
http://www.peritor.com
http://blog.innerewut.de
http://twitter.com/jweiss
![Page 3: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/3.jpg)
3
Advanced Deployment
![Page 4: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/4.jpg)
4
Advanced Deployment
![Page 5: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/5.jpg)
5
Deployment
Process Architecture
Deployment
![Page 6: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/6.jpg)
6
Infrastructure Architecture
![Page 7: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/7.jpg)
7
Simple Rails Setup
One Rails instance handles all requests
Rails is (was) single-threaded: There is only one concurrent request
![Page 8: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/8.jpg)
8
Rails Setup
![Page 9: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/9.jpg)
9
Rails Setup
![Page 10: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/10.jpg)
10
Typical Rails Setup
• A load-balancer distributes the incoming requests
• Some load-balancers will deliver static requests themselves
• Several Rails instances handle all requests
• Number of concurrent requests equals number of Rails instances
![Page 11: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/11.jpg)
11
Rails Setup Options
![Page 12: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/12.jpg)
12
Deployment Questions
Mongrel?
Apache?
Ebb?
FastCGI?
mod_rails?
Thin?
Nginx?
Lighttpd?
Pound? mod_proxy_balancer?
HA-Proxy?
Phusion Passenger?
Load-balancer? Proxy?
Rails Application Server?
Swiftiply? Reverse Proxy?
Pen?
![Page 13: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/13.jpg)
13
The relevant ones
Rails Application Server
• Mongrel
• mod_rails / Phussion Passenger
• JRuby + Glassfish & Co.
Proxy/Web Server
• Apache2
• Nginx
• HA-Proxy
![Page 14: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/14.jpg)
14
Mongrel
![Page 15: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/15.jpg)
15
Mongrel
• Complete HTTP-Server that can load arbitrary Ruby-servlets
• Built-in Rails support
![Page 16: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/16.jpg)
16
Mongrel
![Page 17: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/17.jpg)
17
Mongrel
Apache 2.2 – mod_proxy_balancer Lighttpd Nginx HA-Proxy Pound
![Page 18: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/18.jpg)
18
Mongrel Cluster
Utility to manage several Mongrel instances
![Page 19: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/19.jpg)
19
Mongrel Cluster
Control Mongrels
![Page 20: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/20.jpg)
20
Mongrel
• Very robust
• Strict HTTP parser
• Easy to debug (HTTP!)
• Defacto standard deployment with Apache 2.2 and mod_proxy_balancer
• Can be a bit difficult to setup (mongrel_cluster, ports, Apache)
• Not so easy on mass/virtual hosting
![Page 21: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/21.jpg)
21
mod_rails
![Page 22: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/22.jpg)
22
mod_rails a.k.a Phusion Passenger
• Module for Apache 2.2 (and Nginx)
• Allows Apache to control Rails instances
• Apache starts and stops application instances depending on the application load
• Able to run any RACK-compatible Ruby application (Merb & Co.)
• Only manages Rails on one host - no remote instances
• Combine with HTTP-Proxy / balancing solution
![Page 23: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/23.jpg)
23
Install Phusion Passenger
Install module
Load and activate in Apache
![Page 24: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/24.jpg)
24
Control Phusion Passenger
Restart after deployment:
![Page 25: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/25.jpg)
25
Phusion Passenger
One machine
![Page 26: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/26.jpg)
26
Phusion Passenger
One machine Multiple machines
![Page 27: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/27.jpg)
27
Phusion Passenger
• Fairly new but ready for production
• Makes setup easier – on the single machine level
• Multiple servers still require load balancer
• Suitable for mass-hosting
• (upcoming) standard way of deploying Rails
![Page 28: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/28.jpg)
28
JRuby
![Page 29: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/29.jpg)
29
• Ruby Runtime on the Java Virtual Machine
• Implemented in Java and Ruby
• Compiles Ruby into Java-bytecode
• Integrates with Java code and libraries
• Java’s promises of native threads and JIT
• Allows for Ruby/Rails applications to be packaged as WAR files
• WAR files deployable on any J2EE-container: Glassfish, JBoss, Tomcat, Jetty, …
![Page 30: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/30.jpg)
30
JRuby on Rails
![Page 31: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/31.jpg)
31
JRuby on Glassfish
One machine
![Page 32: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/32.jpg)
32
JRuby on Glassfish
One machine Multiple machines
![Page 33: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/33.jpg)
33
Setup JRuby on Glassfish
1. Download JRuby and Glassfish
2. From http://blog.headius.com/2008/08/zero-to-production-in-15-minutes.html
![Page 34: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/34.jpg)
34
Warble Configuration
Define min/max Rails runtimes
![Page 35: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/35.jpg)
35
Infrastructure Process
![Page 36: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/36.jpg)
36
Deployment Process Requirements
Automatic Reproducible Accountable Notifications
![Page 37: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/37.jpg)
37
Deployment Options
![Page 38: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/38.jpg)
38
Deployment Options
![Page 39: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/39.jpg)
39
Deployment Options
![Page 40: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/40.jpg)
40
Deployment Options
![Page 41: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/41.jpg)
41
What does Capistrano do?
![Page 42: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/42.jpg)
42
Capistrano Deployment Cycle
![Page 43: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/43.jpg)
43
The Deployment Lifecycle
![Page 44: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/44.jpg)
44
Requirements
![Page 45: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/45.jpg)
45
Get Your Capistrano On
![Page 46: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/46.jpg)
46
Get Your Capistrano On
config/deploy.rb
![Page 47: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/47.jpg)
47
Capistrano
Your one-stop deployment shop
![Page 48: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/48.jpg)
48
Capistrano Tasks
To find all the tasks available in your project, use
![Page 49: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/49.jpg)
49
Custom Tasks
Override build-in
![Page 50: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/50.jpg)
50
Write your own Tasks
![Page 51: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/51.jpg)
51
Write your own Tasks
![Page 52: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/52.jpg)
52
The Rest
• Callbacks
• Transactions
• Capistrano Shell
• Custom tasks and namespaces
• Staging and multiple setups
• Gem dependencies
• Support for deploying through gateway servers
• Server setup with deprec gem
![Page 53: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/53.jpg)
53
One Click Deploy
![Page 54: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/54.jpg)
54
Webistrano
![Page 55: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/55.jpg)
55
Webistrano
• Web-UI to Capistrano
• Manages projects and their stages
• Alerting and Accounting
• Scriptable and extendable
• BSD License
http://labs.peritor.com/webistrano
![Page 56: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/56.jpg)
56
Macistrano
• Mac-GUI to Webistrano
• Fire and monitor deployments from your desktop
http://github.com/mattmatt/macistrano
![Page 57: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/57.jpg)
57
Cloud Infrastructure
![Page 58: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/58.jpg)
58
Cloud Infrastructure
Servers come and go
• You do not know your servers before deploying
• Restarting is the same as introducing a new machine
You can’t hardcode IPs
database.yml
![Page 59: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/59.jpg)
59
Solution #1
Query and manually adjust
• Servers do not change that often
• New nodes probably need manual intervention
• Use AWS ElasticIPs to ease the pain
Set servers dynamically AWS Elastic IP
![Page 60: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/60.jpg)
60
Solution #2
Use a central directory service
• A central place to manage your running instances
• Instances query the directory and react
![Page 61: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/61.jpg)
61
Solution #2
Use a central directory service
• A central place to manage your running instances
• Instances query the directory and react
![Page 62: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/62.jpg)
62
Central Directory
Different Implementations
• File on S3
• SimpleDB
• A complete service, capable of monitoring and controlling your instances
![Page 63: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/63.jpg)
63
Final words
Once understood the Rails infrastructure is quite simple
Passenger is very easy to setup and should be the default choice
Learn how to use Capistrano and Webistrano, they will make your life much easier – even in non-Rails setups
![Page 64: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/64.jpg)
64
Questions?
![Page 65: Deployment with Ruby on Rails](https://reader034.vdocuments.site/reader034/viewer/2022052618/55492fcfb4c905a54c8c1b0a/html5/thumbnails/65.jpg)
65
65
Peritor GmbH
Teutonenstraße 16 14129 Berlin
Telefon: +49 (0)30 69 20 09 84 0 Telefax: +49 (0)30 69 20 09 84 9
Internet: www.peritor.com E-Mail: [email protected]
Peritor GmbH - Alle Rechte vorbehalten