recap 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/.gitignore +3 -0
  2. data/.travis.yml +4 -0
  3. data/README.md +12 -3
  4. data/Rakefile +8 -0
  5. data/Vagrantfile +61 -0
  6. data/doc/index.html +45 -26
  7. data/doc/lib/recap/bootstrap.html +42 -0
  8. data/doc/lib/recap/bundler.html +36 -19
  9. data/doc/lib/recap/capistrano_extensions.html +28 -23
  10. data/doc/lib/recap/cli.html +3 -0
  11. data/doc/lib/recap/compatibility.html +6 -3
  12. data/doc/lib/recap/deploy.html +41 -86
  13. data/doc/lib/recap/env.html +6 -1
  14. data/doc/lib/recap/foreman.html +3 -0
  15. data/doc/lib/recap/namespace.html +42 -0
  16. data/doc/lib/recap/preflight.html +12 -7
  17. data/doc/lib/recap/rails.html +3 -0
  18. data/doc/lib/recap/version.html +3 -0
  19. data/doc/lib/recap.html +42 -0
  20. data/features/bundling-gems.feature +18 -0
  21. data/features/deploying-projects.feature +21 -0
  22. data/features/managing-processes.feature +17 -0
  23. data/features/setting-environment-variables.feature +21 -0
  24. data/features/steps/capistrano_steps.rb +98 -0
  25. data/features/support/project.rb +211 -0
  26. data/features/support/server.rb +53 -0
  27. data/features/templates/gem/binary.erb +43 -0
  28. data/features/templates/gem/gemspec.erb +11 -0
  29. data/features/templates/project/Capfile +21 -0
  30. data/features/templates/project/Capfile.erb +21 -0
  31. data/features/templates/project/Gemfile.erb +7 -0
  32. data/features/templates/project/Procfile.erb +1 -0
  33. data/index.rb +26 -17
  34. data/lib/recap/bootstrap.rb +47 -0
  35. data/lib/recap/bundler.rb +31 -21
  36. data/lib/recap/capistrano_extensions.rb +11 -9
  37. data/lib/recap/cli.rb +1 -1
  38. data/lib/recap/compatibility.rb +3 -3
  39. data/lib/recap/deploy.rb +45 -57
  40. data/lib/recap/env.rb +30 -26
  41. data/lib/recap/environment.rb +54 -0
  42. data/lib/recap/foreman.rb +28 -9
  43. data/lib/recap/namespace.rb +37 -0
  44. data/lib/recap/preflight.rb +10 -8
  45. data/lib/recap/rails.rb +6 -4
  46. data/lib/recap/ruby.rb +3 -0
  47. data/lib/recap/static.rb +1 -0
  48. data/lib/recap/version.rb +1 -1
  49. data/lib/recap.rb +12 -0
  50. data/recap.gemspec +8 -4
  51. data/spec/models/environment_spec.rb +143 -0
  52. data/spec/spec_helper.rb +7 -0
  53. data/spec/tasks/bootstrap_spec.rb +34 -0
  54. data/spec/tasks/bundler_spec.rb +126 -0
  55. data/spec/tasks/deploy_spec.rb +209 -0
  56. data/spec/tasks/env_spec.rb +38 -0
  57. data/spec/tasks/foreman_spec.rb +154 -0
  58. data/test-vm/manifests/base.pp +17 -0
  59. data/test-vm/share/.gitkeep +0 -0
  60. metadata +138 -19
  61. /data/bin/{tomafro-deploy → recap} +0 -0
@@ -13,6 +13,8 @@
13
13
  <div id="jump_wrapper">
14
14
  <div id="jump_page">
15
15
  <a class="source" href="../../index.html">index.rb</a>
16
+ <a class="source" href="../recap.html">recap.rb</a>
17
+ <a class="source" href="bootstrap.html">bootstrap.rb</a>
16
18
  <a class="source" href="bundler.html">bundler.rb</a>
17
19
  <a class="source" href="capistrano_extensions.html">capistrano_extensions.rb</a>
18
20
  <a class="source" href="cli.html">cli.rb</a>
@@ -20,6 +22,7 @@
20
22
  <a class="source" href="deploy.html">deploy.rb</a>
21
23
  <a class="source" href="env.html">env.rb</a>
22
24
  <a class="source" href="foreman.html">foreman.rb</a>
25
+ <a class="source" href="namespace.html">namespace.rb</a>
23
26
  <a class="source" href="preflight.html">preflight.rb</a>
24
27
  <a class="source" href="rails.html">rails.rb</a>
25
28
  <a class="source" href="version.html">version.rb</a>
@@ -98,18 +101,6 @@
98
101
  <div class='highlight'><pre> <span class="k">def</span> <span class="nf">put_as_app</span><span class="p">(</span><span class="n">string</span><span class="p">,</span> <span class="n">path</span><span class="p">)</span>
99
102
  <span class="n">as_app</span> <span class="s2">&quot;touch </span><span class="si">#{</span><span class="n">path</span><span class="si">}</span><span class="s2"> &amp;&amp; chmod g+rw </span><span class="si">#{</span><span class="n">path</span><span class="si">}</span><span class="s2">&quot;</span>
100
103
  <span class="n">put</span> <span class="n">string</span><span class="p">,</span> <span class="n">path</span>
101
- <span class="k">end</span>
102
-
103
- <span class="k">def</span> <span class="nf">edit_file</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
104
- <span class="k">if</span> <span class="n">editor</span> <span class="o">=</span> <span class="no">ENV</span><span class="o">[</span><span class="s1">&#39;DEPLOY_EDITOR&#39;</span><span class="o">]</span> <span class="o">||</span> <span class="no">ENV</span><span class="o">[</span><span class="s1">&#39;EDITOR&#39;</span><span class="o">]</span>
105
- <span class="n">as_app</span> <span class="s2">&quot;touch </span><span class="si">#{</span><span class="n">path</span><span class="si">}</span><span class="s2"> &amp;&amp; chmod g+rw </span><span class="si">#{</span><span class="n">path</span><span class="si">}</span><span class="s2">&quot;</span>
106
- <span class="n">local_path</span> <span class="o">=</span> <span class="no">Tempfile</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="s1">&#39;deploy-edit&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">path</span>
107
- <span class="n">get</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">local_path</span><span class="p">)</span>
108
- <span class="sb">`</span><span class="si">#{</span><span class="n">editor</span><span class="si">}</span><span class="sb"> </span><span class="si">#{</span><span class="n">local_path</span><span class="si">}</span><span class="sb">`</span>
109
- <span class="n">upload</span><span class="p">(</span><span class="n">local_path</span><span class="p">,</span> <span class="n">path</span><span class="p">)</span>
110
- <span class="k">else</span>
111
- <span class="nb">abort</span> <span class="s2">&quot;To edit a remote file, either the EDITOR or DEPLOY_EDITOR environment variables must be set&quot;</span>
112
- <span class="k">end</span>
113
104
  <span class="k">end</span></pre></div>
114
105
  </td>
115
106
  </tr>
@@ -118,11 +109,19 @@
118
109
  <div class="pilwrap">
119
110
  <a class="pilcrow" href="#section-6">&#182;</a>
120
111
  </div>
121
- <p>Run a git command in the <code>deploy_to</code> directory</p>
112
+ <p>Edit a file on the remote server, using a local editor</p>
122
113
  </td>
123
114
  <td class=code>
124
- <div class='highlight'><pre> <span class="k">def</span> <span class="nf">git</span><span class="p">(</span><span class="n">command</span><span class="p">)</span>
125
- <span class="n">run</span> <span class="s2">&quot;cd </span><span class="si">#{</span><span class="n">deploy_to</span><span class="si">}</span><span class="s2"> &amp;&amp; git </span><span class="si">#{</span><span class="n">command</span><span class="si">}</span><span class="s2">&quot;</span>
115
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">edit_file</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
116
+ <span class="k">if</span> <span class="n">editor</span> <span class="o">=</span> <span class="no">ENV</span><span class="o">[</span><span class="s1">&#39;DEPLOY_EDITOR&#39;</span><span class="o">]</span> <span class="o">||</span> <span class="no">ENV</span><span class="o">[</span><span class="s1">&#39;EDITOR&#39;</span><span class="o">]</span>
117
+ <span class="n">as_app</span> <span class="s2">&quot;touch </span><span class="si">#{</span><span class="n">path</span><span class="si">}</span><span class="s2"> &amp;&amp; chmod g+rw </span><span class="si">#{</span><span class="n">path</span><span class="si">}</span><span class="s2">&quot;</span>
118
+ <span class="n">local_path</span> <span class="o">=</span> <span class="no">Tempfile</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="s1">&#39;deploy-edit&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">path</span>
119
+ <span class="n">get</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">local_path</span><span class="p">)</span>
120
+ <span class="sb">`</span><span class="si">#{</span><span class="n">editor</span><span class="si">}</span><span class="sb"> </span><span class="si">#{</span><span class="n">local_path</span><span class="si">}</span><span class="sb">`</span>
121
+ <span class="n">upload</span><span class="p">(</span><span class="n">local_path</span><span class="p">,</span> <span class="n">path</span><span class="p">)</span>
122
+ <span class="k">else</span>
123
+ <span class="nb">abort</span> <span class="s2">&quot;To edit a remote file, either the EDITOR or DEPLOY_EDITOR environment variables must be set&quot;</span>
124
+ <span class="k">end</span>
126
125
  <span class="k">end</span></pre></div>
127
126
  </td>
128
127
  </tr>
@@ -131,11 +130,11 @@
131
130
  <div class="pilwrap">
132
131
  <a class="pilcrow" href="#section-7">&#182;</a>
133
132
  </div>
134
- <p>Capture the result of a git command run within the <code>deploy_to</code> directory</p>
133
+ <p>Run a git command in the <code>deploy_to</code> directory</p>
135
134
  </td>
136
135
  <td class=code>
137
- <div class='highlight'><pre> <span class="k">def</span> <span class="nf">capture_git</span><span class="p">(</span><span class="n">command</span><span class="p">)</span>
138
- <span class="n">capture</span> <span class="s2">&quot;cd </span><span class="si">#{</span><span class="n">deploy_to</span><span class="si">}</span><span class="s2"> &amp;&amp; git </span><span class="si">#{</span><span class="n">command</span><span class="si">}</span><span class="s2">&quot;</span>
136
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">git</span><span class="p">(</span><span class="n">command</span><span class="p">)</span>
137
+ <span class="n">run</span> <span class="s2">&quot;cd </span><span class="si">#{</span><span class="n">deploy_to</span><span class="si">}</span><span class="s2"> &amp;&amp; umask 002 &amp;&amp; sg </span><span class="si">#{</span><span class="n">application_group</span><span class="si">}</span><span class="s2"> -c </span><span class="se">\&quot;</span><span class="s2">git </span><span class="si">#{</span><span class="n">command</span><span class="si">}</span><span class="se">\&quot;</span><span class="s2">&quot;</span>
139
138
  <span class="k">end</span></pre></div>
140
139
  </td>
141
140
  </tr>
@@ -144,11 +143,15 @@
144
143
  <div class="pilwrap">
145
144
  <a class="pilcrow" href="#section-8">&#182;</a>
146
145
  </div>
147
- <p>Run a bundle command in the <code>deploy_to</code> directory</p>
146
+ <p>Capture the result of a git command run within the <code>deploy_to</code> directory</p>
148
147
  </td>
149
148
  <td class=code>
150
- <div class='highlight'><pre> <span class="k">def</span> <span class="nf">bundler</span><span class="p">(</span><span class="n">command</span><span class="p">)</span>
151
- <span class="n">as_app</span> <span class="s2">&quot;bundle </span><span class="si">#{</span><span class="n">command</span><span class="si">}</span><span class="s2">&quot;</span>
149
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">capture_git</span><span class="p">(</span><span class="n">command</span><span class="p">)</span>
150
+ <span class="n">capture</span> <span class="s2">&quot;cd </span><span class="si">#{</span><span class="n">deploy_to</span><span class="si">}</span><span class="s2"> &amp;&amp; umask 002 &amp;&amp; sg </span><span class="si">#{</span><span class="n">application_group</span><span class="si">}</span><span class="s2"> -c &#39;git </span><span class="si">#{</span><span class="n">command</span><span class="si">}</span><span class="s2">&#39;&quot;</span>
151
+ <span class="k">end</span>
152
+
153
+ <span class="k">def</span> <span class="nf">exit_code</span><span class="p">(</span><span class="n">command</span><span class="p">)</span>
154
+ <span class="n">capture</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">#{</span><span class="n">command</span><span class="si">}</span><span class="s2"> &gt; /dev/null 2&gt;&amp;1; echo $?&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span>
152
155
  <span class="k">end</span></pre></div>
153
156
  </td>
154
157
  </tr>
@@ -176,7 +179,7 @@ tags are timestamps, the latest tag will always be the last in the list.</p>
176
179
  </td>
177
180
  <td class=code>
178
181
  <div class='highlight'><pre> <span class="k">def</span> <span class="nf">deployed_file_exists?</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
179
- <span class="n">capture</span><span class="p">(</span><span class="s2">&quot;cd </span><span class="si">#{</span><span class="n">deploy_to</span><span class="si">}</span><span class="s2"> &amp;&amp; [ -f </span><span class="si">#{</span><span class="n">path</span><span class="si">}</span><span class="s2"> ]; echo $?&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span> <span class="o">==</span> <span class="s2">&quot;0&quot;</span>
182
+ <span class="n">exit_code</span><span class="p">(</span><span class="s2">&quot;cd </span><span class="si">#{</span><span class="n">deploy_to</span><span class="si">}</span><span class="s2"> &amp;&amp; [ -f </span><span class="si">#{</span><span class="n">path</span><span class="si">}</span><span class="s2"> ]&quot;</span><span class="p">)</span> <span class="o">==</span> <span class="s2">&quot;0&quot;</span>
180
183
  <span class="k">end</span></pre></div>
181
184
  </td>
182
185
  </tr>
@@ -192,8 +195,10 @@ successful deployment this will always return true.</p>
192
195
  <td class=code>
193
196
  <div class='highlight'><pre> <span class="k">def</span> <span class="nf">deployed_file_changed?</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
194
197
  <span class="k">return</span> <span class="kp">true</span> <span class="k">unless</span> <span class="n">latest_tag</span>
195
- <span class="n">capture_git</span><span class="p">(</span><span class="s2">&quot;diff --exit-code </span><span class="si">#{</span><span class="n">latest_tag</span><span class="si">}</span><span class="s2"> origin/</span><span class="si">#{</span><span class="n">branch</span><span class="si">}</span><span class="s2"> </span><span class="si">#{</span><span class="n">path</span><span class="si">}</span><span class="s2"> &gt; /dev/null; echo $?&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span> <span class="o">==</span> <span class="s2">&quot;1&quot;</span>
198
+ <span class="n">exit_code</span><span class="p">(</span><span class="s2">&quot;cd </span><span class="si">#{</span><span class="n">deploy_to</span><span class="si">}</span><span class="s2"> &amp;&amp; git diff --exit-code </span><span class="si">#{</span><span class="n">latest_tag</span><span class="si">}</span><span class="s2"> origin/</span><span class="si">#{</span><span class="n">branch</span><span class="si">}</span><span class="s2"> </span><span class="si">#{</span><span class="n">path</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span> <span class="o">==</span> <span class="s2">&quot;1&quot;</span>
196
199
  <span class="k">end</span>
200
+
201
+ <span class="no">Capistrano</span><span class="o">::</span><span class="no">Configuration</span><span class="o">.</span><span class="n">send</span> <span class="ss">:include</span><span class="p">,</span> <span class="nb">self</span>
197
202
  <span class="k">end</span>
198
203
  <span class="k">end</span></pre></div>
199
204
  </td>
@@ -13,6 +13,8 @@
13
13
  <div id="jump_wrapper">
14
14
  <div id="jump_page">
15
15
  <a class="source" href="../../index.html">index.rb</a>
16
+ <a class="source" href="../recap.html">recap.rb</a>
17
+ <a class="source" href="bootstrap.html">bootstrap.rb</a>
16
18
  <a class="source" href="bundler.html">bundler.rb</a>
17
19
  <a class="source" href="capistrano_extensions.html">capistrano_extensions.rb</a>
18
20
  <a class="source" href="cli.html">cli.rb</a>
@@ -20,6 +22,7 @@
20
22
  <a class="source" href="deploy.html">deploy.rb</a>
21
23
  <a class="source" href="env.html">env.rb</a>
22
24
  <a class="source" href="foreman.html">foreman.rb</a>
25
+ <a class="source" href="namespace.html">namespace.rb</a>
23
26
  <a class="source" href="preflight.html">preflight.rb</a>
24
27
  <a class="source" href="rails.html">rails.rb</a>
25
28
  <a class="source" href="version.html">version.rb</a>
@@ -13,6 +13,8 @@
13
13
  <div id="jump_wrapper">
14
14
  <div id="jump_page">
15
15
  <a class="source" href="../../index.html">index.rb</a>
16
+ <a class="source" href="../recap.html">recap.rb</a>
17
+ <a class="source" href="bootstrap.html">bootstrap.rb</a>
16
18
  <a class="source" href="bundler.html">bundler.rb</a>
17
19
  <a class="source" href="capistrano_extensions.html">capistrano_extensions.rb</a>
18
20
  <a class="source" href="cli.html">cli.rb</a>
@@ -20,6 +22,7 @@
20
22
  <a class="source" href="deploy.html">deploy.rb</a>
21
23
  <a class="source" href="env.html">env.rb</a>
22
24
  <a class="source" href="foreman.html">foreman.rb</a>
25
+ <a class="source" href="namespace.html">namespace.rb</a>
23
26
  <a class="source" href="preflight.html">preflight.rb</a>
24
27
  <a class="source" href="rails.html">rails.rb</a>
25
28
  <a class="source" href="version.html">version.rb</a>
@@ -41,14 +44,14 @@
41
44
  </div>
42
45
  <p><code>recap</code> isn&rsquo;t intended to be compatible with tasks (such as those within the <code>bundler</code>
43
46
  or <code>whenever</code> projects) that are built on the original capistrano deployment recipes. At times
44
- though there are tasks that would work, but for some missing (and redundant) settings. </p>
47
+ though there are tasks that would work, but for some missing (and redundant) settings.</p>
45
48
 
46
49
  <p>Including this recipe adds these legacy settings, but provides no guarantee that original tasks
47
50
  will work. Many are based on assumptions about the deployment layout that no longer hold true.</p>
48
51
  </td>
49
52
  <td class=code>
50
- <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>
51
- <span class="kp">extend</span> <span class="no">Recap</span><span class="o">::</span><span class="no">CapistranoExtensions</span></pre></div>
53
+ <div class='highlight'><pre><span class="k">module</span> <span class="nn">Recap::Compatibility</span>
54
+ <span class="kp">extend</span> <span class="no">Recap</span><span class="o">::</span><span class="no">Namespace</span></pre></div>
52
55
  </td>
53
56
  </tr>
54
57
  <tr id='section-2'>
@@ -13,6 +13,8 @@
13
13
  <div id="jump_wrapper">
14
14
  <div id="jump_page">
15
15
  <a class="source" href="../../index.html">index.rb</a>
16
+ <a class="source" href="../recap.html">recap.rb</a>
17
+ <a class="source" href="bootstrap.html">bootstrap.rb</a>
16
18
  <a class="source" href="bundler.html">bundler.rb</a>
17
19
  <a class="source" href="capistrano_extensions.html">capistrano_extensions.rb</a>
18
20
  <a class="source" href="cli.html">cli.rb</a>
@@ -20,6 +22,7 @@
20
22
  <a class="source" href="deploy.html">deploy.rb</a>
21
23
  <a class="source" href="env.html">env.rb</a>
22
24
  <a class="source" href="foreman.html">foreman.rb</a>
25
+ <a class="source" href="namespace.html">namespace.rb</a>
23
26
  <a class="source" href="preflight.html">preflight.rb</a>
24
27
  <a class="source" href="rails.html">rails.rb</a>
25
28
  <a class="source" href="version.html">version.rb</a>
@@ -42,12 +45,18 @@
42
45
 
43
46
  </td>
44
47
  <td class=code>
45
- <div class='highlight'><pre><span class="nb">require</span> <span class="s1">&#39;recap/capistrano_extensions&#39;</span>
48
+ <div class='highlight'><pre><span class="nb">require</span> <span class="s1">&#39;recap&#39;</span>
49
+ <span class="nb">require</span> <span class="s1">&#39;recap/capistrano_extensions&#39;</span>
50
+
51
+ <span class="nb">require</span> <span class="s1">&#39;recap/bootstrap&#39;</span>
46
52
  <span class="nb">require</span> <span class="s1">&#39;recap/bundler&#39;</span>
53
+ <span class="nb">require</span> <span class="s1">&#39;recap/env&#39;</span>
47
54
  <span class="nb">require</span> <span class="s1">&#39;recap/preflight&#39;</span>
48
55
 
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>
56
+ <span class="k">module</span> <span class="nn">Recap::Deploy</span>
57
+ <span class="kp">extend</span> <span class="no">Recap</span><span class="o">::</span><span class="no">Namespace</span>
58
+
59
+ <span class="n">namespace</span> <span class="ss">:deploy</span> <span class="k">do</span></pre></div>
51
60
  </td>
52
61
  </tr>
53
62
  <tr id='section-2'>
@@ -58,8 +67,8 @@
58
67
  <p>To use this recipe, both the application&rsquo;s name and its git repository are required.</p>
59
68
  </td>
60
69
  <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>
70
+ <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>
71
+ <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
72
  </td>
64
73
  </tr>
65
74
  <tr id='section-3'>
@@ -72,8 +81,8 @@ can deploy the application should be added as a member of the application&rsquo;
72
81
  both the application user and group take the same name as the application.</p>
73
82
  </td>
74
83
  <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>
84
+ <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>
85
+ <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
86
  </td>
78
87
  </tr>
79
88
  <tr id='section-4'>
@@ -84,7 +93,7 @@ both the application user and group take the same name as the application.</p>
84
93
  <p>Deployments can be made from any branch. <code>master</code> is used by default.</p>
85
94
  </td>
86
95
  <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>
96
+ <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
97
  </td>
89
98
  </tr>
90
99
  <tr id='section-5'>
@@ -93,10 +102,10 @@ both the application user and group take the same name as the application.</p>
93
102
  <a class="pilcrow" href="#section-5">&#182;</a>
94
103
  </div>
95
104
  <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>
105
+ directory. The default is <code>/home/#{application_user}/apps/#{application}</code>.</p>
97
106
  </td>
98
107
  <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>
108
+ <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;/home/</span><span class="si">#{</span><span class="n">application_user</span><span class="si">}</span><span class="s2">/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
109
  </td>
101
110
  </tr>
102
111
  <tr id='section-6'>
@@ -109,7 +118,7 @@ changed, it&rsquo;s not recommended, as the sort order of the tag names is impor
109
118
  be listed after earlier tags.</p>
110
119
  </td>
111
120
  <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>
121
+ <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
122
  </td>
114
123
  </tr>
115
124
  <tr id='section-7'>
@@ -121,7 +130,7 @@ be listed after earlier tags.</p>
121
130
  anything useful &ndash; its contents are not important for the recipe.</p>
122
131
  </td>
123
132
  <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>
133
+ <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
134
  </td>
126
135
  </tr>
127
136
  <tr id='section-8'>
@@ -133,7 +142,7 @@ anything useful &ndash; its contents are not important for the recipe.</p>
133
142
  deployments have been made, this will be <code>nil</code>.</p>
134
143
  </td>
135
144
  <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>
145
+ <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
146
  </td>
138
147
  </tr>
139
148
  <tr id='section-9'>
@@ -145,7 +154,7 @@ deployments have been made, this will be <code>nil</code>.</p>
145
154
  deploying user&rsquo;s ssh key than manage keys on deployment servers.</p>
146
155
  </td>
147
156
  <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>
157
+ <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
158
  </td>
150
159
  </tr>
151
160
  <tr id='section-10'>
@@ -157,9 +166,7 @@ deploying user&rsquo;s ssh key than manage keys on deployment servers.</p>
157
166
  <code>:pty</code> is set to <code>true</code>.</p>
158
167
  </td>
159
168
  <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>
169
+ <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></pre></div>
163
170
  </td>
164
171
  </tr>
165
172
  <tr id='section-11'>
@@ -194,12 +201,11 @@ deploying user&rsquo;s ssh key than manage keys on deployment servers.</p>
194
201
  <div class="pilwrap">
195
202
  <a class="pilcrow" href="#section-13">&#182;</a>
196
203
  </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>
204
+ <p>Before cloning, the directory needs to exist and be both readable and writable by the group</p>
200
205
  </td>
201
206
  <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>
207
+ <div class='highlight'><pre> <span class="n">as_app</span> <span class="s2">&quot;mkdir -p </span><span class="si">#{</span><span class="n">deploy_to</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">,</span> <span class="s2">&quot;~&quot;</span>
208
+ <span class="n">as_app</span> <span class="s2">&quot;chmod g+rw </span><span class="si">#{</span><span class="n">deploy_to</span><span class="si">}</span><span class="s2">&quot;</span></pre></div>
203
209
  </td>
204
210
  </tr>
205
211
  <tr id='section-14'>
@@ -207,11 +213,11 @@ doesn&rsquo;t already exist).</p>
207
213
  <div class="pilwrap">
208
214
  <a class="pilcrow" href="#section-14">&#182;</a>
209
215
  </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>
216
+ <p>Then clone the code</p>
212
217
  </td>
213
218
  <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>
219
+ <div class='highlight'><pre> <span class="n">git</span> <span class="s2">&quot;clone </span><span class="si">#{</span><span class="n">repository</span><span class="si">}</span><span class="s2"> .&quot;</span>
220
+ <span class="k">end</span></pre></div>
215
221
  </td>
216
222
  </tr>
217
223
  <tr id='section-15'>
@@ -219,45 +225,6 @@ permission to write in the base deployment folder.</p>
219
225
  <div class="pilwrap">
220
226
  <a class="pilcrow" href="#section-15">&#182;</a>
221
227
  </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
228
  <p>The main deployment task (called with <code>cap deploy</code>) deploys the latest application code to all
262
229
  servers, tags the release and restarts the application.</p>
263
230
  </td>
@@ -272,10 +239,10 @@ servers, tags the release and restarts the application.</p>
272
239
  <span class="k">end</span></pre></div>
273
240
  </td>
274
241
  </tr>
275
- <tr id='section-19'>
242
+ <tr id='section-16'>
276
243
  <td class=docs>
277
244
  <div class="pilwrap">
278
- <a class="pilcrow" href="#section-19">&#182;</a>
245
+ <a class="pilcrow" href="#section-16">&#182;</a>
279
246
  </div>
280
247
  <p>Fetch the latest changes, then update <code>HEAD</code> to the deployment branch.</p>
281
248
  </td>
@@ -283,25 +250,14 @@ servers, tags the release and restarts the application.</p>
283
250
  <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
251
  <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
252
  <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>
253
+ <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>
298
254
  <span class="k">end</span></pre></div>
299
255
  </td>
300
256
  </tr>
301
- <tr id='section-21'>
257
+ <tr id='section-17'>
302
258
  <td class=docs>
303
259
  <div class="pilwrap">
304
- <a class="pilcrow" href="#section-21">&#182;</a>
260
+ <a class="pilcrow" href="#section-17">&#182;</a>
305
261
  </div>
306
262
  <p>Tag <code>HEAD</code> with the release tag and message</p>
307
263
  </td>
@@ -309,14 +265,13 @@ servers, tags the release and restarts the application.</p>
309
265
  <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
266
  <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
267
  <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
268
  <span class="k">end</span></pre></div>
314
269
  </td>
315
270
  </tr>
316
- <tr id='section-22'>
271
+ <tr id='section-18'>
317
272
  <td class=docs>
318
273
  <div class="pilwrap">
319
- <a class="pilcrow" href="#section-22">&#182;</a>
274
+ <a class="pilcrow" href="#section-18">&#182;</a>
320
275
  </div>
321
276
  <p>After a successful deployment, the app is restarted. In the most basic deployments this does
322
277
  nothing, but other recipes may override it, or attach tasks it&rsquo;s before or after hooks.</p>
@@ -327,10 +282,10 @@ nothing, but other recipes may override it, or attach tasks it&rsquo;s before or
327
282
  <span class="k">end</span></pre></div>
328
283
  </td>
329
284
  </tr>
330
- <tr id='section-23'>
285
+ <tr id='section-19'>
331
286
  <td class=docs>
332
287
  <div class="pilwrap">
333
- <a class="pilcrow" href="#section-23">&#182;</a>
288
+ <a class="pilcrow" href="#section-19">&#182;</a>
334
289
  </div>
335
290
  <p>To rollback a release, the latest tag is deleted, and <code>HEAD</code> reset to the previous release
336
291
  (if one exists). Finally the application is restarted again.</p>
@@ -350,10 +305,10 @@ nothing, but other recipes may override it, or attach tasks it&rsquo;s before or
350
305
  <span class="k">end</span></pre></div>
351
306
  </td>
352
307
  </tr>
353
- <tr id='section-24'>
308
+ <tr id='section-20'>
354
309
  <td class=docs>
355
310
  <div class="pilwrap">
356
- <a class="pilcrow" href="#section-24">&#182;</a>
311
+ <a class="pilcrow" href="#section-20">&#182;</a>
357
312
  </div>
358
313
  <p>In case of emergency or when manually testing deployment, it can be useful to remove all
359
314
  previously deployed files before starting again.</p>
@@ -13,6 +13,8 @@
13
13
  <div id="jump_wrapper">
14
14
  <div id="jump_page">
15
15
  <a class="source" href="../../index.html">index.rb</a>
16
+ <a class="source" href="../recap.html">recap.rb</a>
17
+ <a class="source" href="bootstrap.html">bootstrap.rb</a>
16
18
  <a class="source" href="bundler.html">bundler.rb</a>
17
19
  <a class="source" href="capistrano_extensions.html">capistrano_extensions.rb</a>
18
20
  <a class="source" href="cli.html">cli.rb</a>
@@ -20,6 +22,7 @@
20
22
  <a class="source" href="deploy.html">deploy.rb</a>
21
23
  <a class="source" href="env.html">env.rb</a>
22
24
  <a class="source" href="foreman.html">foreman.rb</a>
25
+ <a class="source" href="namespace.html">namespace.rb</a>
23
26
  <a class="source" href="preflight.html">preflight.rb</a>
24
27
  <a class="source" href="rails.html">rails.rb</a>
25
28
  <a class="source" href="version.html">version.rb</a>
@@ -48,7 +51,9 @@
48
51
 
49
52
  </td>
50
53
  <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>
54
+ <div class='highlight'><pre><span class="k">module</span> <span class="nn">Recap::Env</span>
55
+ <span class="kp">extend</span> <span class="no">Recap</span><span class="o">::</span><span class="no">Namespace</span>
56
+
52
57
  <span class="n">namespace</span> <span class="ss">:env</span> <span class="k">do</span>
53
58
  <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
59
 
@@ -13,6 +13,8 @@
13
13
  <div id="jump_wrapper">
14
14
  <div id="jump_page">
15
15
  <a class="source" href="../../index.html">index.rb</a>
16
+ <a class="source" href="../recap.html">recap.rb</a>
17
+ <a class="source" href="bootstrap.html">bootstrap.rb</a>
16
18
  <a class="source" href="bundler.html">bundler.rb</a>
17
19
  <a class="source" href="capistrano_extensions.html">capistrano_extensions.rb</a>
18
20
  <a class="source" href="cli.html">cli.rb</a>
@@ -20,6 +22,7 @@
20
22
  <a class="source" href="deploy.html">deploy.rb</a>
21
23
  <a class="source" href="env.html">env.rb</a>
22
24
  <a class="source" href="foreman.html">foreman.rb</a>
25
+ <a class="source" href="namespace.html">namespace.rb</a>
23
26
  <a class="source" href="preflight.html">preflight.rb</a>
24
27
  <a class="source" href="rails.html">rails.rb</a>
25
28
  <a class="source" href="version.html">version.rb</a>