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
@@ -0,0 +1,32 @@
1
+
2
+ Acknowledgements
3
+ ----------------
4
+
5
+ © 2012-2014, Nadarei. Released under the [MIT
6
+ License](http://www.opensource.org/licenses/mit-license.php).
7
+
8
+ Mina is authored and maintained by [Rico Sta. Cruz][rsc] and [Michael
9
+ Galero][mg] with help from its [contributors][c]. It is sponsored by our
10
+ startup, [Nadarei][nd].
11
+
12
+ * [Nadarei](http://nadarei.co) (nadarei.co)
13
+ * [Github](http://github.com/nadarei) (@nadarei)
14
+
15
+ Rico:
16
+
17
+ * [My website](http://ricostacruz.com) (ricostacruz.com)
18
+ * [Github](http://github.com/rstacruz) (@rstacruz)
19
+ * [Twitter](http://twitter.com/rstacruz) (@rstacruz)
20
+
21
+ Michael:
22
+
23
+ * [My website][mg] (michaelgalero.com)
24
+ * [Github](http://github.com/mikong) (@mikong)
25
+
26
+ [rsc]: http://ricostacruz.com
27
+ [mg]: http://devblog.michaelgalero.com/
28
+ [c]: http://github.com/nadarei/mina/contributors
29
+ [nd]: http://nadarei.co
30
+ [issues]: https://github.com/nadarei/mina/issues
31
+ [trello]: https://trello.com/board/mina/4fc8b3023d9c9a4d72e573e6
32
+
@@ -0,0 +1,16 @@
1
+ # 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/mina-deploy/mina.svg?branch=master)](https://travis-ci.org/mina-deploy/mina) [![Gem Version](https://badge.fury.io/rb/mina.svg)](http://badge.fury.io/rb/mina)
data/support/guide.md ADDED
@@ -0,0 +1,297 @@
1
+
2
+ User guide
3
+ ==========
4
+
5
+ Setting up a project
6
+ --------------------
7
+
8
+ Let's deploy a project using Mina.
9
+
10
+ ### Step 1: Create a config/deploy.rb
11
+
12
+ In your project, type `mina init` to create a sample of this file.
13
+
14
+ $ mina init
15
+ Created config/deploy.rb.
16
+
17
+ This is just a Rake file with tasks! See [About deploy.rb](#about-deployrb) for
18
+ more info on what *deploy.rb* is. You will want to at least configure your
19
+ server:
20
+
21
+ ~~~ ruby
22
+ # config/deploy.rb
23
+ set :user, 'username'
24
+ set :domain, 'your.server.com'
25
+ set :deploy_to, '/var/www/flipstack.com'
26
+ ...
27
+ ~~~
28
+
29
+ ### Step 2: Set up your server
30
+
31
+ Make a directory in your server called `/var/www/flipstack.com` (in *deploy_to*)
32
+ change it's ownership to the correct user.
33
+
34
+ $ ssh username@your.server.com
35
+
36
+ # Once in your server, create the deploy folder:
37
+ ~@your.server.com$ mkdir /var/www/flipstack.com
38
+ ~@your.server.com$ chown -R username /var/www/flipstack.com
39
+
40
+ ### Step 3: Run 'mina setup'
41
+
42
+ Back at your computer, do `mina setup` to set up the [folder
43
+ structure](#directory_structure) in this path. This will connect to your server
44
+ via SSH and create the right directories.
45
+
46
+ $ mina setup
47
+ -----> Creating folders... done.
48
+
49
+ See [directory structure](#directory_structure) for more info.
50
+
51
+ ### Step 4: Deploy!
52
+
53
+ Use `mina deploy` to run the `deploy` task defined in *config/deploy.rb*.
54
+
55
+ $ mina deploy
56
+ -----> Deploying to 2012-06-12-040248
57
+ ...
58
+ Lots of things happening...
59
+ ...
60
+ -----> Done.
61
+
62
+ About deploy.rb
63
+ ---------------
64
+
65
+ The file `deploy.rb` is simply a Rakefile invoked by Rake. In fact, `mina` is
66
+ mostly an alias that invokes Rake to load `deploy.rb`.
67
+
68
+ ~~~ ruby
69
+ # Sample config/deploy.rb
70
+ set :domain, 'your.server.com'
71
+
72
+ task :restart do
73
+ queue 'sudo service restart apache'
74
+ end
75
+ ~~~
76
+
77
+ As it's all Rake, you can define tasks that you can invoke using `mina`. In this
78
+ example, it provides the `mina restart` command.
79
+
80
+ The magic of Mina is in the new commands it gives you.
81
+
82
+ The `queue` command queues up Bash commands to be run on the remote server.
83
+ If you invoke `mina restart`, it will invoke the task above and run the queued
84
+ commands on the remote server `your.server.com` via SSH.
85
+
86
+ See [the command queue](#the-command-queue) for more information on the *queue*
87
+ command.
88
+
89
+ The command queue
90
+ -----------------
91
+
92
+ At the heart of it, Mina is merely sugar on top of Rake to queue commands
93
+ and execute them remotely at the end. Take a look at this minimal *deploy.rb*
94
+ configuration:
95
+
96
+ ~~~ ruby
97
+ # config/deploy.rb
98
+ set :user, 'john'
99
+ set :domain, 'flipstack.com'
100
+
101
+ task :logs do
102
+ queue 'echo "Contents of the log file are as follows:"'
103
+ queue "tail -f /var/log/apache.log"
104
+ end
105
+ ~~~
106
+
107
+ Once you type `mina logs` in your terminal, it invokes the *queue*d commands
108
+ remotely on the server using the command `ssh john@flipstack.com`.
109
+
110
+ ~~~ sh
111
+ $ mina logs --simulate
112
+ # Execute the following commands via
113
+ # ssh john@flipstack.com:
114
+ #
115
+ echo "Contents of the log file are as follows:"
116
+ tail -f /var/log/apache.log
117
+ ~~~
118
+
119
+ Subtasks
120
+ --------
121
+
122
+ Mina provides the helper `invoke` to invoke other tasks from a
123
+ task.
124
+
125
+ ~~~ ruby
126
+ # config/deploy.rb
127
+ task :down do
128
+ invoke :maintenance_on
129
+ invoke :restart
130
+ end
131
+
132
+ task :maintenance_on
133
+ queue 'touch maintenance.txt'
134
+ end
135
+
136
+ task :restart
137
+ queue 'sudo service restart apache'
138
+ end
139
+ ~~~
140
+
141
+ In this example above, if you type `mina down`, it simply invokes the other
142
+ subtasks which queues up their commands. The commands will be run after
143
+ everything.
144
+
145
+ Directory structure
146
+ -------------------
147
+
148
+ The deploy procedures make the assumption that you have a folder like so:
149
+
150
+ /var/www/flipstack.com/ # The deploy_to path
151
+ |- releases/ # Holds releases, one subdir per release
152
+ | |- 1/
153
+ | |- 2/
154
+ | |- 3/
155
+ | '- ...
156
+ |- shared/ # Holds files shared between releases
157
+ | |- logs/ # Log files are usually stored here
158
+ | `- ...
159
+ '- current/ # A symlink to the current release in releases/
160
+
161
+ It also assumes that the `deploy_to` path is fully writeable/readable for the
162
+ user we're going to SSH with.
163
+
164
+ Deploying
165
+ ---------
166
+
167
+ Mina provides the `deploy` command which *queue*s up a deploy script for
168
+ you.
169
+
170
+ ~~~ ruby
171
+ # config/deploy.rb
172
+ set :domain, 'flipstack.com'
173
+ set :user, 'flipstack'
174
+ set :deploy_to, '/var/www/flipstack.com'
175
+ set :repository, 'http://github.com/flipstack/flipstack.git'
176
+
177
+ task :deploy do
178
+ deploy do
179
+ # Put things that prepare the empty release folder here.
180
+ # Commands queued here will be run on a new release directory.
181
+ invoke :'git:clone'
182
+ invoke :'bundle:install'
183
+
184
+ # These are instructions to start the app after it's been prepared.
185
+ to :launch do
186
+ queue 'touch tmp/restart.txt'
187
+ end
188
+
189
+ # This optional block defines how a broken release should be cleaned up.
190
+ to :clean do
191
+ queue 'log "failed deployment"'
192
+ end
193
+ end
194
+ end
195
+ ~~~
196
+
197
+ It works by capturing the *queue*d commands inside the block, wrapping them
198
+ in a deploy script, then *queue*ing them back in.
199
+
200
+ ### How deploying works
201
+
202
+ Here is an example of a deploy! (Note that some commands have been simplified
203
+ to illustrate the point better.)
204
+
205
+ ### Step 1: Build it
206
+
207
+ The deploy process builds a new temp folder with instructions you provide.
208
+ In this example, it will do `git:clone` and `bundle:install`.
209
+
210
+ $ mina deploy --verbose
211
+ -----> Creating the build path
212
+ $ mkdir tmp/build-128293482394
213
+ -----> Cloning the Git repository
214
+ $ git clone https://github.com/flipstack/flipstack.git . -n --recursive
215
+ Cloning... done.
216
+ -----> Installing gem dependencies using Bundler
217
+ $ bundle install --without development:test
218
+ Using i18n (0.6.0)
219
+ Using multi_json (1.0.4)
220
+ ...
221
+ Your bundle is complete! It was installed to ./vendor/bundle
222
+
223
+ ### Step 2: Move it to releases
224
+
225
+ Once the project has been built, it will be moved to `releases/`. A symlink
226
+ called `current/` will be created to point to the active release.
227
+
228
+ $
229
+ -----> Moving to releases/4
230
+ $ mv "./tmp/build-128293482394" "releases/4"
231
+ -----> Symlinking to current
232
+ $ ln -nfs releases/4 current
233
+
234
+ ### Step 3: Launch it
235
+
236
+ Invoke the commands queued up in the `to :launch` block. These often
237
+ commands to restart the webserver process. Once this in complete, you're done!
238
+
239
+ $
240
+ -----> Launching
241
+ $ cd releases/4
242
+ $ sudo service nginx restart
243
+ -----> Done. Deployed v4
244
+
245
+ ### What about failure?
246
+
247
+ If it fails at any point, the release path will be deleted. If any commands are
248
+ queued using the `to :clean` block, they will be run. It will be as if nothing
249
+ happened. Lets see what happens if a build fails:
250
+
251
+ $
252
+ -----> Launching
253
+ $ cd releases/4
254
+ $ sudo service nginx restart
255
+ Starting nginx... error: can't start service
256
+ -----> ERROR: Deploy failed.
257
+ -----> Cleaning up build
258
+ $ rm -rf tmp/build-128293482394
259
+ -----> Unlinking current
260
+ $ ln -nfs releases/3 current
261
+ OK
262
+
263
+ Command line options
264
+ --------------------
265
+
266
+ Basic usage:
267
+
268
+ $ mina [OPTIONS] [TASKS] [VAR1=val VAR2=val ...]
269
+
270
+ ### Options
271
+
272
+ * `-v` / `--verbose` - This will show commands being done on the server. Off by
273
+ default.
274
+
275
+ * `-S` / `--simulate` - This will not invoke any SSH connections; instead, it
276
+ will simply output the script it builds.
277
+
278
+ * `-t` / `--trace` - Show backtraces when errors occur.
279
+
280
+ * `-f FILE` - Use a custom deploy.rb configuration.
281
+
282
+ * `-V` / `--version` - Shows the current version.
283
+
284
+ ### Tasks
285
+
286
+ There are many tasks available. See the [tasks reference](http://mina-deploy.github.io/mina/tasks/), or
287
+ type `mina tasks`.
288
+
289
+ ### Variables
290
+
291
+ You may specify additional variables in the `KEY=value` style, just like Rake.
292
+ You can add as many variables as needed.
293
+
294
+ $ mina restart on=staging
295
+
296
+ # This sets the ENV['on'] variable to 'staging'.
297
+
@@ -0,0 +1,53 @@
1
+ <html>
2
+ <head>
3
+ <meta charset='utf-8'>
4
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
5
+ <meta name="viewport" content="width=device-width">
6
+
7
+ <title>Mina</title>
8
+
9
+ <!-- Flatdoc -->
10
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
11
+ <script src='http://rstacruz.github.io/flatdoc/v/0.8.0/legacy.js'></script>
12
+ <script src='http://rstacruz.github.io/flatdoc/v/0.8.0/flatdoc.js'></script>
13
+
14
+ <!-- Flatdoc theme -->
15
+ <link href='http://rstacruz.github.io/flatdoc/v/0.8.0/theme-white/style.css' rel='stylesheet'>
16
+ <script src='http://rstacruz.github.io/flatdoc/v/0.8.0/theme-white/script.js'></script>
17
+
18
+ <!-- Meta -->
19
+ <meta content="Mina" property="og:title">
20
+ <meta content="Mina deployer tool." name="description">
21
+
22
+ <!-- Initializer -->
23
+ <script>
24
+ Flatdoc.run({
25
+ fetcher: location.hostname.match(/localhost/) ? Flatdoc.file('../Readme.md') : Flatdoc.github('nadarei/mina')
26
+ });
27
+ </script>
28
+ </head>
29
+ <body role='flatdoc'>
30
+
31
+ <div class='header'>
32
+ <div class='left'>
33
+ <h1>Mina</h1>
34
+ <ul>
35
+ <li><a href='https://github.com/nadarei/mina'>View on GitHub</a></li>
36
+ <li><a href='https://github.com/nadarei/mina/issues'>Issues</a></li>
37
+ </ul>
38
+ </div>
39
+ <div class='right'>
40
+ <!-- GitHub buttons: see http://ghbtns.com -->
41
+ <iframe src="http://ghbtns.com/github-btn.html?user=nadarei&amp;repo=mina&amp;type=watch&amp;count=true" allowtransparency="true" frameborder="0" scrolling="0" width="110" height="20"></iframe>
42
+ </div>
43
+ </div>
44
+
45
+ <div class='content-root'>
46
+ <div class='menubar'>
47
+ <div class='menu section' role='flatdoc-menu'></div>
48
+ </div>
49
+ <div role='flatdoc-content' class='content'></div>
50
+ </div>
51
+
52
+ </body>
53
+ </html>
data/support/to_md.rb ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ c = /(?:#|\/\/)/ # Comment prefix
3
+ lang = "ruby" # Default language
4
+ blocks = STDIN.read.scan(/(?:^[ \t]*#{c} [^\n]*\n)+/) # Read contiguous comments
5
+ blocks.map! { |s| s.gsub!(/(?:^|\n)+[ \t]*#{c} /, "\n") } # Strip out prefixes
6
+
7
+ # Code blocks
8
+ md = blocks.join("")
9
+ md.gsub!(/((?:^ .*\n+)+)/) { |f| "~~~ #{lang}\n" + f.gsub(/^ /, '').gsub(/\s*$/, '') + "\n~~~\n\n" }
10
+
11
+ puts md
@@ -0,0 +1,69 @@
1
+ # NOTE:
2
+ # Yes, you can deploy this project. It will deploy into the ./deploy/
3
+ # directory. The commands have been stubbed, so it's harmless. No rails or
4
+ # bundler magic will happen.
5
+
6
+ # ASSUMPTIONS:
7
+ # - You have git installed. (of course you do)
8
+ # - You have SSH enabled. In OS X, this is "Remote Login" under the Sharing pref pane.
9
+ # - You have your own SSH key added to your own user so you can SSH to your own machine.
10
+
11
+ # In fact, let's make that folder right now.
12
+ require 'fileutils'
13
+ FileUtils.mkdir_p "#{Dir.pwd}/deploy"
14
+ FileUtils.mkdir_p "#{Dir.pwd}/deploy/config"
15
+ File.open("#{Dir.pwd}/deploy/config/database.yml", 'w') { |f| f.write "Hello" }
16
+
17
+ # -- Stubs end, deploy script begins! --------------
18
+
19
+ require 'mina/rails'
20
+ require 'mina/bundler'
21
+ require 'mina/git'
22
+
23
+ set :domain, 'localhost'
24
+ set :deploy_to, "#{Dir.pwd}/deploy"
25
+ set :repository, "#{Mina.root_path}"
26
+ set :shared_paths, ['config/database.yml']
27
+
28
+ set :keep_releases, 2
29
+
30
+ task :environment do
31
+ queue print_str('-> Loading env')
32
+ end
33
+
34
+ desc "Deploys."
35
+ task :deploy => :environment do
36
+ queue "bundle() { true; }" # Stub the bundle command.
37
+
38
+ deploy do
39
+ queue %[ruby -e "\\$stderr.write \\\"This is stdout output\n\\\""]
40
+ invoke :'git:clone'
41
+ invoke :'deploy:link_shared_paths'
42
+ invoke :'bundle:install'
43
+ invoke :'rails:db_migrate'
44
+
45
+ to :launch do
46
+ invoke :'passenger:restart'
47
+ end
48
+ end
49
+ end
50
+
51
+ desc "Restarts the passenger server."
52
+ task :restart do
53
+ invoke :'passenger:restart'
54
+ end
55
+
56
+ namespace :passenger do
57
+ task :restart do
58
+ queue %{
59
+ #{print_str '-> Restarting passenger'}
60
+ #{echo_cmd %[mkdir -p tmp]}
61
+ #{echo_cmd %[touch tmp/restart.txt]}
62
+ }
63
+ end
64
+ end
65
+
66
+ task :get_password do
67
+ set :term_mode, :pretty
68
+ queue %[echo "-> Getting password"; echo -n "Password: "; read x; echo ""; echo out: $x;]
69
+ end