-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathslides_deploying_rails.html
More file actions
333 lines (310 loc) · 14.6 KB
/
slides_deploying_rails.html
File metadata and controls
333 lines (310 loc) · 14.6 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Slides for
Deploying Rails — Ruby on Rails Guides
</title>
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" data-turbo-track="reload">
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print">
<link rel="stylesheet" type="text/css" href="stylesheets/highlight.css" data-turbo-track="reload">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="stylesheets/reset.css">
<link rel="stylesheet" href="stylesheets/reveal.css">
<link rel="stylesheet" href="stylesheets/myslide.css" id="theme">
<link rel="stylesheet" href="stylesheets/code.css">
<script src="javascripts/clipboard.js" data-turbo-track="reload"></script>
<script src="javascripts/slides.js" data-turbo-track="reload"></script>
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1>Deploying Rails</h1><p>Your "Minimal Viable Product" is finished, now you
want to publish it on the web.</p><p>After working through this guide you should be able to</p>
<ul>
<li>deploy a rails app to dokku (or heroku) using git</li>
<li>deploy a rails app to any unix server using capistrano</li>
</ul>
<p><small>Slides - use arrow keys to navigate, esc to return to page view, f for fullscreen</small></p>
</section>
<section><a class='slide_break' href='deploying_rails.html#slide-0'>▻</a>
<h2 id="deploying-with-git"><a class="anchorlink" href="#deploying-with-git"><span>1</span> Deploying with git</a></h2><p>heroku is one "Platform as a Service" provider that offers
to host your rails app. Heroku uses git to push the code to
the production server.</p><p>(See also
<a href="http://railsbridge.projects.multimediatechnology.at/installfest/create_a_heroku_account">Railsbridge Installfest: Create A Heroku Account</a>
and
<a href="https://railsbridge.projects.multimediatechnology.at/installfest/deploy_a_rails_app">Railsbridge Installfest: Deploy A Rails App</a>
)</p>
<ul>
<li>create an account on <a href="https://heroku.com">https://heroku.com</a></li>
<li>add your public key to your heroku account</li>
<li>install the heroku toolbelt on your local development machine</li>
</ul>
<p>in your rails app, which is already using git:</p>
<ul>
<li>heroku create</li>
<li>make some changes in the Gemfile (rubyracer, pg instead of sqlite)</li>
<li>don't forget to commit all changes!</li>
<li>git push heroku master</li>
<li>heroku run rake db:migrate</li>
<li>heroku open</li>
<li>heroku logs</li>
</ul>
<p>That's it. You should now have an app with a very strange URL, like
<a href="http://mighty-shore-1497.herokuapp.com/">http://mighty-shore-1497.herokuapp.com/</a></p></section>
<section><a class='slide_break' href='deploying_rails.html#slide-1'>▻</a>
<h2 id="public-key-authentication-in-ssh"><a class="anchorlink" href="#public-key-authentication-in-ssh"><span>2</span> Public Key Authentication in SSH</a></h2><p>(See also <a href="http://railsbridge.projects.multimediatechnology.at/installfest/create_an_ssh_key">Railsbridge Installfest</a>)</p><p><img src="images/public_key_crypto.svg" alt="public key login"></p>
<ul>
<li><a href="https://dougvitale.wordpress.com/2012/02/20/ssh-the-secure-shell/">learn about ssh</a></li>
<li>if you have a public + private key pair
<ul>
<li><code>id_rsa</code></li>
<li><code>id_rsa.pub</code></li>
</ul></li>
<li>and your private key is on your local computer
<ul>
<li>stored in <code>~/.ssh/id_rsa</code></li>
</ul></li>
<li>and your public key is on the server
<ul>
<li>stored in <code>~/.ssh/authorized_keys2</code></li>
</ul></li>
<li>then ssh will let you log in without giving a password</li>
</ul>
<p><img src="images/ssh_login_with_public_key.svg" alt="public key login"></p></section>
<section><a class='slide_break' href='deploying_rails.html#slide-2'>▻</a>
<h3 id="deploying-with-a-deploy-user"><a class="anchorlink" href="#deploying-with-a-deploy-user"><span>2.1</span> deploying with a deploy-user</a></h3>
<ul>
<li>alice and bob both want to deploy project x</li>
<li><code>deploy_x</code> is set up as an account on the server</li>
<li>alice adds her public key to <code>~deploy_x/.ssh/authorized_keys2</code></li>
<li>bob adds his public key to <code>~deploy_x/.ssh/authorized_keys2</code></li>
<li>both can deploy (from different machines) using the same capistrano setup</li>
</ul>
</section>
<section><a class='slide_break' href='deploying_rails.html#slide-3'>▻</a>
<h3 id="authorized-keys2"><a class="anchorlink" href="#authorized-keys2"><span>2.2</span> authorized_keys2</a></h3><div class="interstitial code">
<pre><code class="highlight plaintext">ssh-rsa AAAAB3NzaC...2EAAAABI== alice@fh-salzburg.ac.at
ssh-rsa AAAAB8NzaC...DVj3R4Ww== bob@fh-salzburg.ac.at
</code></pre>
<button class="clipboard-button" data-clipboard-text="ssh-rsa AAAAB3NzaC...2EAAAABI== alice@fh-salzburg.ac.at
ssh-rsa AAAAB8NzaC...DVj3R4Ww== bob@fh-salzburg.ac.at
">Copy</button>
</div>
</section>
<section><a class='slide_break' href='deploying_rails.html#slide-4'>▻</a>
<h2 id="how-to-run-rails"><a class="anchorlink" href="#how-to-run-rails"><span>3</span> How to run Rails</a></h2>
<ul>
<li>WEBrick (built in web server)</li>
<li>apache/nginx + mod_passenger</li>
<li>apache/nginx + mod_passenger + capistrano</li>
</ul>
</section>
<section><a class='slide_break' href='deploying_rails.html#slide-5'>▻</a>
<h3 id="webrick"><a class="anchorlink" href="#webrick"><span>3.1</span> WEBrick</a></h3>
<ul>
<li>rails s</li>
</ul>
</section>
<section><a class='slide_break' href='deploying_rails.html#slide-6'>▻</a>
<h3 id="mod-passenger"><a class="anchorlink" href="#mod-passenger"><span>3.2</span> mod_passenger</a></h3>
<ul>
<li>install <a href="https://www.phusionpassenger.com/">mod_passenger</a></li>
<li>upload your code</li>
<li>create files not in git (e.g. database.yml)</li>
<li>apache config:
<ul>
<li>set <code>DocumentRoot</code> to <code>public/</code></li>
<li>set <code>RailsEnv production</code></li>
</ul></li>
<li>restart apache</li>
<li>if you change the code:
<ul>
<li>touch <code>tmp/restart.txt</code> to force reload of code</li>
</ul></li>
</ul>
</section>
<section><a class='slide_break' href='deploying_rails.html#slide-7'>▻</a>
<h2 id="deploying-with-capistrano"><a class="anchorlink" href="#deploying-with-capistrano"><span>4</span> Deploying with Capistrano</a></h2><p><img src="images/capistrano-deploy.svg" alt="Deploying with Javascript"></p></section>
<section><a class='slide_break' href='deploying_rails.html#slide-8'>▻</a>
<h3 id="warning"><a class="anchorlink" href="#warning"><span>4.1</span> WARNING</a></h3>
<ul>
<li>capistrano is a command line tool</li>
<li>you need to read the output!</li>
<li>you need to read every line of the output!</li>
<li>you seriously need to read every line of the output!</li>
</ul>
</section>
<section><a class='slide_break' href='deploying_rails.html#slide-9'>▻</a>
<h3 id="capistrano-assumptions"><a class="anchorlink" href="#capistrano-assumptions"><span>4.2</span> capistrano assumptions</a></h3>
<ul>
<li>You are using SSH to access your remote machines</li>
<li>your remote servers have a shell called sh</li>
<li>authentication through password or public key</li>
<li>Capistrano reads its instructions from a <code>capfile</code></li>
</ul>
</section>
<section><a class='slide_break' href='deploying_rails.html#slide-10'>▻</a>
<h3 id="how-to-install"><a class="anchorlink" href="#how-to-install"><span>4.3</span> how to install</a></h3><div class="interstitial code">
<pre><code class="highlight sh"><span class="nv">$ </span><span class="nb">sudo gem install </span>capistrano
Fetching: capistrano-2.13.5.gem <span class="o">(</span>100%<span class="o">)</span>
Successfully installed capistrano-2.13.5
1 <span class="nb">gem </span>installed
<span class="nv">$ $ </span>cap <span class="nb">install
mkdir</span> <span class="nt">-p</span> config/deploy
create config/deploy.rb
create config/deploy/staging.rb
create config/deploy/production.rb
<span class="nb">mkdir</span> <span class="nt">-p</span> lib/capistrano/tasks
create Capfile
Capified
</code></pre>
<button class="clipboard-button" data-clipboard-text="$ sudo gem install capistrano
Fetching: capistrano-2.13.5.gem (100%)
Successfully installed capistrano-2.13.5
1 gem installed
$ $ cap install
mkdir -p config/deploy
create config/deploy.rb
create config/deploy/staging.rb
create config/deploy/production.rb
mkdir -p lib/capistrano/tasks
create Capfile
Capified
">Copy</button>
</div>
</section>
<section><a class='slide_break' href='deploying_rails.html#slide-11'>▻</a>
<h3 id="configuration-in-config-deploy-rb"><a class="anchorlink" href="#configuration-in-config-deploy-rb"><span>4.4</span> configuration in <code>config/deploy.rb</code></a></h3><p>local information, see our wiki</p></section>
<section><a class='slide_break' href='deploying_rails.html#slide-12'>▻</a>
<h3 id="example-task-in-capfile"><a class="anchorlink" href="#example-task-in-capfile"><span>4.5</span> example task in Capfile</a></h3><div class="interstitial code">
<pre><code class="highlight ruby"><span class="n">task</span> <span class="ss">:display_free_disk_space</span> <span class="k">do</span>
<span class="n">run</span> <span class="s2">"df -h"</span>
<span class="k">end</span>
</code></pre>
<button class="clipboard-button" data-clipboard-text="task :display_free_disk_space do
run "df -h"
end
">Copy</button>
</div>
</section>
<section><a class='slide_break' href='deploying_rails.html#slide-13'>▻</a>
<h3 id="prepare-capistranoe"><a class="anchorlink" href="#prepare-capistranoe"><span>4.6</span> prepare capistranoe</a></h3><div class="interstitial code">
<pre><code class="highlight sh"><span class="nv">$ </span>cap production <span class="nb">git</span>:check
<span class="nv">$ </span>scp config/database.yml deployuser@server:/var/www/.../shared/config
<span class="nv">$ </span>scp config/secrets.yml deployuser@server:/var/www/.../shared/config
<span class="nv">$ </span>cap production deploy
</code></pre>
<button class="clipboard-button" data-clipboard-text="$ cap production git:check
$ scp config/database.yml deployuser@server:/var/www/.../shared/config
$ scp config/secrets.yml deployuser@server:/var/www/.../shared/config
$ cap production deploy
">Copy</button>
</div>
</section>
<section><a class='slide_break' href='deploying_rails.html#slide-14'>▻</a>
<h3 id="run-a-capistrano-task"><a class="anchorlink" href="#run-a-capistrano-task"><span>4.7</span> run a capistrano task</a></h3><div class="interstitial code">
<pre><code class="highlight sh"><span class="nv">$ </span>cap production deploy
<span class="nv">$ </span>cap display_free_disk_space
<span class="k">*</span> 2012-11-29 05:34:45 executing <span class="s1">'display_free_disk_space'</span>
<span class="k">*</span> executing <span class="s2">"df -h"</span>
servers: <span class="o">[</span><span class="s2">"multimediaart.at"</span><span class="o">]</span>
Password: <span class="k">****</span>
<span class="o">[</span>multimediaart.at] executing <span class="nb">command</span>
<span class="k">**</span> <span class="o">[</span>out :: multimediaart.at] Size Used Avail Use% Mounted on
<span class="k">**</span> <span class="o">[</span>out :: multimediaart.at] 98G 70G 24G 75% /var/www
<span class="nb">command </span>finished <span class="k">in </span>165ms
</code></pre>
<button class="clipboard-button" data-clipboard-text="$ cap production deploy
$ cap display_free_disk_space
* 2012-11-29 05:34:45 executing 'display_free_disk_space'
* executing "df -h"
servers: ["multimediaart.at"]
Password: ****
[multimediaart.at] executing command
** [out :: multimediaart.at] Size Used Avail Use% Mounted on
** [out :: multimediaart.at] 98G 70G 24G 75% /var/www
command finished in 165ms
">Copy</button>
</div>
</section>
<section><a class='slide_break' href='deploying_rails.html#slide-15'>▻</a>
<h3 id="capistrano-folders"><a class="anchorlink" href="#capistrano-folders"><span>4.8</span> capistrano folders</a></h3><p>read the logfile, try to find out how capistrano lays out
the folders</p>
<ul>
<li>current --> links to a release</li>
<li>release
<ul>
<li>20121201113038</li>
<li>20121201150544</li>
</ul></li>
<li>shared
<ul>
<li>assets</li>
<li>bundle</li>
<li>log</li>
<li>pids</li>
<li>system</li>
</ul></li>
</ul>
</section>
<section><a class='slide_break' href='deploying_rails.html#slide-16'>▻</a>
<h3 id="my-first-deploy"><a class="anchorlink" href="#my-first-deploy"><span>4.9</span> my first deploy</a></h3><div class="interstitial code">
<pre><code class="highlight sh"><span class="nv">$ </span>cap deploy:setup
<span class="nv">$ </span>cap deploy:check
<span class="nv">$ </span>cap deploy:cold
<span class="nv">$ </span>cap deploy:upload <span class="nv">FILES</span><span class="o">=</span><span class="s1">'config/database.yml'</span>
</code></pre>
<button class="clipboard-button" data-clipboard-text="$ cap deploy:setup
$ cap deploy:check
$ cap deploy:cold
$ cap deploy:upload FILES='config/database.yml'
">Copy</button>
</div>
</div></section>
</div>
</div>
<!-- End slides. -->
<!-- Required JS files. -->
<script src="javascripts/reveal.js"></script>
<script src="javascripts/search.js"></script>
<script src="javascripts/markdown.js"></script>
<script>
// Also available as an ES module, see:
// https://revealjs.com/initialization/
Reveal.initialize({
controls: false,
progress: true,
center: false,
hash: true,
// The "normal" size of the presentation, aspect ratio will
// be preserved when the presentation is scaled to fit different
// resolutions. Can be specified using percentage units.
width: 1000,
height: 600,
disableLayout: false,
// Factor of the display size that should remain empty around
// the content
margin: 0.05,
// Bounds for smallest/largest possible scale to apply to content
minScale: 0.2,
maxScale: 10.0,
keyboard: {
27: () => {
// do something custom when ESC is pressed
var new_url = window.location.pathname.replace('slides_', '') + window.location.hash.replace('/','slide-');
window.location = new_url;
},
191: 'toggleHelp',
13: 'next', // go to the next slide when the ENTER key is pressed
},
// Learn about plugins: https://revealjs.com/plugins/
plugins: [ RevealSearch, RevealMarkdown ]
});
</script>
</body>
</html>