recap 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,373 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>deploy.rb</title>
6
+ <link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
7
+ </head>
8
+ <body>
9
+ <div id='container'>
10
+ <div id="background"></div>
11
+ <div id="jump_to">
12
+ Jump To &hellip;
13
+ <div id="jump_wrapper">
14
+ <div id="jump_page">
15
+ <a class="source" href="../../index.html">index.rb</a>
16
+ <a class="source" href="bundler.html">bundler.rb</a>
17
+ <a class="source" href="capistrano_extensions.html">capistrano_extensions.rb</a>
18
+ <a class="source" href="cli.html">cli.rb</a>
19
+ <a class="source" href="compatibility.html">compatibility.rb</a>
20
+ <a class="source" href="deploy.html">deploy.rb</a>
21
+ <a class="source" href="env.html">env.rb</a>
22
+ <a class="source" href="foreman.html">foreman.rb</a>
23
+ <a class="source" href="preflight.html">preflight.rb</a>
24
+ <a class="source" href="rails.html">rails.rb</a>
25
+ <a class="source" href="version.html">version.rb</a>
26
+ </div>
27
+ </div>
28
+ </div>
29
+ <table cellspacing=0 cellpadding=0>
30
+ <thead>
31
+ <tr>
32
+ <th class=docs><h1>deploy.rb</h1></th>
33
+ <th class=code></th>
34
+ </tr>
35
+ </thead>
36
+ <tbody>
37
+ <tr id='section-1'>
38
+ <td class=docs>
39
+ <div class="pilwrap">
40
+ <a class="pilcrow" href="#section-1">&#182;</a>
41
+ </div>
42
+
43
+ </td>
44
+ <td class=code>
45
+ <div class='highlight'><pre><span class="nb">require</span> <span class="s1">&#39;recap/capistrano_extensions&#39;</span>
46
+ <span class="nb">require</span> <span class="s1">&#39;recap/bundler&#39;</span>
47
+ <span class="nb">require</span> <span class="s1">&#39;recap/preflight&#39;</span>
48
+
49
+ <span class="no">Capistrano</span><span class="o">::</span><span class="no">Configuration</span><span class="o">.</span><span class="n">instance</span><span class="p">(</span><span class="ss">:must_exist</span><span class="p">)</span><span class="o">.</span><span class="n">load</span> <span class="k">do</span>
50
+ <span class="kp">extend</span> <span class="no">Recap</span><span class="o">::</span><span class="no">CapistranoExtensions</span></pre></div>
51
+ </td>
52
+ </tr>
53
+ <tr id='section-2'>
54
+ <td class=docs>
55
+ <div class="pilwrap">
56
+ <a class="pilcrow" href="#section-2">&#182;</a>
57
+ </div>
58
+ <p>To use this recipe, both the application&rsquo;s name and its git repository are required.</p>
59
+ </td>
60
+ <td class=code>
61
+ <div class='highlight'><pre> <span class="n">set</span><span class="p">(</span><span class="ss">:application</span><span class="p">)</span> <span class="p">{</span> <span class="nb">abort</span> <span class="s2">&quot;You must set the name of your application in your Capfile, e.g.: set :application, &#39;tomafro.net&#39;&quot;</span> <span class="p">}</span>
62
+ <span class="n">set</span><span class="p">(</span><span class="ss">:repository</span><span class="p">)</span> <span class="p">{</span> <span class="nb">abort</span> <span class="s2">&quot;You must set the git respository location in your Capfile, e.g.: set :respository, &#39;git@github.com/tomafro/tomafro.net&#39;&quot;</span><span class="p">}</span></pre></div>
63
+ </td>
64
+ </tr>
65
+ <tr id='section-3'>
66
+ <td class=docs>
67
+ <div class="pilwrap">
68
+ <a class="pilcrow" href="#section-3">&#182;</a>
69
+ </div>
70
+ <p>The recipe assumes that the application code will be run as a dedicated user. Any any user who
71
+ can deploy the application should be added as a member of the application&rsquo;s group. By default,
72
+ both the application user and group take the same name as the application.</p>
73
+ </td>
74
+ <td class=code>
75
+ <div class='highlight'><pre> <span class="n">set</span><span class="p">(</span><span class="ss">:application_user</span><span class="p">)</span> <span class="p">{</span> <span class="n">application</span> <span class="p">}</span>
76
+ <span class="n">set</span><span class="p">(</span><span class="ss">:application_group</span><span class="p">)</span> <span class="p">{</span> <span class="n">application_user</span> <span class="p">}</span></pre></div>
77
+ </td>
78
+ </tr>
79
+ <tr id='section-4'>
80
+ <td class=docs>
81
+ <div class="pilwrap">
82
+ <a class="pilcrow" href="#section-4">&#182;</a>
83
+ </div>
84
+ <p>Deployments can be made from any branch. <code>master</code> is used by default.</p>
85
+ </td>
86
+ <td class=code>
87
+ <div class='highlight'><pre> <span class="n">set</span><span class="p">(</span><span class="ss">:branch</span><span class="p">,</span> <span class="s1">&#39;master&#39;</span><span class="p">)</span></pre></div>
88
+ </td>
89
+ </tr>
90
+ <tr id='section-5'>
91
+ <td class=docs>
92
+ <div class="pilwrap">
93
+ <a class="pilcrow" href="#section-5">&#182;</a>
94
+ </div>
95
+ <p>Unlike a standard capistrano deployment, all releases are stored directly in the <code>deploy_to</code>
96
+ directory. The default is <code>/var/apps/#{application}</code>.</p>
97
+ </td>
98
+ <td class=code>
99
+ <div class='highlight'><pre> <span class="n">set</span><span class="p">(</span><span class="ss">:deploy_to</span><span class="p">)</span> <span class="p">{</span> <span class="s2">&quot;/var/apps/</span><span class="si">#{</span><span class="n">application</span><span class="si">}</span><span class="s2">&quot;</span> <span class="p">}</span></pre></div>
100
+ </td>
101
+ </tr>
102
+ <tr id='section-6'>
103
+ <td class=docs>
104
+ <div class="pilwrap">
105
+ <a class="pilcrow" href="#section-6">&#182;</a>
106
+ </div>
107
+ <p>Each release is marked by a unique tag, generated with the current timestamp. While this can be
108
+ changed, it&rsquo;s not recommended, as the sort order of the tag names is important; later tags must
109
+ be listed after earlier tags.</p>
110
+ </td>
111
+ <td class=code>
112
+ <div class='highlight'><pre> <span class="n">set</span><span class="p">(</span><span class="ss">:release_tag</span><span class="p">)</span> <span class="p">{</span> <span class="s2">&quot;</span><span class="si">#{</span><span class="no">Time</span><span class="o">.</span><span class="n">now</span><span class="o">.</span><span class="n">utc</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s2">&quot;%Y%m%d%H%M%S&quot;</span><span class="p">)</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">}</span></pre></div>
113
+ </td>
114
+ </tr>
115
+ <tr id='section-7'>
116
+ <td class=docs>
117
+ <div class="pilwrap">
118
+ <a class="pilcrow" href="#section-7">&#182;</a>
119
+ </div>
120
+ <p>On tagging a release, a message is also recorded alongside the tag. This message can contain
121
+ anything useful &ndash; its contents are not important for the recipe.</p>
122
+ </td>
123
+ <td class=code>
124
+ <div class='highlight'><pre> <span class="n">set</span><span class="p">(</span><span class="ss">:release_message</span><span class="p">,</span> <span class="s2">&quot;Deployed at </span><span class="si">#{</span><span class="no">Time</span><span class="o">.</span><span class="n">now</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span></pre></div>
125
+ </td>
126
+ </tr>
127
+ <tr id='section-8'>
128
+ <td class=docs>
129
+ <div class="pilwrap">
130
+ <a class="pilcrow" href="#section-8">&#182;</a>
131
+ </div>
132
+ <p>Some tasks need to know the <code>latest_tag</code> &ndash; the most recent successful deployment. If no
133
+ deployments have been made, this will be <code>nil</code>.</p>
134
+ </td>
135
+ <td class=code>
136
+ <div class='highlight'><pre> <span class="n">set</span><span class="p">(</span><span class="ss">:latest_tag</span><span class="p">)</span> <span class="p">{</span> <span class="n">latest_tag_from_repository</span> <span class="p">}</span></pre></div>
137
+ </td>
138
+ </tr>
139
+ <tr id='section-9'>
140
+ <td class=docs>
141
+ <div class="pilwrap">
142
+ <a class="pilcrow" href="#section-9">&#182;</a>
143
+ </div>
144
+ <p>To authenticate with github or other git servers, it is easier (and cleaner) to forward the
145
+ deploying user&rsquo;s ssh key than manage keys on deployment servers.</p>
146
+ </td>
147
+ <td class=code>
148
+ <div class='highlight'><pre> <span class="n">ssh_options</span><span class="o">[</span><span class="ss">:forward_agent</span><span class="o">]</span> <span class="o">=</span> <span class="kp">true</span></pre></div>
149
+ </td>
150
+ </tr>
151
+ <tr id='section-10'>
152
+ <td class=docs>
153
+ <div class="pilwrap">
154
+ <a class="pilcrow" href="#section-10">&#182;</a>
155
+ </div>
156
+ <p>If key forwarding isn&rsquo;t possible, git may show a password prompt which stalls capistrano unless
157
+ <code>:pty</code> is set to <code>true</code>.</p>
158
+ </td>
159
+ <td class=code>
160
+ <div class='highlight'><pre> <span class="n">default_run_options</span><span class="o">[</span><span class="ss">:pty</span><span class="o">]</span> <span class="o">=</span> <span class="kp">true</span>
161
+
162
+ <span class="n">namespace</span> <span class="ss">:deploy</span> <span class="k">do</span></pre></div>
163
+ </td>
164
+ </tr>
165
+ <tr id='section-11'>
166
+ <td class=docs>
167
+ <div class="pilwrap">
168
+ <a class="pilcrow" href="#section-11">&#182;</a>
169
+ </div>
170
+ <p>The <code>deploy:setup</code> task prepares all the servers for the deployment.</p>
171
+ </td>
172
+ <td class=code>
173
+ <div class='highlight'><pre> <span class="n">desc</span> <span class="s2">&quot;Prepare servers for deployment&quot;</span>
174
+ <span class="n">task</span> <span class="ss">:setup</span><span class="p">,</span> <span class="ss">:except</span> <span class="o">=&gt;</span> <span class="p">{</span><span class="ss">:no_release</span> <span class="o">=&gt;</span> <span class="kp">true</span><span class="p">}</span> <span class="k">do</span>
175
+ <span class="n">transaction</span> <span class="k">do</span>
176
+ <span class="n">clone_code</span>
177
+ <span class="k">end</span>
178
+ <span class="k">end</span></pre></div>
179
+ </td>
180
+ </tr>
181
+ <tr id='section-12'>
182
+ <td class=docs>
183
+ <div class="pilwrap">
184
+ <a class="pilcrow" href="#section-12">&#182;</a>
185
+ </div>
186
+ <p>Clone the repository into the deployment directory.</p>
187
+ </td>
188
+ <td class=code>
189
+ <div class='highlight'><pre> <span class="n">task</span> <span class="ss">:clone_code</span><span class="p">,</span> <span class="ss">:except</span> <span class="o">=&gt;</span> <span class="p">{</span><span class="ss">:no_release</span> <span class="o">=&gt;</span> <span class="kp">true</span><span class="p">}</span> <span class="k">do</span></pre></div>
190
+ </td>
191
+ </tr>
192
+ <tr id='section-13'>
193
+ <td class=docs>
194
+ <div class="pilwrap">
195
+ <a class="pilcrow" href="#section-13">&#182;</a>
196
+ </div>
197
+ <p>This is a slightly complicated process, as git doesn&rsquo;t allow us to clone into an existing
198
+ directory. To get around this, using <code>sudo</code> we create the base deployment folder (if it
199
+ doesn&rsquo;t already exist).</p>
200
+ </td>
201
+ <td class=code>
202
+ <div class='highlight'><pre> <span class="n">sudo</span> <span class="s2">&quot;mkdir -p </span><span class="si">#{</span><span class="no">File</span><span class="o">.</span><span class="n">expand_path</span><span class="p">(</span><span class="n">deploy_to</span> <span class="o">+</span> <span class="s2">&quot;/..&quot;</span><span class="p">)</span><span class="si">}</span><span class="s2">&quot;</span></pre></div>
203
+ </td>
204
+ </tr>
205
+ <tr id='section-14'>
206
+ <td class=docs>
207
+ <div class="pilwrap">
208
+ <a class="pilcrow" href="#section-14">&#182;</a>
209
+ </div>
210
+ <p>Next, clone our code into a temporary location. This is necessary as our user might not have
211
+ permission to write in the base deployment folder.</p>
212
+ </td>
213
+ <td class=code>
214
+ <div class='highlight'><pre> <span class="n">run</span> <span class="s2">&quot;git clone </span><span class="si">#{</span><span class="n">repository</span><span class="si">}</span><span class="s2"> $HOME/</span><span class="si">#{</span><span class="n">application</span><span class="si">}</span><span class="s2">.tmp&quot;</span></pre></div>
215
+ </td>
216
+ </tr>
217
+ <tr id='section-15'>
218
+ <td class=docs>
219
+ <div class="pilwrap">
220
+ <a class="pilcrow" href="#section-15">&#182;</a>
221
+ </div>
222
+ <p>Again using <code>sudo</code>, move the temporary clone to its final destination.</p>
223
+ </td>
224
+ <td class=code>
225
+ <div class='highlight'><pre> <span class="n">sudo</span> <span class="s2">&quot;mv $HOME/</span><span class="si">#{</span><span class="n">application</span><span class="si">}</span><span class="s2">.tmp </span><span class="si">#{</span><span class="n">deploy_to</span><span class="si">}</span><span class="s2">&quot;</span></pre></div>
226
+ </td>
227
+ </tr>
228
+ <tr id='section-16'>
229
+ <td class=docs>
230
+ <div class="pilwrap">
231
+ <a class="pilcrow" href="#section-16">&#182;</a>
232
+ </div>
233
+ <p>Finally ensure that members of the <code>application_group</code> can read and write all files.</p>
234
+ </td>
235
+ <td class=code>
236
+ <div class='highlight'><pre> <span class="n">top</span><span class="o">.</span><span class="n">deploy</span><span class="o">.</span><span class="n">change_ownership</span>
237
+ <span class="k">end</span></pre></div>
238
+ </td>
239
+ </tr>
240
+ <tr id='section-17'>
241
+ <td class=docs>
242
+ <div class="pilwrap">
243
+ <a class="pilcrow" href="#section-17">&#182;</a>
244
+ </div>
245
+ <p>Any files that have been created or updated by our user need to have thier permissions changed to
246
+ ensure they can be read and written by and member of the <code>application_group</code> (deploying users and
247
+ the application itself).</p>
248
+ </td>
249
+ <td class=code>
250
+ <div class='highlight'><pre> <span class="n">task</span> <span class="ss">:change_ownership</span><span class="p">,</span> <span class="ss">:except</span> <span class="o">=&gt;</span> <span class="p">{</span><span class="ss">:no_release</span> <span class="o">=&gt;</span> <span class="kp">true</span><span class="p">}</span> <span class="k">do</span>
251
+ <span class="n">run</span> <span class="s2">&quot;find </span><span class="si">#{</span><span class="n">deploy_to</span><span class="si">}</span><span class="s2"> -user `whoami` ! -group </span><span class="si">#{</span><span class="n">application_group</span><span class="si">}</span><span class="s2"> -exec chown :</span><span class="si">#{</span><span class="n">application_group</span><span class="si">}</span><span class="s2"> {} </span><span class="se">\\</span><span class="s2">;&quot;</span>
252
+ <span class="n">run</span> <span class="s2">&quot;find </span><span class="si">#{</span><span class="n">deploy_to</span><span class="si">}</span><span class="s2"> -user `whoami` -exec chmod g+rw {} </span><span class="se">\\</span><span class="s2">;&quot;</span>
253
+ <span class="k">end</span></pre></div>
254
+ </td>
255
+ </tr>
256
+ <tr id='section-18'>
257
+ <td class=docs>
258
+ <div class="pilwrap">
259
+ <a class="pilcrow" href="#section-18">&#182;</a>
260
+ </div>
261
+ <p>The main deployment task (called with <code>cap deploy</code>) deploys the latest application code to all
262
+ servers, tags the release and restarts the application.</p>
263
+ </td>
264
+ <td class=code>
265
+ <div class='highlight'><pre> <span class="n">desc</span> <span class="s2">&quot;Deploy the latest application code&quot;</span>
266
+ <span class="n">task</span> <span class="ss">:default</span> <span class="k">do</span>
267
+ <span class="n">transaction</span> <span class="k">do</span>
268
+ <span class="n">update_code</span>
269
+ <span class="n">tag</span>
270
+ <span class="k">end</span>
271
+ <span class="n">restart</span>
272
+ <span class="k">end</span></pre></div>
273
+ </td>
274
+ </tr>
275
+ <tr id='section-19'>
276
+ <td class=docs>
277
+ <div class="pilwrap">
278
+ <a class="pilcrow" href="#section-19">&#182;</a>
279
+ </div>
280
+ <p>Fetch the latest changes, then update <code>HEAD</code> to the deployment branch.</p>
281
+ </td>
282
+ <td class=code>
283
+ <div class='highlight'><pre> <span class="n">task</span> <span class="ss">:update_code</span><span class="p">,</span> <span class="ss">:except</span> <span class="o">=&gt;</span> <span class="p">{</span><span class="ss">:no_release</span> <span class="o">=&gt;</span> <span class="kp">true</span><span class="p">}</span> <span class="k">do</span>
284
+ <span class="n">on_rollback</span> <span class="p">{</span> <span class="n">git</span> <span class="s2">&quot;reset --hard </span><span class="si">#{</span><span class="n">latest_tag</span><span class="si">}</span><span class="s2">&quot;</span> <span class="k">if</span> <span class="n">latest_tag</span> <span class="p">}</span>
285
+ <span class="n">git</span> <span class="s2">&quot;fetch&quot;</span>
286
+ <span class="n">git</span> <span class="s2">&quot;reset --hard origin/</span><span class="si">#{</span><span class="n">branch</span><span class="si">}</span><span class="s2">&quot;</span></pre></div>
287
+ </td>
288
+ </tr>
289
+ <tr id='section-20'>
290
+ <td class=docs>
291
+ <div class="pilwrap">
292
+ <a class="pilcrow" href="#section-20">&#182;</a>
293
+ </div>
294
+ <p>Finally ensure that the members of the <code>application_group</code> can read and write all files.</p>
295
+ </td>
296
+ <td class=code>
297
+ <div class='highlight'><pre> <span class="n">top</span><span class="o">.</span><span class="n">deploy</span><span class="o">.</span><span class="n">change_ownership</span>
298
+ <span class="k">end</span></pre></div>
299
+ </td>
300
+ </tr>
301
+ <tr id='section-21'>
302
+ <td class=docs>
303
+ <div class="pilwrap">
304
+ <a class="pilcrow" href="#section-21">&#182;</a>
305
+ </div>
306
+ <p>Tag <code>HEAD</code> with the release tag and message</p>
307
+ </td>
308
+ <td class=code>
309
+ <div class='highlight'><pre> <span class="n">task</span> <span class="ss">:tag</span><span class="p">,</span> <span class="ss">:except</span> <span class="o">=&gt;</span> <span class="p">{</span><span class="ss">:no_release</span> <span class="o">=&gt;</span> <span class="kp">true</span><span class="p">}</span> <span class="k">do</span>
310
+ <span class="n">on_rollback</span> <span class="p">{</span> <span class="n">git</span> <span class="s2">&quot;tag -d </span><span class="si">#{</span><span class="n">release_tag</span><span class="si">}</span><span class="s2">&quot;</span> <span class="p">}</span>
311
+ <span class="n">git</span> <span class="s2">&quot;tag </span><span class="si">#{</span><span class="n">release_tag</span><span class="si">}</span><span class="s2"> -m &#39;</span><span class="si">#{</span><span class="n">release_message</span><span class="si">}</span><span class="s2">&#39;&quot;</span>
312
+ <span class="n">top</span><span class="o">.</span><span class="n">deploy</span><span class="o">.</span><span class="n">change_ownership</span>
313
+ <span class="k">end</span></pre></div>
314
+ </td>
315
+ </tr>
316
+ <tr id='section-22'>
317
+ <td class=docs>
318
+ <div class="pilwrap">
319
+ <a class="pilcrow" href="#section-22">&#182;</a>
320
+ </div>
321
+ <p>After a successful deployment, the app is restarted. In the most basic deployments this does
322
+ nothing, but other recipes may override it, or attach tasks it&rsquo;s before or after hooks.</p>
323
+ </td>
324
+ <td class=code>
325
+ <div class='highlight'><pre> <span class="n">desc</span> <span class="s2">&quot;Restart the application following a deploy&quot;</span>
326
+ <span class="n">task</span> <span class="ss">:restart</span> <span class="k">do</span>
327
+ <span class="k">end</span></pre></div>
328
+ </td>
329
+ </tr>
330
+ <tr id='section-23'>
331
+ <td class=docs>
332
+ <div class="pilwrap">
333
+ <a class="pilcrow" href="#section-23">&#182;</a>
334
+ </div>
335
+ <p>To rollback a release, the latest tag is deleted, and <code>HEAD</code> reset to the previous release
336
+ (if one exists). Finally the application is restarted again.</p>
337
+ </td>
338
+ <td class=code>
339
+ <div class='highlight'><pre> <span class="n">desc</span> <span class="s2">&quot;Rollback to the previous release&quot;</span>
340
+ <span class="n">namespace</span> <span class="ss">:rollback</span> <span class="k">do</span>
341
+ <span class="n">task</span> <span class="ss">:default</span> <span class="k">do</span>
342
+ <span class="k">if</span> <span class="n">latest_tag</span>
343
+ <span class="n">git</span> <span class="s2">&quot;tag -d </span><span class="si">#{</span><span class="n">latest_tag</span><span class="si">}</span><span class="s2">&quot;</span>
344
+ <span class="k">if</span> <span class="n">previous_tag</span> <span class="o">=</span> <span class="n">latest_tag_from_repository</span>
345
+ <span class="n">git</span> <span class="s2">&quot;reset --hard </span><span class="si">#{</span><span class="n">previous_tag</span><span class="si">}</span><span class="s2">&quot;</span>
346
+ <span class="k">end</span>
347
+ <span class="k">end</span>
348
+ <span class="n">restart</span>
349
+ <span class="k">end</span>
350
+ <span class="k">end</span></pre></div>
351
+ </td>
352
+ </tr>
353
+ <tr id='section-24'>
354
+ <td class=docs>
355
+ <div class="pilwrap">
356
+ <a class="pilcrow" href="#section-24">&#182;</a>
357
+ </div>
358
+ <p>In case of emergency or when manually testing deployment, it can be useful to remove all
359
+ previously deployed files before starting again.</p>
360
+
361
+ </td>
362
+ <td class=code>
363
+ <div class='highlight'><pre> <span class="n">desc</span> <span class="s2">&quot;Remove all deployed files&quot;</span>
364
+ <span class="n">task</span> <span class="ss">:destroy</span> <span class="k">do</span>
365
+ <span class="n">sudo</span> <span class="s2">&quot;rm -rf </span><span class="si">#{</span><span class="n">deploy_to</span><span class="si">}</span><span class="s2">&quot;</span>
366
+ <span class="k">end</span>
367
+ <span class="k">end</span>
368
+ <span class="k">end</span></pre></div>
369
+ </td>
370
+ </tr>
371
+ </table>
372
+ </div>
373
+ </body>
@@ -0,0 +1,103 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>env.rb</title>
6
+ <link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
7
+ </head>
8
+ <body>
9
+ <div id='container'>
10
+ <div id="background"></div>
11
+ <div id="jump_to">
12
+ Jump To &hellip;
13
+ <div id="jump_wrapper">
14
+ <div id="jump_page">
15
+ <a class="source" href="../../index.html">index.rb</a>
16
+ <a class="source" href="bundler.html">bundler.rb</a>
17
+ <a class="source" href="capistrano_extensions.html">capistrano_extensions.rb</a>
18
+ <a class="source" href="cli.html">cli.rb</a>
19
+ <a class="source" href="compatibility.html">compatibility.rb</a>
20
+ <a class="source" href="deploy.html">deploy.rb</a>
21
+ <a class="source" href="env.html">env.rb</a>
22
+ <a class="source" href="foreman.html">foreman.rb</a>
23
+ <a class="source" href="preflight.html">preflight.rb</a>
24
+ <a class="source" href="rails.html">rails.rb</a>
25
+ <a class="source" href="version.html">version.rb</a>
26
+ </div>
27
+ </div>
28
+ </div>
29
+ <table cellspacing=0 cellpadding=0>
30
+ <thead>
31
+ <tr>
32
+ <th class=docs><h1>env.rb</h1></th>
33
+ <th class=code></th>
34
+ </tr>
35
+ </thead>
36
+ <tbody>
37
+ <tr id='section-1'>
38
+ <td class=docs>
39
+ <div class="pilwrap">
40
+ <a class="pilcrow" href="#section-1">&#182;</a>
41
+ </div>
42
+ <p>N.B. To get the environment loaded on every shell invocation add the following to .profile:</p>
43
+
44
+ <pre><code>if [ -s &ldquo;$HOME/.env&rdquo; ]; then export $(cat $HOME/.env); fi
45
+ </code></pre>
46
+
47
+ <p>This will eventually be done automatically</p>
48
+
49
+ </td>
50
+ <td class=code>
51
+ <div class='highlight'><pre><span class="no">Capistrano</span><span class="o">::</span><span class="no">Configuration</span><span class="o">.</span><span class="n">instance</span><span class="p">(</span><span class="ss">:must_exist</span><span class="p">)</span><span class="o">.</span><span class="n">load</span> <span class="k">do</span>
52
+ <span class="n">namespace</span> <span class="ss">:env</span> <span class="k">do</span>
53
+ <span class="n">set</span><span class="p">(</span><span class="ss">:environment_file</span><span class="p">)</span> <span class="p">{</span> <span class="s2">&quot;/home/</span><span class="si">#{</span><span class="n">application_user</span><span class="si">}</span><span class="s2">/.env&quot;</span> <span class="p">}</span>
54
+
55
+ <span class="k">def</span> <span class="nf">extract_environment</span><span class="p">(</span><span class="n">declarations</span><span class="p">)</span>
56
+ <span class="n">declarations</span><span class="o">.</span><span class="n">inject</span><span class="p">({})</span> <span class="k">do</span> <span class="o">|</span><span class="n">env</span><span class="p">,</span> <span class="n">line</span><span class="o">|</span>
57
+ <span class="k">if</span> <span class="n">line</span> <span class="o">=~</span> <span class="sr">/\A([A-Za-z_]+)=(.*)\z/</span>
58
+ <span class="n">env</span><span class="o">[</span><span class="vg">$1</span><span class="o">]</span> <span class="o">=</span> <span class="vg">$2</span><span class="o">.</span><span class="n">strip</span>
59
+ <span class="k">end</span>
60
+ <span class="n">env</span>
61
+ <span class="k">end</span>
62
+ <span class="k">end</span>
63
+
64
+ <span class="k">def</span> <span class="nf">current_environment</span>
65
+ <span class="vi">@current_environment</span> <span class="o">||=</span> <span class="k">begin</span>
66
+ <span class="k">if</span> <span class="n">deployed_file_exists?</span><span class="p">(</span><span class="n">environment_file</span><span class="p">)</span>
67
+ <span class="n">extract_environment</span><span class="p">(</span><span class="n">capture</span><span class="p">(</span><span class="s2">&quot;cat </span><span class="si">#{</span><span class="n">environment_file</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">))</span>
68
+ <span class="k">else</span>
69
+ <span class="p">{}</span>
70
+ <span class="k">end</span>
71
+ <span class="k">end</span>
72
+ <span class="k">end</span>
73
+
74
+ <span class="k">def</span> <span class="nf">write_environment</span><span class="p">(</span><span class="n">env</span><span class="p">)</span>
75
+ <span class="n">env</span><span class="o">.</span><span class="n">keys</span><span class="o">.</span><span class="n">sort</span><span class="o">.</span><span class="n">collect</span> <span class="k">do</span> <span class="o">|</span><span class="n">v</span><span class="o">|</span>
76
+ <span class="s2">&quot;</span><span class="si">#{</span><span class="n">v</span><span class="si">}</span><span class="s2">=</span><span class="si">#{</span><span class="n">env</span><span class="o">[</span><span class="n">v</span><span class="o">]</span><span class="si">}</span><span class="s2">&quot;</span> <span class="k">unless</span> <span class="n">env</span><span class="o">[</span><span class="n">v</span><span class="o">].</span><span class="n">nil?</span> <span class="o">||</span> <span class="n">env</span><span class="o">[</span><span class="n">v</span><span class="o">].</span><span class="n">empty?</span>
77
+ <span class="k">end</span><span class="o">.</span><span class="n">compact</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
78
+ <span class="k">end</span>
79
+
80
+ <span class="n">task</span> <span class="ss">:default</span> <span class="k">do</span>
81
+ <span class="nb">puts</span> <span class="n">write_environment</span><span class="p">(</span><span class="n">current_environment</span><span class="p">)</span>
82
+ <span class="k">end</span>
83
+
84
+ <span class="n">task</span> <span class="ss">:set</span> <span class="k">do</span>
85
+ <span class="n">additions</span> <span class="o">=</span> <span class="n">extract_environment</span><span class="p">(</span><span class="no">ARGV</span><span class="o">[</span><span class="mi">1</span><span class="o">.</span><span class="n">.</span><span class="o">-</span><span class="mi">1</span><span class="o">]</span><span class="p">)</span>
86
+ <span class="n">env</span> <span class="o">=</span> <span class="n">write_environment</span><span class="p">(</span><span class="n">current_environment</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">additions</span><span class="p">))</span>
87
+ <span class="k">if</span> <span class="n">env</span><span class="o">.</span><span class="n">empty?</span>
88
+ <span class="n">as_app</span> <span class="s2">&quot;rm -f </span><span class="si">#{</span><span class="n">environment_file</span><span class="si">}</span><span class="s2">&quot;</span>
89
+ <span class="k">else</span>
90
+ <span class="n">put_as_app</span> <span class="n">env</span><span class="p">,</span> <span class="n">environment_file</span>
91
+ <span class="k">end</span>
92
+ <span class="k">end</span>
93
+
94
+ <span class="n">task</span> <span class="ss">:edit</span> <span class="k">do</span>
95
+ <span class="n">edit_file</span> <span class="n">environment_file</span>
96
+ <span class="k">end</span>
97
+ <span class="k">end</span>
98
+ <span class="k">end</span></pre></div>
99
+ </td>
100
+ </tr>
101
+ </table>
102
+ </div>
103
+ </body>
@@ -0,0 +1,39 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>foreman.rb</title>
6
+ <link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
7
+ </head>
8
+ <body>
9
+ <div id='container'>
10
+ <div id="background"></div>
11
+ <div id="jump_to">
12
+ Jump To &hellip;
13
+ <div id="jump_wrapper">
14
+ <div id="jump_page">
15
+ <a class="source" href="../../index.html">index.rb</a>
16
+ <a class="source" href="bundler.html">bundler.rb</a>
17
+ <a class="source" href="capistrano_extensions.html">capistrano_extensions.rb</a>
18
+ <a class="source" href="cli.html">cli.rb</a>
19
+ <a class="source" href="compatibility.html">compatibility.rb</a>
20
+ <a class="source" href="deploy.html">deploy.rb</a>
21
+ <a class="source" href="env.html">env.rb</a>
22
+ <a class="source" href="foreman.html">foreman.rb</a>
23
+ <a class="source" href="preflight.html">preflight.rb</a>
24
+ <a class="source" href="rails.html">rails.rb</a>
25
+ <a class="source" href="version.html">version.rb</a>
26
+ </div>
27
+ </div>
28
+ </div>
29
+ <table cellspacing=0 cellpadding=0>
30
+ <thead>
31
+ <tr>
32
+ <th class=docs><h1>foreman.rb</h1></th>
33
+ <th class=code></th>
34
+ </tr>
35
+ </thead>
36
+ <tbody>
37
+ </table>
38
+ </div>
39
+ </body>