Deployment with Ruby on Rails

Post on 06-May-2015

8,077 views 1 download

Tags:

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

Advanced Deployment with Rails JAX 2009

Jonathan Weiss, 21 April 2009

Peritor GmbH

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

3

Advanced Deployment

4

Advanced Deployment

5

Deployment

Process Architecture

Deployment

6

Infrastructure Architecture

7

Simple Rails Setup

One Rails instance handles all requests

Rails is (was) single-threaded: There is only one concurrent request

8

Rails Setup

9

Rails Setup

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

11

Rails Setup Options

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?

13

The relevant ones

Rails Application Server

•  Mongrel

•  mod_rails / Phussion Passenger

•  JRuby + Glassfish & Co.

Proxy/Web Server

•  Apache2

•  Nginx

•  HA-Proxy

14

Mongrel

15

Mongrel

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

•  Built-in Rails support

16

Mongrel

17

Mongrel

Apache 2.2 – mod_proxy_balancer Lighttpd Nginx HA-Proxy Pound

18

Mongrel Cluster

Utility to manage several Mongrel instances

19

Mongrel Cluster

Control Mongrels

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

21

mod_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

23

Install Phusion Passenger

Install module

Load and activate in Apache

24

Control Phusion Passenger

Restart after deployment:

25

Phusion Passenger

One machine

26

Phusion Passenger

One machine Multiple machines

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

28

JRuby

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, …

30

JRuby on Rails

31

JRuby on Glassfish

One machine

32

JRuby on Glassfish

One machine Multiple machines

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

34

Warble Configuration

Define min/max Rails runtimes

35

Infrastructure Process

36

Deployment Process Requirements

Automatic Reproducible Accountable Notifications

37

Deployment Options

38

Deployment Options

39

Deployment Options

40

Deployment Options

41

What does Capistrano do?

42

Capistrano Deployment Cycle

43

The Deployment Lifecycle

44

Requirements

45

Get Your Capistrano On

46

Get Your Capistrano On

config/deploy.rb

47

Capistrano

Your one-stop deployment shop

48

Capistrano Tasks

To find all the tasks available in your project, use

49

Custom Tasks

Override build-in

50

Write your own Tasks

51

Write your own Tasks

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

53

One Click Deploy

54

Webistrano

55

Webistrano

•  Web-UI to Capistrano

•  Manages projects and their stages

•  Alerting and Accounting

•  Scriptable and extendable

•  BSD License

http://labs.peritor.com/webistrano

56

Macistrano

•  Mac-GUI to Webistrano

•  Fire and monitor deployments from your desktop

http://github.com/mattmatt/macistrano

57

Cloud Infrastructure

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

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

60

Solution #2

Use a central directory service

•  A central place to manage your running instances

•  Instances query the directory and react

61

Solution #2

Use a central directory service

•  A central place to manage your running instances

•  Instances query the directory and react

62

Central Directory

Different Implementations

•  File on S3

•  SimpleDB

•  A complete service, capable of monitoring and controlling your instances

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

64

Questions?

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: kontakt@peritor.com

Peritor GmbH - Alle Rechte vorbehalten