Upload
chang-sau-sheong
View
217
Download
0
Embed Size (px)
Citation preview
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
1/40
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
2/40
Todays lesson
Components used for deployment
Deploying Ruby/Rack-based web applicationson servers with full control
Deploying Ruby/Rack-based web applicationson Ruby cloud platforms (PaaS)
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
3/40
Mongrel
FastCGI
Rubyservers
Server
adapters
HTTPservers
Unicorn
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
4/40
Web app is a web server -> standalone(Webrick/Mongrel/Thin/Unicorn)
Web app as a spawned process -> CGI/FastCGI
Web app in app server -> proxied cluster
(Web/proxy server + Thin/Mongrel/Unicorn)
Web app in a web server -> Passenger(mod_rails)
Full server control
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
5/40
Standalone
Webrick/Thin/
Mongrel
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
6/40
CGI
remote/localApache/Nginx/Lighttpd
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
7/40
FastCGI
persistent
remote/localApache/Nginx/Lighttpd
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
8/40
Proxied clusterThin/
Mongrel
Thin/Mongrel
Thin/
Mongrel
remote/local
Apache/
Nginx/Lighttpd
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
9/40
Passenger (mod_rails)
local
Apache/Nginx
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
10/40Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
11/40
Install Passenger
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
12/40Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
13/40Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
14/40
Configure Passengerwith Apache
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
15/40
Add the following into your
httpd.conf (or what your Apacheconfiguration file is)
LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/
passenger-2.2.15/ext/apache2/mod_passenger.so
PassengerRoot /Library/Ruby/Gems/1.8/gems/passenger-2.2.15PassengerRuby /System/Library/Frameworks/Ruby.framework/
Versions/1.8/usr/bin/ruby
the path to your filesare probably different
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
16/40
ServerName localhost
DocumentRoot"/Users/sausheong/projects/chirpy/public"
order allow,deny Allow from all
AllowOverride all
Options -MultiViews
ErrorLog"/Users/sausheong/projects/chirpy/error_log"
CustomLog"/Users/sausheong/projects/chirpy/access_log" common
Put this is your Apache virtual hostconfiguration
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
17/40
Add config.ru to your
applicationThis is the Rackup file, used to configure and
start up Rack apps (it is actually a Ruby script)
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
18/40
require 'chirpy'
run Sinatra::Application
config.ru
Put this in yourapplication root
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
19/40
Restart your Apache andaccess the site
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
20/40
Ruby Cloud Platforms
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
21/40
Platform-as-a-Service
Heroku
Engine YardMicrosoft Azure (IronRuby)
Google App Engine (JRuby)
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
22/40Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
23/40
What is it?
Cloud-based Ruby platform
Runs on Amazon AWS EC2
Shared, multi-tenant platform
Fully managed and curated
Provides basic infrastructure, for others, useplug-ins
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
24/40Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
25/40
Using Heroku
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
26/40
Install Heroku gem
$ sudo gem install heroku
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
27/40
Initialize an empty Gitrepository
$ git init
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
28/40
Add all the files in thecurrent directory
$ git add .
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
29/40
Commit all the files inthe directory to Heroku
$ git commit -m initial import
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
30/40
Create the Herokuapplication
$ heroku create chirpy
If this is the first time youre using the Heroku command, you will be
prompted for a user name and password, subsequently will be saved in~/.heroku/credentials. This will upload your public key to all you to
push and pull code from Heroku
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
31/40
Push your code toHeroku
$ git push heroku master
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
32/40
Your application is now
deployed to Heroku$ heroku create chirpy
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
33/40
http://chirpy.heroku.com
Wednesday, September 22, 2010
http://chirpy.heroku.com/http://chirpy.heroku.com/8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
34/40
Fully deployed?
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
35/40
Not yet
gems
needed
create
databasetables
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
36/40
Include the gems
Create a file named .gems in the applicationroot
hamlsinatra --version >= 1.0
rack-flash --source http://...
json
rest-client
activesupport
dm-core
dm-postgres-adapter
dm-migrations
differentnames than inthe require
not include in
the app, usedto access PSQLin Heroku used for migrations
(creating tables)
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
37/40
Create the tables
Heroku provides an irb-like console thatloads the environment
$ heroku console>> require dm-migrations
>> DataMapper.auto_migrate!
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
38/40
Other stuffCheck the logs with
Add configuration variables (so that you dontneed to put it in the code)
Using it in the code:
$ heroku logs
$ heroku config:add FB_CLIENT_ID=...
$ heroku config:add FB_CLIENT_ID=...
redirect "https://graph.facebook.com/oauth/
authorize?client_id="+ ENV['FB_CLIENT_ID'] + ...
Wednesday, September 22, 2010
https://graph.facebook.com/oauth/authorize?client_id=https://graph.facebook.com/oauth/authorize?client_id=https://graph.facebook.com/oauth/authorize?client_id=https://graph.facebook.com/oauth/authorize?client_id=https://graph.facebook.com/oauth/authorize?client_id=8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
39/40
Add-ons
Amazon RDS
WebSolr
SendGrid
MoonShado
Zerigo
MongoHQ
New Relic
Memcache
relational DB cloud provider
search engine
DNS API
SMTP API
MongoDB cloud provider
SMS API
Performance monitoring
Data caching
And many more ...
Wednesday, September 22, 2010
8/8/2019 Ruby Course - Lesson 9 - Deploying Ruby Web Applications
40/40
Questions