forked from otobrglez/webruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchapter6.html
105 lines (89 loc) · 4.05 KB
/
chapter6.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!doctype html>
<html>
<head>
<title>Programming for the Web with Ruby</title>
<meta charset="utf-8">
<meta name="author" content="Satish Talim" >
<meta name="keywords" content="programming, Ruby, Rack, Sinatra" >
<meta name="description" content="A Ruby programming tutorial on topics that hopefully will help those that have some knowledge of Ruby programming to get started with web programming." >
<link rel="stylesheet" href="stylesheets/intruby.css">
</head>
<body>
<div>
<p>
<strong>
<a href="chapter5.html"><Chapter 5 | </a>
<a href="toc.html">TOC | </a>
<a href="chapter7.html">Chapter 7></a>
</strong>
</p>
<h1 class="title">Day 7</h1>
<h2>Deploying Pure Rack Apps to Heroku</h2>
<h3>Deploy your app to Heroku</h3>
<p>In order for Heroku to know what to do with your Rack app, create a <code>config.ru</code> (ru stands for Rack up) in say the <code>rackheroku</code> folder. The contents are:</p>
<pre>require './my_app'
run MyApp.new
</pre>
<p>Also, copy the <code>my_app.rb</code> file to the <code>rackheroku</code> folder. It's contents are:</p>
<pre># my_app.rb
class MyApp
def call env
[200, {"Content-Type" => "text/html"}, ["Hello Rack Participants from across the globe"]]
end
end
</pre>
<p>Next, we will install the required gems (if any) via bundler. In the already open Git Bash shell for folder <code>rackheroku</code> type:</p>
<pre>$ bundle init
Writing new Gemfile to c:/rackheroku/Gemfile
</pre>
<p>Edit the created <code>Gemfile</code> with your preferred text editor to let it look like this:</p>
<pre>source "http://rubygems.org"
gem 'rack'
</pre>
<p>Now we need to tell Bundler to check if we're missing the gems our application depends on, if so, tell it to install them. In your open Bash shell type:</p>
<pre>$ bundle check
The Gemfile's dependencies are satisfied
</pre>
<p>Finally in the open Bash shell, type:</p>
<pre>$ bundle install
</pre>
<p>This will ensure all gems specified on Gemfile, together with their dependencies, are available for your application. Running "bundle install" will also generate a "Gemfile.lock" file. The Gemfile.lock ensures that your deployed versions of gems on Heroku match the version installed locally on your development machine.</p>
<p>Next we set up our local app to use Git. Type:</p>
<pre>$ git init
$ git add .
$ git commit -m "Rack app first commit"
</pre>
<p>Let's create our Rack app on Heroku. Type:</p>
<pre>$ heroku create
Creating quiet-winter-3741... done, stack is bamboo-mri-1.9.2
http://quiet-winter-3741.heroku.com/ | [email protected]:quiet-winter-3741.git
Git remote heroku added
</pre>
<p>The app has been created and two URLs are provided. One is for the web face of your new app i.e. http://quiet-winter-3741.heroku.com/ If you visit that URL now, you'll see a standard welcome page, until you push your application up. The other one is for the Git repository that you will push your code to. Normally you would need to add this as a git remote; the "heroku create" command has done this for you automatically. Do note that the output from the create command <em>will be different for each one of you</em>.</p>
<p>Now let us deploy our code to Heroku. Type:</p>
<pre>$ git push heroku master
</pre>
<p>At this stage we can rename our app to rackheroku. Type:</p>
<pre>$ heroku rename rackheroku
http://rackheroku.heroku.com/ | [email protected]:rackheroku.git
Git remote heroku updated
</pre>
<p>Our app is now deployed to Heroku. Open a new browser window and type <a href="http://rackheroku.heroku.com/">http://rackheroku.heroku.com/</a></p>
<p>In the browser window, you should see:</p>
<pre>Hello Rack Participants
</pre>
<h3>Exercise on deployment</h3>
<p>As an exercise, deploy all your Rack apps to Heroku.</p>
<p>
<strong>
<a href="chapter5.html"><Chapter 5 | </a>
<a href="toc.html">TOC | </a>
<a href="chapter7.html">Chapter 7></a>
</strong>
</p>
<div id="footer">
<p>© 2006-2012 <strong>RubyLearning.org - Programming for the Web with Ruby</strong> Page Updated: 20th Feb. 2012</p>
</div>
</div>
</body>
</html>