colorful-mina 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +21 -0
  5. data/CONTRIBUTING.md +124 -0
  6. data/Gemfile +10 -0
  7. data/HISTORY.md +348 -0
  8. data/LICENSE +23 -0
  9. data/Makefile +29 -0
  10. data/Notes.md +70 -0
  11. data/README.md +1015 -0
  12. data/Rakefile +20 -0
  13. data/bin/mina +65 -0
  14. data/data/deploy.rb +80 -0
  15. data/data/deploy.sh.erb +106 -0
  16. data/lib/mina.rb +23 -0
  17. data/lib/mina/bundler.rb +49 -0
  18. data/lib/mina/chruby.rb +49 -0
  19. data/lib/mina/default.rb +145 -0
  20. data/lib/mina/deploy.rb +138 -0
  21. data/lib/mina/deploy_helpers.rb +34 -0
  22. data/lib/mina/exec_helpers.rb +111 -0
  23. data/lib/mina/foreman.rb +82 -0
  24. data/lib/mina/git.rb +62 -0
  25. data/lib/mina/helpers.rb +386 -0
  26. data/lib/mina/output_helpers.rb +95 -0
  27. data/lib/mina/rails.rb +206 -0
  28. data/lib/mina/rake.rb +9 -0
  29. data/lib/mina/rbenv.rb +47 -0
  30. data/lib/mina/rvm.rb +88 -0
  31. data/lib/mina/settings.rb +32 -0
  32. data/lib/mina/ssh_helpers.rb +123 -0
  33. data/lib/mina/tools.rb +20 -0
  34. data/lib/mina/version.rb +5 -0
  35. data/lib/mina/whenever.rb +27 -0
  36. data/manual/index.md +15 -0
  37. data/manual/modules.md +2 -0
  38. data/mina.gemspec +17 -0
  39. data/spec/command_helper.rb +52 -0
  40. data/spec/commands/cleanup_spec.rb +16 -0
  41. data/spec/commands/command_spec.rb +71 -0
  42. data/spec/commands/custom_config_spec.rb +20 -0
  43. data/spec/commands/deploy_spec.rb +36 -0
  44. data/spec/commands/outside_project_spec.rb +35 -0
  45. data/spec/commands/real_deploy_spec.rb +53 -0
  46. data/spec/commands/ssh_spec.rb +14 -0
  47. data/spec/commands/verbose_spec.rb +21 -0
  48. data/spec/dsl/invoke_spec.rb +48 -0
  49. data/spec/dsl/queue_spec.rb +49 -0
  50. data/spec/dsl/settings_in_rake_spec.rb +39 -0
  51. data/spec/dsl/settings_spec.rb +61 -0
  52. data/spec/dsl/to_spec.rb +20 -0
  53. data/spec/fixtures/custom_file_env/custom_deploy.rb +15 -0
  54. data/spec/fixtures/empty_env/config/deploy.rb +15 -0
  55. data/spec/helpers/exec_helper_spec.rb +19 -0
  56. data/spec/helpers/output_helper_spec.rb +24 -0
  57. data/spec/spec_helper.rb +27 -0
  58. data/support/Readme-footer.md +32 -0
  59. data/support/Readme-header.md +16 -0
  60. data/support/guide.md +297 -0
  61. data/support/index.html +53 -0
  62. data/support/to_md.rb +11 -0
  63. data/test_env/config/deploy.rb +69 -0
  64. metadata +150 -0
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ LICENSE
2
+
3
+ The MIT License
4
+
5
+ Copyright (c) 2014 Nadarei, Inc.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
data/Makefile ADDED
@@ -0,0 +1,29 @@
1
+ Readme.md: \
2
+ support/Readme-header.md \
3
+ support/guide.md \
4
+ support/helpers.md \
5
+ support/modules.md \
6
+ support/Readme-footer.md
7
+ cat $^ > $@
8
+
9
+ support/modules.md: \
10
+ lib/mina/bundler.rb \
11
+ lib/mina/default.rb \
12
+ lib/mina/deploy.rb \
13
+ lib/mina/foreman.rb \
14
+ lib/mina/git.rb \
15
+ lib/mina/rails.rb \
16
+ lib/mina/rbenv.rb \
17
+ lib/mina/rvm.rb \
18
+ lib/mina/whenever.rb
19
+ cat $^ | ruby support/to_md.rb > $@
20
+
21
+ support/helpers.md: \
22
+ lib/mina/helpers.rb \
23
+ lib/mina/deploy_helpers.rb
24
+ cat $^ | ruby support/to_md.rb > $@
25
+
26
+ clean:
27
+ rm Readme.md support/modules.md support/helpers.md
28
+
29
+ .PHONY: clean
data/Notes.md ADDED
@@ -0,0 +1,70 @@
1
+ Readme
2
+ ------
3
+
4
+ The readme file is auto-generated using make.
5
+
6
+ $ make Readme.md
7
+
8
+ Documentation
9
+ -------------
10
+
11
+ Please consult the [project documentation](http://mina-deploy.github.io/mina) for full
12
+ details.
13
+
14
+ Problems or suggestions? File issues at the [issue tracker][issues].
15
+
16
+ Documentation sources
17
+ ---------------------
18
+
19
+ See [mina-deploy/mina-docs](https://github.com/mina-deploy/mina-docs) for the sources of
20
+ the documentation site. Please ensure that docs there are in sync with the
21
+ features here.
22
+
23
+ Development & testing
24
+ ---------------------
25
+
26
+ To test out stuff in development:
27
+
28
+ ``` sh
29
+ # Run specs
30
+ $ rspec
31
+ $ rspec -t ssh # Run SSH tests (read test_env/config/deploy.rb first)
32
+ $ rake=10 rspec
33
+ $ rake=0.9 rspec
34
+ $ rake=0.8 rspec
35
+
36
+ # Alias your 'mina' to use it everywhere
37
+ $ alias mina="`pwd -LP`/bin/mina"
38
+ ```
39
+
40
+ ### Doing test deploys
41
+
42
+ Try out the test environment:
43
+
44
+ ``` sh
45
+ $ cd test_env
46
+ $ mina deploy --simulate
47
+ $ mina deploy
48
+
49
+ # There's an rspec task for it too
50
+ $ rspec -t ssh
51
+ ```
52
+
53
+ ### Gem management
54
+
55
+ ``` sh
56
+ # To release the gem:
57
+ # Install the Git changelog helper: https://gist.github.com/2880525
58
+ # Then:
59
+
60
+ $ vim lib/mina/version.rb
61
+ $ git clog -w
62
+ $ vim HISTORY.md
63
+ $ git commit -m "Release v0.8.4."
64
+ $ rake release
65
+
66
+ # Please don't forget to tag the release in github.com/nadarei/mina-docs too!
67
+
68
+ $ rake build # Builds the gem file
69
+ $ rake install # Installs the gem locally
70
+ ```
data/README.md ADDED
@@ -0,0 +1,1015 @@
1
+ # Colorful Mina
2
+
3
+ Really fast deployer and server automation tool.
4
+
5
+ Mina works really fast because it's a deploy Bash script generator. It
6
+ generates an entire procedure as a Bash script and runs it remotely in the
7
+ server.
8
+
9
+ Compare this to the likes of Vlad or Capistrano, where each command
10
+ is run separately on their own SSH sessions. Mina only creates *one* SSH
11
+ session per deploy, minimizing the SSH connection overhead.
12
+
13
+ $ gem install mina
14
+ $ mina
15
+
16
+ [![Build Status](https://travis-ci.org/wevtimoteo/colorful-mina.svg?branch=master)](https://travis-ci.org/wevtimoteo/colorful-mina) [![Gem Version](https://badge.fury.io/rb/mina.svg)](http://badge.fury.io/rb/mina)
17
+
18
+ ## About Colorful Mina
19
+
20
+ This fork uses `print_str` method already implemented all over `mina-deploy/mina` repository.
21
+
22
+ The rest of features remain the same.
23
+
24
+ User guide
25
+ ==========
26
+
27
+ Setting up a project
28
+ --------------------
29
+
30
+ Let's deploy a project using Mina.
31
+
32
+ ### Step 1: Create a config/deploy.rb
33
+
34
+ In your project, type `mina init` to create a sample of this file.
35
+
36
+ $ mina init
37
+ Created config/deploy.rb.
38
+
39
+ This is just a Rake file with tasks! See [About deploy.rb](#about-deployrb) for
40
+ more info on what *deploy.rb* is. You will want to at least configure your
41
+ server:
42
+
43
+ ~~~ ruby
44
+ # config/deploy.rb
45
+ set :user, 'username'
46
+ set :domain, 'your.server.com'
47
+ set :deploy_to, '/var/www/flipstack.com'
48
+ ...
49
+ ~~~
50
+
51
+ ### Step 2: Set up your server
52
+
53
+ Make a directory in your server called `/var/www/flipstack.com` (in *deploy_to*)
54
+ change it's ownership to the correct user.
55
+
56
+ $ ssh username@your.server.com
57
+
58
+ # Once in your server, create the deploy folder:
59
+ ~@your.server.com$ mkdir /var/www/flipstack.com
60
+ ~@your.server.com$ chown -R username /var/www/flipstack.com
61
+
62
+ ### Step 3: Run 'mina setup'
63
+
64
+ Back at your computer, do `mina setup` to set up the [folder
65
+ structure](#directory_structure) in this path. This will connect to your server
66
+ via SSH and create the right directories.
67
+
68
+ $ mina setup
69
+ -----> Creating folders... done.
70
+
71
+ See [directory structure](#directory-structure) for more info.
72
+
73
+ ### Step 4: Deploy!
74
+
75
+ Use `mina deploy` to run the `deploy` task defined in *config/deploy.rb*.
76
+
77
+ $ mina deploy
78
+ -----> Deploying to 2012-06-12-040248
79
+ ...
80
+ Lots of things happening...
81
+ ...
82
+ -----> Done.
83
+
84
+ About deploy.rb
85
+ ---------------
86
+
87
+ The file `deploy.rb` is simply a Rakefile invoked by Rake. In fact, `mina` is
88
+ mostly an alias that invokes Rake to load `deploy.rb`.
89
+
90
+ ~~~ ruby
91
+ # Sample config/deploy.rb
92
+ set :domain, 'your.server.com'
93
+
94
+ task :restart do
95
+ queue 'sudo service restart apache'
96
+ end
97
+ ~~~
98
+
99
+ As it's all Rake, you can define tasks that you can invoke using `mina`. In this
100
+ example, it provides the `mina restart` command.
101
+
102
+ The magic of Mina is in the new commands it gives you.
103
+
104
+ The `queue` command queues up Bash commands to be run on the remote server.
105
+ If you invoke `mina restart`, it will invoke the task above and run the queued
106
+ commands on the remote server `your.server.com` via SSH.
107
+
108
+ See [the command queue](#the-command-queue) for more information on the *queue*
109
+ command.
110
+
111
+ The command queue
112
+ -----------------
113
+
114
+ At the heart of it, Mina is merely sugar on top of Rake to queue commands
115
+ and execute them remotely at the end. Take a look at this minimal *deploy.rb*
116
+ configuration:
117
+
118
+ ~~~ ruby
119
+ # config/deploy.rb
120
+ set :user, 'john'
121
+ set :domain, 'flipstack.com'
122
+
123
+ task :logs do
124
+ queue print_str('Contents of the log file are as follows:')
125
+ queue "tail -f /var/log/apache.log"
126
+ end
127
+ ~~~
128
+
129
+ Once you type `mina logs` in your terminal, it invokes the *queue*d commands
130
+ remotely on the server using the command `ssh john@flipstack.com`.
131
+
132
+ ~~~ sh
133
+ $ mina logs --simulate
134
+ # Execute the following commands via
135
+ # ssh john@flipstack.com:
136
+ #
137
+ echo "Contents of the log file are as follows:"
138
+ tail -f /var/log/apache.log
139
+ ~~~
140
+
141
+ Subtasks
142
+ --------
143
+
144
+ Mina provides the helper `invoke` to invoke other tasks from a
145
+ task.
146
+
147
+ ~~~ ruby
148
+ # config/deploy.rb
149
+ task :down do
150
+ invoke :maintenance_on
151
+ invoke :restart
152
+ end
153
+
154
+ task :maintenance_on
155
+ queue 'touch maintenance.txt'
156
+ end
157
+
158
+ task :restart
159
+ queue 'sudo service restart apache'
160
+ end
161
+ ~~~
162
+
163
+ In this example above, if you type `mina down`, it simply invokes the other
164
+ subtasks which queues up their commands. The commands will be run after
165
+ everything.
166
+
167
+ Directory structure
168
+ -------------------
169
+
170
+ The deploy procedures make the assumption that you have a folder like so:
171
+
172
+ /var/www/flipstack.com/ # The deploy_to path
173
+ |- releases/ # Holds releases, one subdir per release
174
+ | |- 1/
175
+ | |- 2/
176
+ | |- 3/
177
+ | '- ...
178
+ |- shared/ # Holds files shared between releases
179
+ | |- logs/ # Log files are usually stored here
180
+ | `- ...
181
+ '- current/ # A symlink to the current release in releases/
182
+
183
+ It also assumes that the `deploy_to` path is fully writeable/readable for the
184
+ user we're going to SSH with.
185
+
186
+ Deploying
187
+ ---------
188
+
189
+ Mina provides the `deploy` command which *queue*s up a deploy script for
190
+ you.
191
+
192
+ ~~~ ruby
193
+ # config/deploy.rb
194
+ set :domain, 'flipstack.com'
195
+ set :user, 'flipstack'
196
+ set :deploy_to, '/var/www/flipstack.com'
197
+ set :repository, 'http://github.com/flipstack/flipstack.git'
198
+
199
+ task :deploy do
200
+ deploy do
201
+ # Put things that prepare the empty release folder here.
202
+ # Commands queued here will be run on a new release directory.
203
+ invoke :'git:clone'
204
+ invoke :'bundle:install'
205
+
206
+ # These are instructions to start the app after it's been prepared.
207
+ to :launch do
208
+ queue "mkdir -p #{deploy_to}/#{current_path}/tmp/"
209
+ queue "touch #{deploy_to}/#{current_path}/tmp/restart.txt"
210
+ end
211
+
212
+ # This optional block defines how a broken release should be cleaned up.
213
+ to :clean do
214
+ queue 'log "failed deployment"'
215
+ end
216
+ end
217
+ end
218
+ ~~~
219
+
220
+ It works by capturing the *queue*d commands inside the block, wrapping them
221
+ in a deploy script, then *queue*ing them back in.
222
+
223
+ ### How deploying works
224
+
225
+ Here is an example of a deploy! (Note that some commands have been simplified
226
+ to illustrate the point better.)
227
+
228
+ ### Step 1: Build it
229
+
230
+ The deploy process builds a new temp folder with instructions you provide.
231
+ In this example, it will do `git:clone` and `bundle:install`.
232
+
233
+ $ mina deploy --verbose
234
+ -----> Creating the build path
235
+ $ mkdir tmp/build-128293482394
236
+ -----> Cloning the Git repository
237
+ $ git clone https://github.com/flipstack/flipstack.git . -n --recursive
238
+ Cloning... done.
239
+ -----> Installing gem dependencies using Bundler
240
+ $ bundle install --without development:test
241
+ Using i18n (0.6.0)
242
+ Using multi_json (1.0.4)
243
+ ...
244
+ Your bundle is complete! It was installed to ./vendor/bundle
245
+
246
+ ### Step 2: Move it to releases
247
+
248
+ Once the project has been built, it will be moved to `releases/`. A symlink
249
+ called `current/` will be created to point to the active release.
250
+
251
+ $
252
+ -----> Moving to releases/4
253
+ $ mv "./tmp/build-128293482394" "releases/4"
254
+ -----> Symlinking to current
255
+ $ ln -nfs releases/4 current
256
+
257
+ ### Step 3: Launch it
258
+
259
+ Invoke the commands queued up in the `to :launch` block. These often
260
+ commands to restart the webserver process. Once this in complete, you're done!
261
+
262
+ $
263
+ -----> Launching
264
+ $ cd releases/4
265
+ $ sudo service nginx restart
266
+ -----> Done. Deployed v4
267
+
268
+ ### What about failure?
269
+
270
+ If it fails at any point, the release path will be deleted. If any commands are
271
+ queued using the `to :clean` block, they will be run. It will be as if nothing
272
+ happened. Lets see what happens if a build fails:
273
+
274
+ $
275
+ -----> Launching
276
+ $ cd releases/4
277
+ $ sudo service nginx restart
278
+ Starting nginx... error: can't start service
279
+ -----> ERROR: Deploy failed.
280
+ -----> Cleaning up build
281
+ $ rm -rf tmp/build-128293482394
282
+ -----> Unlinking current
283
+ $ ln -nfs releases/3 current
284
+ OK
285
+
286
+ Command line options
287
+ --------------------
288
+
289
+ Basic usage:
290
+
291
+ $ mina [OPTIONS] [TASKS] [VAR1=val VAR2=val ...]
292
+
293
+ ### Options
294
+
295
+ * `-v` / `--verbose` - This will show commands being done on the server. Off by
296
+ default.
297
+
298
+ * `-S` / `--simulate` - This will not invoke any SSH connections; instead, it
299
+ will simply output the script it builds.
300
+
301
+ * `-t` / `--trace` - Show backtraces when errors occur.
302
+
303
+ * `-f FILE` - Use a custom deploy.rb configuration.
304
+
305
+ * `-V` / `--version` - Shows the current version.
306
+
307
+ ### Tasks
308
+
309
+ There are many tasks available. See the [tasks reference](http://mina-deploy.github.io/mina/tasks/index.html), or
310
+ type `mina tasks`.
311
+
312
+ ### Variables
313
+
314
+ You may specify additional variables in the `KEY=value` style, just like Rake.
315
+ You can add as many variables as needed.
316
+
317
+ $ mina restart on=staging
318
+
319
+ # This sets the ENV['on'] variable to 'staging'.
320
+
321
+
322
+ # Helpers
323
+
324
+ ### invoke
325
+ Invokes another Rake task. By default if the task has already been invoked it will not been executed again (see the `:reenable` option).
326
+
327
+ Invokes the task given in `task`. Returns nothing.
328
+
329
+ ~~~ ruby
330
+ invoke :'git:clone'
331
+ invoke :restart
332
+ ~~~
333
+
334
+ __Options:__
335
+ `:reenable` (bool) - Execute the task even next time. Defaults to `false`
336
+
337
+ ### erb
338
+ Evaluates an ERB block in the current scope and returns a string.
339
+
340
+ ~~~ ruby
341
+ a = 1
342
+ b = 2
343
+ # Assuming foo.erb is <%= a %> and <%= b %>
344
+ puts erb('foo.erb')
345
+ #=> "1 and 2"
346
+ ~~~
347
+
348
+ Returns the output string of the ERB template.
349
+
350
+ ### run!
351
+ SSHs into the host and runs the code that has been queued.
352
+
353
+ This is already automatically invoked before Rake exits to run all
354
+ commands that have been queued up.
355
+
356
+ ~~~ ruby
357
+ queue "sudo restart"
358
+ run!
359
+ ~~~
360
+
361
+ Returns nothing.
362
+
363
+ ### report_time
364
+ Report time elapsed in the block.
365
+ Returns the output of the block.
366
+
367
+ ~~~ ruby
368
+ report_time do
369
+ sleep 2
370
+ # do other things
371
+ end
372
+ # Output:
373
+ # Elapsed time: 2.00 seconds
374
+ ~~~
375
+
376
+ ### measure
377
+ Measures the time (in seconds) a block takes.
378
+ Returns a [time, output] tuple.
379
+
380
+ ### mina_cleanup
381
+ __Internal:__ Invoked when Rake exits.
382
+
383
+ Returns nothing.
384
+
385
+ ## Errors
386
+
387
+ ### die
388
+ Exits with a nice looking message.
389
+ Returns nothing.
390
+
391
+ ~~~ ruby
392
+ die 2
393
+ die 2, "Tests failed"
394
+ ~~~
395
+
396
+ ### error
397
+ __Internal:__ Prints to stdout.
398
+ Consider using `print_error` instead.
399
+
400
+ ## Queueing
401
+
402
+ ### queue
403
+ Queues code to be run.
404
+
405
+ This queues code to be run to the current code bucket (defaults to `:default`).
406
+ To get the things that have been queued, use commands[:default]
407
+
408
+ Returns nothing.
409
+
410
+ ~~~ ruby
411
+ queue "sudo restart"
412
+ queue "true"
413
+ commands == ['sudo restart', 'true']
414
+ ~~~
415
+
416
+ ### queue!
417
+ Shortcut for `queue`ing a command that shows up in verbose mode.
418
+
419
+ ### echo_cmd
420
+ Converts a bash command to a command that echoes before execution.
421
+ Used to show commands in verbose mode. This does nothing unless verbose mode is on.
422
+
423
+ Returns a string of the compound bash command, typically in the format of
424
+ `echo xx && xx`. However, if `verbose_mode?` is false, it returns the
425
+ input string unharmed.
426
+
427
+ ~~~ ruby
428
+ echo_cmd("ln -nfs releases/2 current")
429
+ #=> echo "$ ln -nfs releases/2 current" && ln -nfs releases/2 current
430
+ ~~~
431
+
432
+ ## Commands
433
+
434
+ ### commands
435
+ Returns an array of queued code strings.
436
+
437
+ You may give an optional `aspect`.
438
+
439
+ Returns an array of strings.
440
+
441
+ ~~~ ruby
442
+ queue "sudo restart"
443
+ queue "true"
444
+ to :clean do
445
+ queue "rm"
446
+ end
447
+ commands == ["sudo restart", "true"]
448
+ commands(:clean) == ["rm"]
449
+ ~~~
450
+
451
+ ### isolate
452
+ Starts a new block where new `commands` are collected.
453
+
454
+ Returns nothing.
455
+
456
+ ~~~ ruby
457
+ queue "sudo restart"
458
+ queue "true"
459
+ commands.should == ['sudo restart', 'true']
460
+ isolate do
461
+ queue "reload"
462
+ commands.should == ['reload']
463
+ end
464
+ commands.should == ['sudo restart', 'true']
465
+ ~~~
466
+
467
+ ### in_directory
468
+ Starts a new block where #commands are collected, to be executed inside `path`.
469
+
470
+ Returns nothing.
471
+
472
+ ~~~ ruby
473
+ in_directory './webapp' do
474
+ queue "./reload"
475
+ end
476
+ commands.should == ['cd ./webapp && (./reload && true)']
477
+ ~~~
478
+
479
+ ### to
480
+ Defines instructions on how to do a certain thing.
481
+ This makes the commands that are `queue`d go into a different bucket in commands.
482
+
483
+ Returns nothing.
484
+
485
+ ~~~ ruby
486
+ to :prepare do
487
+ run "bundle install"
488
+ end
489
+ to :launch do
490
+ run "nginx -s restart"
491
+ end
492
+ commands(:prepare) == ["bundle install"]
493
+ commands(:restart) == ["nginx -s restart"]
494
+ ~~~
495
+
496
+ ## Settings helpers
497
+
498
+ ### set
499
+ Sets settings.
500
+ Sets given symbol `key` to value in `value`.
501
+
502
+ Returns the value.
503
+
504
+ ~~~ ruby
505
+ set :domain, 'kickflip.me'
506
+ ~~~
507
+
508
+ ### set_default
509
+ Sets default settings.
510
+ Sets given symbol `key` to value in `value` only if the key isn't set yet.
511
+
512
+ Returns the value.
513
+
514
+ ~~~ ruby
515
+ set_default :term_mode, :pretty
516
+ set :term_mode, :system
517
+ settings.term_mode.should == :system
518
+ set :term_mode, :system
519
+ set_default :term_mode, :pretty
520
+ settings.term_mode.should == :system
521
+ ~~~
522
+
523
+ ### settings
524
+ Accesses the settings hash.
525
+
526
+ ~~~ ruby
527
+ set :domain, 'kickflip.me'
528
+ settings.domain #=> 'kickflip.me'
529
+ domain #=> 'kickflip.me'
530
+ ~~~
531
+
532
+ ### method_missing
533
+ Hook to get settings.
534
+ See #settings for an explanation.
535
+
536
+ Returns things.
537
+
538
+ ## Command line mode helpers
539
+
540
+ ### verbose_mode?
541
+ Checks if Rake was invoked with --verbose.
542
+
543
+ Returns true or false.
544
+
545
+ ~~~ ruby
546
+ if verbose_mode?
547
+ queue %[print_str '-> Starting a new process']
548
+ end
549
+ ~~~
550
+
551
+ ### simulate_mode?
552
+ Checks if Rake was invoked with --simulate.
553
+
554
+ Returns true or false.
555
+
556
+ ## Internal helpers
557
+
558
+ ### indent
559
+ Indents a given code block with `count` spaces before it.
560
+
561
+ ### unindent
562
+ __Internal:__ Normalizes indentation on a given string.
563
+
564
+ Returns the normalized string without extraneous indentation.
565
+
566
+ ~~~ ruby
567
+ puts unindent %{
568
+ Hello
569
+ There
570
+ }
571
+ # Output:
572
+ # Hello
573
+ # There
574
+ ~~~
575
+
576
+ ### reindent
577
+ Resets the indentation on a given code block.
578
+
579
+ ### capture
580
+ Returns the output of command via SSH.
581
+
582
+ # Helpers: Deploy helpers
583
+ Helpers for deployment.
584
+
585
+ ### deploy
586
+ Wraps the things inside it in a deploy script and queues it.
587
+ This generates a script using deploy_script and queues it.
588
+
589
+ Returns nothing.
590
+
591
+ ### deploy_script
592
+ Wraps the things inside it in a deploy script.
593
+
594
+ ~~~ ruby
595
+ script = deploy_script do
596
+ invoke :'git:checkout'
597
+ end
598
+ queue script
599
+ ~~~
600
+
601
+ Returns the deploy script as a string, ready for `queue`ing.
602
+
603
+ # Modules: Bundler
604
+ Adds settings and tasks for managing Ruby Bundler.
605
+
606
+ ~~~ ruby
607
+ require 'mina/bundler'
608
+ ~~~
609
+
610
+ ## Settings
611
+ Any and all of these settings can be overriden in your `deploy.rb`.
612
+
613
+ ### bundle_bin
614
+ Sets the bundle path.
615
+
616
+ ### bundle_path
617
+ Sets the path to where the gems are expected to be.
618
+
619
+ This path will be symlinked to `./shared/bundle` so that the gems cache will
620
+ be shared between all releases.
621
+
622
+ ### bundle_options
623
+ Sets the options for installing gems via Bundler.
624
+
625
+ ## Deploy tasks
626
+ These tasks are meant to be invoked inside deploy scripts, not invoked on
627
+ their own.
628
+
629
+ ### bundle:install
630
+ Installs gems.
631
+
632
+ # Modules: Default
633
+ This module is loaded when invoking `mina` with or without a project.
634
+
635
+ ## Settings
636
+ Here are some of the common settings. All settings are optional unless
637
+ otherwise noted.
638
+
639
+ ### deploy_to
640
+ (Required) Path to deploy to.
641
+
642
+ ### domain
643
+ (Required) Host name to deploy to.
644
+
645
+ ### port
646
+ SSH port number.
647
+
648
+ ### forward_agent
649
+ If set to `true`, enables SSH agent forwarding.
650
+
651
+ ### identity_file
652
+ The local path to the SSH private key file.
653
+
654
+ ### ssh_options
655
+ Switches to be passed to the `ssh` command.
656
+
657
+ ## Tasks
658
+ Any and all of these settings can be overriden in your `deploy.rb`.
659
+
660
+ ### environment
661
+ Make the `:environment` task exist by default. This is meant to be overridden
662
+ by users.
663
+
664
+ ### init
665
+ Initializes a new Mina project.
666
+
667
+ ~~~ ruby
668
+ $ mina init
669
+ ~~~
670
+
671
+ ### help
672
+ Shows the help screen.
673
+
674
+ ### tasks
675
+ Display all tasks in a nice table.
676
+
677
+ ~~~ ruby
678
+ $ mina tasks
679
+ ~~~
680
+
681
+ # Modules: Deployment
682
+ This module is automatically loaded for all Mina projects.
683
+
684
+ ## Settings
685
+ Any and all of these settings can be overriden in your `deploy.rb`.
686
+
687
+ ### releases_path
688
+ (default: 'releases')
689
+
690
+ ### shared_path
691
+ (default: 'shared')
692
+
693
+ ### current_path
694
+ (default: 'current_path')
695
+
696
+ ### lock_file
697
+ Name of the file to generate while a deploy is currently ongoing.
698
+ (default: 'deploy.lock')
699
+
700
+ ### keep_releases
701
+ Number of releases to keep when doing the `deploy:cleanup` task.
702
+ (default: 5)
703
+
704
+ ## Tasks
705
+
706
+ ### deploy:force_unlock
707
+ Forces a deploy unlock by deleting the lock file.
708
+
709
+ ~~~ ruby
710
+ $ mina deploy:force_unlock
711
+ ~~~
712
+
713
+ You can also combine that task with `deploy`:
714
+
715
+ ~~~ ruby
716
+ $ mina deploy:force_unlock deploy
717
+ ~~~
718
+
719
+ ### deploy:link_shared_paths
720
+ Links the shared paths in the `shared_paths` setting.
721
+
722
+ ### deploy:cleanup
723
+ Cleans up old releases.
724
+
725
+ By default, the last 5 releases are kept on each server (though you can
726
+ change this with the keep_releases setting). All other deployed revisions
727
+ are removed from the servers."
728
+
729
+ ### setup
730
+ Sets up a site's directory structure.
731
+
732
+ ### run[]
733
+ Runs a command on a server.
734
+
735
+ ~~~ ruby
736
+ $ mina run[tail -f logs.txt]
737
+ ~~~
738
+
739
+ # Modules: Foreman
740
+ Adds settings and tasks for managing projects with [foreman].
741
+
742
+ NOTE: Requires sudo privileges
743
+
744
+ [foreman]: http://rubygems.org/ddolar/foreman
745
+
746
+ require 'mina/foreman'
747
+
748
+ ## Common usage
749
+
750
+ set :application, "app-name"
751
+
752
+ task :deploy => :environment do
753
+ ~~~ ruby
754
+ deploy do
755
+ # ...
756
+ invoke 'foreman:export'
757
+ # ...
758
+ end
759
+ to :launch do
760
+ invoke 'foreman:restart'
761
+ end
762
+ ~~~
763
+
764
+ end
765
+
766
+ ## Settings
767
+ Any and all of these settings can be overriden in your `deploy.rb`.
768
+
769
+ ### foreman_app
770
+ Sets the service name that foreman will export to upstart. Uses *application*
771
+ variable as a default. It should be set, otherwise export command will fail.
772
+
773
+ ### foreman_user
774
+ Sets the user under which foreman will execute the service. Defaults to *user*
775
+
776
+ ### foreman_log
777
+ Sets the foreman log path. Defaults to *shared/log*
778
+
779
+ encoding: utf-8
780
+
781
+ # Modules: Git
782
+ Adds settings and tasks related to managing Git.
783
+
784
+ ~~~ ruby
785
+ require 'mina/git'
786
+ ~~~
787
+
788
+ ## Settings
789
+ Any and all of these settings can be overriden in your `deploy.rb`.
790
+
791
+ ### branch
792
+ Sets the branch to be deployed.
793
+
794
+ ## Deploy tasks
795
+ These tasks are meant to be invoked inside deploy scripts, not invoked on
796
+ their own.
797
+
798
+ ### git:clone
799
+ Clones the Git repository. Meant to be used inside a deploy script.
800
+
801
+ # Modules: Rails
802
+ Adds settings and tasks for managing Rails projects.
803
+
804
+ ~~~ ruby
805
+ require 'mina/rails'
806
+ ~~~
807
+
808
+ ## Settings
809
+ Any and all of these settings can be overriden in your `deploy.rb`.
810
+
811
+ ### rails_env
812
+ Sets the Rails environment for `rake` and `rails` commands.
813
+
814
+ Note that changing this will NOT change the environment that your application
815
+ is run in.
816
+
817
+ ### bundle_prefix
818
+ Prefix for Bundler commands. Often to something like `RAILS_ENV=production
819
+ bundle exec`.
820
+
821
+ ~~~ ruby
822
+ queue! "#{bundle_prefix} annotate -r"
823
+ ~~~
824
+
825
+ ### rake
826
+ The prefix for `rake` commands. Use like so:
827
+
828
+ ~~~ ruby
829
+ queue! "#{rake} db:migrate"
830
+ ~~~
831
+
832
+ ### rails
833
+ The prefix for `rails` commands. Use like so:
834
+
835
+ ~~~ ruby
836
+ queue! "#{rails} console"
837
+ ~~~
838
+
839
+ ### asset_paths
840
+ The paths to be checked.
841
+
842
+ Whenever assets are compiled, the asset files are checked if they have
843
+ changed from the previous release.
844
+
845
+ If they're unchanged, compiled assets will simply be copied over to the new
846
+ release.
847
+
848
+ Override this if you have custom asset paths declared in your Rails's
849
+ `config.assets.paths` setting.
850
+
851
+ ### rake_assets_precompile
852
+ The command to invoke when precompiling assets.
853
+ Override me if you like.
854
+
855
+ ----
856
+
857
+ Macro used later by :rails, :rake, etc
858
+
859
+ ## Command-line tasks
860
+ These tasks can be invoked in the command line.
861
+
862
+ ### rails[]
863
+ Invokes a rails command.
864
+
865
+ ~~~ ruby
866
+ $ mina rails[console]
867
+ ~~~
868
+
869
+ ### rake[]
870
+ Invokes a rake command.
871
+
872
+ ~~~ ruby
873
+ $ mina rake db:cleanup
874
+ ~~~
875
+
876
+ ### console
877
+ Opens the Ruby console for the currently-deployed version.
878
+
879
+ ~~~ ruby
880
+ $ mina console
881
+ ~~~
882
+
883
+ ## Deploy tasks
884
+ These tasks are meant to be invoked inside deploy scripts, not invoked on
885
+ their own.
886
+
887
+ ### rails:db_migrate
888
+
889
+ ### rails:db_migrate:force
890
+
891
+ ### rails:assets_precompile:force
892
+
893
+ ### rails:assets_precompile
894
+
895
+ # Modules: rbenv
896
+ Adds settings and tasks for managing [rbenv] installations.
897
+
898
+ [rbenv]: https://github.com/sstephenson/rbenv
899
+
900
+ ~~~ ruby
901
+ require 'mina/rbenv'
902
+ ~~~
903
+
904
+ ## Common usage
905
+
906
+ ~~~ ruby
907
+ task :environment do
908
+ invoke :'rbenv:load'
909
+ end
910
+ task :deploy => :environment do
911
+ ...
912
+ end
913
+ ~~~
914
+
915
+ ## Settings
916
+ Any and all of these settings can be overriden in your `deploy.rb`.
917
+
918
+ ### rbenv_path
919
+ Sets the path where *rbenv* is installed.
920
+
921
+ You may override this if rbenv is placed elsewhere in your setup.
922
+
923
+ ## Tasks
924
+
925
+ ### rbenv:load
926
+ Loads the *rbenv* runtime.
927
+
928
+ # Modules: RVM
929
+ Adds settings and tasks for managing [RVM] installations.
930
+
931
+ [rvm]: http://rvm.io
932
+
933
+ ~~~ ruby
934
+ require 'mina/rvm'
935
+ ~~~
936
+
937
+ ## Common usage
938
+
939
+ ~~~ ruby
940
+ task :environment do
941
+ invoke :'rvm:use[ruby-1.9.3-p125@gemset_name]'
942
+ end
943
+ task :deploy => :environment do
944
+ ...
945
+ end
946
+ ~~~
947
+
948
+ ## Settings
949
+ Any and all of these settings can be overriden in your `deploy.rb`.
950
+
951
+ ### rvm_path
952
+ Sets the path to RVM.
953
+
954
+ You can override this in your projects if RVM is installed in a different
955
+ path, say, if you have a system-wide RVM install.
956
+
957
+ ## Tasks
958
+
959
+ ### rvm:use[]
960
+ Uses a given RVM environment provided as an argument.
961
+
962
+ This is usually placed in the `:environment` task.
963
+
964
+ ~~~ ruby
965
+ task :environment do
966
+ invoke :'rvm:use[ruby-1.9.3-p125@gemset_name]'
967
+ end
968
+ ~~~
969
+
970
+ ### rvm:wrapper[]
971
+ Creates a rvm wrapper for a given executable.
972
+
973
+ This is usually placed in the `:setup` task.
974
+
975
+ ~~~ ruby
976
+ task ::setup => :environment do
977
+ ...
978
+ invoke :'rvm:wrapper[ruby-1.9.3-p125@gemset_name,wrapper_name,binary_name]'
979
+ end
980
+ ~~~
981
+
982
+ Adds settings and tasks for managing projects with [whenever].
983
+ [whenever]: http://rubygems.org/gems/whenever
984
+
985
+ Acknowledgements
986
+ ----------------
987
+
988
+ © 2012-2014, Nadarei. Released under the [MIT
989
+ License](http://www.opensource.org/licenses/mit-license.php).
990
+
991
+ Mina is authored and maintained by [Rico Sta. Cruz][rsc] and [Michael
992
+ Galero][mg] with help from its [contributors][c]. It is sponsored by our
993
+ startup, [Nadarei][nd].
994
+
995
+ * [Nadarei](http://nadarei.co) (nadarei.co)
996
+ * [Github](http://github.com/nadarei) (@nadarei)
997
+
998
+ Rico:
999
+
1000
+ * [My website](http://ricostacruz.com) (ricostacruz.com)
1001
+ * [Github](http://github.com/rstacruz) (@rstacruz)
1002
+ * [Twitter](http://twitter.com/rstacruz) (@rstacruz)
1003
+
1004
+ Michael:
1005
+
1006
+ * [My website][mg] (michaelgalero.com)
1007
+ * [Github](http://github.com/mikong) (@mikong)
1008
+
1009
+ [rsc]: http://ricostacruz.com
1010
+ [mg]: http://devblog.michaelgalero.com/
1011
+ [c]: https://github.com/mina-deploy/mina/graphs/contributors
1012
+ [nd]: http://nadarei.co
1013
+ [issues]: https://github.com/mina-deploy/mina/issues
1014
+ [trello]: https://trello.com/board/mina/4fc8b3023d9c9a4d72e573e6
1015
+