+ All Categories
Home > Technology > Deployment with Ruby on Rails

Deployment with Ruby on Rails

Date post: 06-May-2015
Category:
Upload: jonathan-weiss
View: 8,077 times
Download: 1 times
Share this document with a friend
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.
Popular Tags:
65
Advanced Deployment with Rails JAX 2009 Jonathan Weiss, 21 April 2009 Peritor GmbH
Transcript
Page 1: Deployment with Ruby on Rails

Advanced Deployment with Rails JAX 2009

Jonathan Weiss, 21 April 2009

Peritor GmbH

Page 2: Deployment with Ruby on Rails

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

3

Advanced Deployment

Page 4: Deployment with Ruby on Rails

4

Advanced Deployment

Page 5: Deployment with Ruby on Rails

5

Deployment

Process Architecture

Deployment

Page 6: Deployment with Ruby on Rails

6

Infrastructure Architecture

Page 7: Deployment with Ruby on Rails

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

8

Rails Setup

Page 9: Deployment with Ruby on Rails

9

Rails Setup

Page 10: Deployment with Ruby on Rails

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

11

Rails Setup Options

Page 12: Deployment with Ruby on Rails

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

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

14

Mongrel

Page 15: Deployment with Ruby on Rails

15

Mongrel

•  Complete HTTP-Server that can load arbitrary Ruby-servlets

•  Built-in Rails support

Page 16: Deployment with Ruby on Rails

16

Mongrel

Page 17: Deployment with Ruby on Rails

17

Mongrel

Apache 2.2 – mod_proxy_balancer Lighttpd Nginx HA-Proxy Pound

Page 18: Deployment with Ruby on Rails

18

Mongrel Cluster

Utility to manage several Mongrel instances

Page 19: Deployment with Ruby on Rails

19

Mongrel Cluster

Control Mongrels

Page 20: Deployment with Ruby on Rails

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

21

mod_rails

Page 22: Deployment with Ruby on Rails

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

23

Install Phusion Passenger

Install module

Load and activate in Apache

Page 24: Deployment with Ruby on Rails

24

Control Phusion Passenger

Restart after deployment:

Page 25: Deployment with Ruby on Rails

25

Phusion Passenger

One machine

Page 26: Deployment with Ruby on Rails

26

Phusion Passenger

One machine Multiple machines

Page 27: Deployment with Ruby on Rails

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

28

JRuby

Page 29: Deployment with Ruby on Rails

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

30

JRuby on Rails

Page 31: Deployment with Ruby on Rails

31

JRuby on Glassfish

One machine

Page 32: Deployment with Ruby on Rails

32

JRuby on Glassfish

One machine Multiple machines

Page 33: Deployment with Ruby on Rails

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

34

Warble Configuration

Define min/max Rails runtimes

Page 35: Deployment with Ruby on Rails

35

Infrastructure Process

Page 36: Deployment with Ruby on Rails

36

Deployment Process Requirements

Automatic Reproducible Accountable Notifications

Page 37: Deployment with Ruby on Rails

37

Deployment Options

Page 38: Deployment with Ruby on Rails

38

Deployment Options

Page 39: Deployment with Ruby on Rails

39

Deployment Options

Page 40: Deployment with Ruby on Rails

40

Deployment Options

Page 41: Deployment with Ruby on Rails

41

What does Capistrano do?

Page 42: Deployment with Ruby on Rails

42

Capistrano Deployment Cycle

Page 43: Deployment with Ruby on Rails

43

The Deployment Lifecycle

Page 44: Deployment with Ruby on Rails

44

Requirements

Page 45: Deployment with Ruby on Rails

45

Get Your Capistrano On

Page 46: Deployment with Ruby on Rails

46

Get Your Capistrano On

config/deploy.rb

Page 47: Deployment with Ruby on Rails

47

Capistrano

Your one-stop deployment shop

Page 48: Deployment with Ruby on Rails

48

Capistrano Tasks

To find all the tasks available in your project, use

Page 49: Deployment with Ruby on Rails

49

Custom Tasks

Override build-in

Page 50: Deployment with Ruby on Rails

50

Write your own Tasks

Page 51: Deployment with Ruby on Rails

51

Write your own Tasks

Page 52: Deployment with Ruby on Rails

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

53

One Click Deploy

Page 54: Deployment with Ruby on Rails

54

Webistrano

Page 55: Deployment with Ruby on Rails

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

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

57

Cloud Infrastructure

Page 58: Deployment with Ruby on Rails

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

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

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

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

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

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

64

Questions?

Page 65: Deployment with Ruby on Rails

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


Recommended