recap 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/.gitignore +2 -1
  2. data/README.md +55 -10
  3. data/Rakefile +19 -5
  4. data/bin/recap +2 -2
  5. data/features/managing-processes.feature +1 -1
  6. data/features/setting-environment-variables.feature +26 -1
  7. data/features/steps/capistrano_steps.rb +10 -6
  8. data/features/support/project.rb +24 -5
  9. data/features/templates/project/Capfile.erb +1 -1
  10. data/lib/recap/recipes/rails.rb +6 -0
  11. data/lib/recap/recipes/ruby.rb +11 -0
  12. data/lib/recap/recipes/static.rb +3 -0
  13. data/lib/recap/recipes.rb +18 -0
  14. data/lib/recap/support/capistrano_extensions.rb +85 -0
  15. data/lib/recap/support/cli.rb +57 -0
  16. data/lib/recap/{compatibility.rb → support/compatibility.rb} +2 -2
  17. data/lib/recap/support/environment.rb +61 -0
  18. data/lib/recap/support/namespace.rb +47 -0
  19. data/lib/recap/support/shell_command.rb +35 -0
  20. data/lib/recap/support/templates/Capfile.erb +6 -0
  21. data/lib/recap/tasks/bootstrap.rb +77 -0
  22. data/lib/recap/{bundler.rb → tasks/bundler.rb} +15 -6
  23. data/lib/recap/{deploy.rb → tasks/deploy.rb} +30 -17
  24. data/lib/recap/tasks/env.rb +111 -0
  25. data/lib/recap/{foreman.rb → tasks/foreman.rb} +20 -12
  26. data/lib/recap/{preflight.rb → tasks/preflight.rb} +13 -11
  27. data/lib/recap/tasks/rails.rb +42 -0
  28. data/lib/recap/tasks.rb +16 -0
  29. data/lib/recap/version.rb +1 -1
  30. data/lib/recap.rb +119 -10
  31. data/recap.gemspec +3 -2
  32. data/spec/models/capistrano_extensions_spec.rb +41 -0
  33. data/spec/models/cli_spec.rb +25 -0
  34. data/spec/models/environment_spec.rb +14 -14
  35. data/spec/models/shell_command_spec.rb +55 -0
  36. data/spec/spec_helper.rb +1 -1
  37. data/spec/tasks/bootstrap_spec.rb +9 -13
  38. data/spec/tasks/bundler_spec.rb +39 -7
  39. data/spec/tasks/deploy_spec.rb +42 -26
  40. data/spec/tasks/env_spec.rb +81 -5
  41. data/spec/tasks/foreman_spec.rb +10 -5
  42. data/spec/tasks/rails_spec.rb +80 -0
  43. metadata +65 -57
  44. data/doc/index.html +0 -235
  45. data/doc/lib/recap/bootstrap.html +0 -42
  46. data/doc/lib/recap/bundler.html +0 -168
  47. data/doc/lib/recap/capistrano_extensions.html +0 -208
  48. data/doc/lib/recap/cli.html +0 -42
  49. data/doc/lib/recap/compatibility.html +0 -73
  50. data/doc/lib/recap/deploy.html +0 -328
  51. data/doc/lib/recap/env.html +0 -108
  52. data/doc/lib/recap/foreman.html +0 -42
  53. data/doc/lib/recap/namespace.html +0 -42
  54. data/doc/lib/recap/preflight.html +0 -163
  55. data/doc/lib/recap/rails.html +0 -42
  56. data/doc/lib/recap/version.html +0 -42
  57. data/doc/lib/recap.html +0 -42
  58. data/index.rb +0 -62
  59. data/lib/recap/bootstrap.rb +0 -47
  60. data/lib/recap/capistrano_extensions.rb +0 -74
  61. data/lib/recap/cli.rb +0 -32
  62. data/lib/recap/deploy/templates/Capfile.erb +0 -6
  63. data/lib/recap/env.rb +0 -58
  64. data/lib/recap/environment.rb +0 -54
  65. data/lib/recap/namespace.rb +0 -37
  66. data/lib/recap/rails.rb +0 -24
  67. data/lib/recap/ruby.rb +0 -3
  68. data/lib/recap/static.rb +0 -1
@@ -1,208 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
- <title>capistrano_extensions.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="../recap.html">recap.rb</a>
17
- <a class="source" href="bootstrap.html">bootstrap.rb</a>
18
- <a class="source" href="bundler.html">bundler.rb</a>
19
- <a class="source" href="capistrano_extensions.html">capistrano_extensions.rb</a>
20
- <a class="source" href="cli.html">cli.rb</a>
21
- <a class="source" href="compatibility.html">compatibility.rb</a>
22
- <a class="source" href="deploy.html">deploy.rb</a>
23
- <a class="source" href="env.html">env.rb</a>
24
- <a class="source" href="foreman.html">foreman.rb</a>
25
- <a class="source" href="namespace.html">namespace.rb</a>
26
- <a class="source" href="preflight.html">preflight.rb</a>
27
- <a class="source" href="rails.html">rails.rb</a>
28
- <a class="source" href="version.html">version.rb</a>
29
- </div>
30
- </div>
31
- </div>
32
- <table cellspacing=0 cellpadding=0>
33
- <thead>
34
- <tr>
35
- <th class=docs><h1>capistrano_extensions.rb</h1></th>
36
- <th class=code></th>
37
- </tr>
38
- </thead>
39
- <tbody>
40
- <tr id='section-1'>
41
- <td class=docs>
42
- <div class="pilwrap">
43
- <a class="pilcrow" href="#section-1">&#182;</a>
44
- </div>
45
-
46
- </td>
47
- <td class=code>
48
- <div class='highlight'><pre><span class="nb">require</span> <span class="s1">&#39;tempfile&#39;</span>
49
-
50
- <span class="k">module</span> <span class="nn">Recap</span>
51
- <span class="k">module</span> <span class="nn">CapistranoExtensions</span></pre></div>
52
- </td>
53
- </tr>
54
- <tr id='section-2'>
55
- <td class=docs>
56
- <div class="pilwrap">
57
- <a class="pilcrow" href="#section-2">&#182;</a>
58
- </div>
59
- <p>Run a command as the given user</p>
60
- </td>
61
- <td class=code>
62
- <div class='highlight'><pre> <span class="k">def</span> <span class="nf">as_user</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="n">command</span><span class="p">,</span> <span class="n">pwd</span> <span class="o">=</span> <span class="n">deploy_to</span><span class="p">)</span>
63
- <span class="n">sudo</span> <span class="s2">&quot;su - </span><span class="si">#{</span><span class="n">user</span><span class="si">}</span><span class="s2"> -c &#39;cd </span><span class="si">#{</span><span class="n">pwd</span><span class="si">}</span><span class="s2"> &amp;&amp; </span><span class="si">#{</span><span class="n">command</span><span class="si">}</span><span class="s2">&#39;&quot;</span>
64
- <span class="k">end</span></pre></div>
65
- </td>
66
- </tr>
67
- <tr id='section-3'>
68
- <td class=docs>
69
- <div class="pilwrap">
70
- <a class="pilcrow" href="#section-3">&#182;</a>
71
- </div>
72
- <p>Run a command as root</p>
73
- </td>
74
- <td class=code>
75
- <div class='highlight'><pre> <span class="k">def</span> <span class="nf">as_root</span><span class="p">(</span><span class="n">command</span><span class="p">,</span> <span class="n">pwd</span> <span class="o">=</span> <span class="n">deploy_to</span><span class="p">)</span>
76
- <span class="n">as_user</span> <span class="s1">&#39;root&#39;</span><span class="p">,</span> <span class="n">command</span><span class="p">,</span> <span class="n">pwd</span>
77
- <span class="k">end</span></pre></div>
78
- </td>
79
- </tr>
80
- <tr id='section-4'>
81
- <td class=docs>
82
- <div class="pilwrap">
83
- <a class="pilcrow" href="#section-4">&#182;</a>
84
- </div>
85
- <p>Run a command as the application user</p>
86
- </td>
87
- <td class=code>
88
- <div class='highlight'><pre> <span class="k">def</span> <span class="nf">as_app</span><span class="p">(</span><span class="n">command</span><span class="p">,</span> <span class="n">pwd</span> <span class="o">=</span> <span class="n">deploy_to</span><span class="p">)</span>
89
- <span class="n">as_user</span> <span class="n">application_user</span><span class="p">,</span> <span class="n">command</span><span class="p">,</span> <span class="n">pwd</span>
90
- <span class="k">end</span></pre></div>
91
- </td>
92
- </tr>
93
- <tr id='section-5'>
94
- <td class=docs>
95
- <div class="pilwrap">
96
- <a class="pilcrow" href="#section-5">&#182;</a>
97
- </div>
98
- <p>Put a string into a file as the application user</p>
99
- </td>
100
- <td class=code>
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>
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>
103
- <span class="n">put</span> <span class="n">string</span><span class="p">,</span> <span class="n">path</span>
104
- <span class="k">end</span></pre></div>
105
- </td>
106
- </tr>
107
- <tr id='section-6'>
108
- <td class=docs>
109
- <div class="pilwrap">
110
- <a class="pilcrow" href="#section-6">&#182;</a>
111
- </div>
112
- <p>Edit a file on the remote server, using a local editor</p>
113
- </td>
114
- <td class=code>
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>
125
- <span class="k">end</span></pre></div>
126
- </td>
127
- </tr>
128
- <tr id='section-7'>
129
- <td class=docs>
130
- <div class="pilwrap">
131
- <a class="pilcrow" href="#section-7">&#182;</a>
132
- </div>
133
- <p>Run a git command in the <code>deploy_to</code> directory</p>
134
- </td>
135
- <td class=code>
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>
138
- <span class="k">end</span></pre></div>
139
- </td>
140
- </tr>
141
- <tr id='section-8'>
142
- <td class=docs>
143
- <div class="pilwrap">
144
- <a class="pilcrow" href="#section-8">&#182;</a>
145
- </div>
146
- <p>Capture the result of a git command run within the <code>deploy_to</code> directory</p>
147
- </td>
148
- <td class=code>
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>
155
- <span class="k">end</span></pre></div>
156
- </td>
157
- </tr>
158
- <tr id='section-9'>
159
- <td class=docs>
160
- <div class="pilwrap">
161
- <a class="pilcrow" href="#section-9">&#182;</a>
162
- </div>
163
- <p>Find the latest tag from the repository. As <code>git tag</code> returns tags in order, and our release
164
- tags are timestamps, the latest tag will always be the last in the list.</p>
165
- </td>
166
- <td class=code>
167
- <div class='highlight'><pre> <span class="k">def</span> <span class="nf">latest_tag_from_repository</span>
168
- <span class="n">result</span> <span class="o">=</span> <span class="n">capture_git</span><span class="p">(</span><span class="s2">&quot;tag | tail -n1&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span>
169
- <span class="n">result</span><span class="o">.</span><span class="n">empty?</span> <span class="p">?</span> <span class="kp">nil</span> <span class="p">:</span> <span class="n">result</span>
170
- <span class="k">end</span></pre></div>
171
- </td>
172
- </tr>
173
- <tr id='section-10'>
174
- <td class=docs>
175
- <div class="pilwrap">
176
- <a class="pilcrow" href="#section-10">&#182;</a>
177
- </div>
178
- <p>Does the given file exist within the deployment directory?</p>
179
- </td>
180
- <td class=code>
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>
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>
183
- <span class="k">end</span></pre></div>
184
- </td>
185
- </tr>
186
- <tr id='section-11'>
187
- <td class=docs>
188
- <div class="pilwrap">
189
- <a class="pilcrow" href="#section-11">&#182;</a>
190
- </div>
191
- <p>Has the given path been created or changed since the previous deployment? During the first
192
- successful deployment this will always return true.</p>
193
-
194
- </td>
195
- <td class=code>
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>
197
- <span class="k">return</span> <span class="kp">true</span> <span class="k">unless</span> <span class="n">latest_tag</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>
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>
202
- <span class="k">end</span>
203
- <span class="k">end</span></pre></div>
204
- </td>
205
- </tr>
206
- </table>
207
- </div>
208
- </body>
@@ -1,42 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
- <title>cli.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="../recap.html">recap.rb</a>
17
- <a class="source" href="bootstrap.html">bootstrap.rb</a>
18
- <a class="source" href="bundler.html">bundler.rb</a>
19
- <a class="source" href="capistrano_extensions.html">capistrano_extensions.rb</a>
20
- <a class="source" href="cli.html">cli.rb</a>
21
- <a class="source" href="compatibility.html">compatibility.rb</a>
22
- <a class="source" href="deploy.html">deploy.rb</a>
23
- <a class="source" href="env.html">env.rb</a>
24
- <a class="source" href="foreman.html">foreman.rb</a>
25
- <a class="source" href="namespace.html">namespace.rb</a>
26
- <a class="source" href="preflight.html">preflight.rb</a>
27
- <a class="source" href="rails.html">rails.rb</a>
28
- <a class="source" href="version.html">version.rb</a>
29
- </div>
30
- </div>
31
- </div>
32
- <table cellspacing=0 cellpadding=0>
33
- <thead>
34
- <tr>
35
- <th class=docs><h1>cli.rb</h1></th>
36
- <th class=code></th>
37
- </tr>
38
- </thead>
39
- <tbody>
40
- </table>
41
- </div>
42
- </body>
@@ -1,73 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
- <title>compatibility.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="../recap.html">recap.rb</a>
17
- <a class="source" href="bootstrap.html">bootstrap.rb</a>
18
- <a class="source" href="bundler.html">bundler.rb</a>
19
- <a class="source" href="capistrano_extensions.html">capistrano_extensions.rb</a>
20
- <a class="source" href="cli.html">cli.rb</a>
21
- <a class="source" href="compatibility.html">compatibility.rb</a>
22
- <a class="source" href="deploy.html">deploy.rb</a>
23
- <a class="source" href="env.html">env.rb</a>
24
- <a class="source" href="foreman.html">foreman.rb</a>
25
- <a class="source" href="namespace.html">namespace.rb</a>
26
- <a class="source" href="preflight.html">preflight.rb</a>
27
- <a class="source" href="rails.html">rails.rb</a>
28
- <a class="source" href="version.html">version.rb</a>
29
- </div>
30
- </div>
31
- </div>
32
- <table cellspacing=0 cellpadding=0>
33
- <thead>
34
- <tr>
35
- <th class=docs><h1>compatibility.rb</h1></th>
36
- <th class=code></th>
37
- </tr>
38
- </thead>
39
- <tbody>
40
- <tr id='section-1'>
41
- <td class=docs>
42
- <div class="pilwrap">
43
- <a class="pilcrow" href="#section-1">&#182;</a>
44
- </div>
45
- <p><code>recap</code> isn&rsquo;t intended to be compatible with tasks (such as those within the <code>bundler</code>
46
- or <code>whenever</code> projects) that are built on the original capistrano deployment recipes. At times
47
- though there are tasks that would work, but for some missing (and redundant) settings.</p>
48
-
49
- <p>Including this recipe adds these legacy settings, but provides no guarantee that original tasks
50
- will work. Many are based on assumptions about the deployment layout that no longer hold true.</p>
51
- </td>
52
- <td class=code>
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>
55
- </td>
56
- </tr>
57
- <tr id='section-2'>
58
- <td class=docs>
59
- <div class="pilwrap">
60
- <a class="pilcrow" href="#section-2">&#182;</a>
61
- </div>
62
- <p>As <code>git</code> to manages releases, all deployments are placed directly in the <code>deploy_to</code> folder. The
63
- <code>current_path</code> is always this directory (no symlinking required).</p>
64
-
65
- </td>
66
- <td class=code>
67
- <div class='highlight'><pre> <span class="n">set</span><span class="p">(</span><span class="ss">:current_path</span><span class="p">)</span> <span class="p">{</span> <span class="n">deploy_to</span> <span class="p">}</span>
68
- <span class="k">end</span></pre></div>
69
- </td>
70
- </tr>
71
- </table>
72
- </div>
73
- </body>