deploy-slide



deploy-slide

0 0


deploy-slide


On Github shamithc / deploy-slide

Deployment In Rails

Asset Pipeline

Rails 3.1 Fast by default Concatenate assets Minification / compression Precompilation Fingerprinting

Asset Organization

app/assets lib/assets vendor/assets

Managing Assets

Sprockets Manifest Include file Preprocessing

Manifest

Directives

require include require_tree require_self require_directory

Gemfile

group :assets do
  gem 'sass-rails'
  gem 'coffee-rails'
  gem 'uglifier'
  gem 'yui-compressor'
  gem 'compass-rails'
end

production.rb

    config.serve_static_assets = true

    # Compress JavaScripts and CSS
    config.assets.compress = true

    # Setting compressor currently doesn't work (thx to @carhartl for the tip) https://github.com/rails/sass-rails/issues/104
    config.assets.css_compressor = :yui
    config.assets.js_compressor = :uglifier

    # Don't fallback to assets pipeline if a precompiled asset is missed
    config.assets.compile = false

    # Generate digests for assets URLs
    config.assets.digest = true

    # User cloudfront as deployment asset host
    # SET THIS AT THE END OF THIS GUIDE, 
    config.action_controller.asset_host = ENV['ASSET_HOST']

Dev vs Prod

Rails In deployment

Web And App Server

Web Server is designed to serve HTTP Content.App Server can also serve HTTP Content but is not limited to just HTTP. Web Server is mostly designed to serve static content Most of the application servers have Web Server - Application level services such as Connection Pooling, Object Pooling, Transaction Support, Messaging services etc. Most of the production environments have web server acting as reverse proxy to app server.

Phusion Passenger

Fast and robust web server and application server Supports applications written in multiple programming languages Phusion Passenger is a robust module for Apache and Nginx servers

Deploying Rails App with Phusion Passenger and Nginx

    # Download source code
    cd /tmp
    wget http://nginx.org/download/nginx-1.0.15.tar.gz
    tar -xvzf nginx-1.0.15.tar.gz

    # Install  passenger
    gem install passenger 

    #  configure your Nginx to work with Passenger.
    passenger-install-nginx-module

    # nginx config file 
    sudo nano /opt/nginx/conf/nginx.conf

    # simple configuration
    server { 
        listen 80; 
        server_name example.com; 
        passenger_enabled on; 
        root my-rails-app/public; 
    }

Nginx.conf

user  user1
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    passenger_root /home/user/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.18;
    passenger_ruby /home/user/.rvm/wrappers/ruby-1.9.3-p194/ruby;

    include       mime.types;
    default_type  application/octet-stream;

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen 80;
        server_name  localhost;
        root /home/user/BBC-v3.1/BBC/trunk/BBC/public;
        passenger_enabled on;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        #location / {
        #    root   html;
        #    index  index.html index.htm;
        #}

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

          location /sign_up {
              proxy_pass  http://localhost:8080/;    
         }

       location /homes/bbc_signup {
          proxy_pass  http://localhost:8080/homes/bbc_signup; 
       }

       location /success_signup {
          proxy_pass  http://localhost:8080/homes/sucess_signup;
       }

       location ~ ^/(assets-suscription)/  {
          root /home/user/BBC-v3.1/BBC/trunk/BBC-SubscriptionApp/public ;
          expires max;
          break;
       }   
    }
}

Capistrano

Advanced tools to deploy Perform pre and post-deploy functions Deploy to many machines at once.