mina 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +14 -5
  3. data/HISTORY.md +45 -1
  4. data/LICENSE +1 -1
  5. data/Makefile +29 -0
  6. data/Notes.md +70 -0
  7. data/Readme.md +1009 -0
  8. data/bin/mina +1 -1
  9. data/data/deploy.rb +13 -7
  10. data/lib/mina/bundler.rb +6 -1
  11. data/lib/mina/chruby.rb +49 -0
  12. data/lib/mina/default.rb +1 -0
  13. data/lib/mina/deploy.rb +17 -1
  14. data/lib/mina/deploy_helpers.rb +4 -4
  15. data/lib/mina/exec_helpers.rb +26 -19
  16. data/lib/mina/foreman.rb +5 -1
  17. data/lib/mina/git.rb +1 -1
  18. data/lib/mina/helpers.rb +22 -13
  19. data/lib/mina/rails.rb +6 -6
  20. data/lib/mina/rbenv.rb +1 -0
  21. data/lib/mina/rvm.rb +2 -4
  22. data/lib/mina/ssh_helpers.rb +2 -1
  23. data/lib/mina/version.rb +1 -1
  24. data/lib/mina/whenever.rb +6 -6
  25. data/mina.gemspec +2 -2
  26. data/spec/command_helper.rb +1 -1
  27. data/spec/commands/cleanup_spec.rb +16 -0
  28. data/spec/commands/command_spec.rb +18 -18
  29. data/spec/commands/custom_config_spec.rb +2 -2
  30. data/spec/commands/deploy_spec.rb +7 -7
  31. data/spec/commands/outside_project_spec.rb +7 -7
  32. data/spec/commands/real_deploy_spec.rb +21 -21
  33. data/spec/commands/verbose_spec.rb +2 -2
  34. data/spec/dsl/invoke_spec.rb +17 -2
  35. data/spec/dsl/queue_spec.rb +4 -4
  36. data/spec/dsl/settings_in_rake_spec.rb +6 -6
  37. data/spec/dsl/settings_spec.rb +16 -10
  38. data/spec/dsl/to_spec.rb +2 -2
  39. data/spec/helpers/exec_helper_spec.rb +19 -0
  40. data/spec/spec_helper.rb +6 -0
  41. data/support/Readme-footer.md +32 -0
  42. data/support/Readme-header.md +16 -0
  43. data/support/guide.md +297 -0
  44. data/support/index.html +53 -0
  45. data/support/to_md.rb +11 -0
  46. data/test_env/config/deploy.rb +2 -0
  47. metadata +96 -61
  48. checksums.yaml +0 -7
  49. data/README.md +0 -114
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](tasks/index.html), 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
@@ -25,6 +25,8 @@ set :deploy_to, "#{Dir.pwd}/deploy"
25
25
  set :repository, "#{Mina.root_path}"
26
26
  set :shared_paths, ['config/database.yml']
27
27
 
28
+ set :keep_releases, 2
29
+
28
30
  task :environment do
29
31
  queue %[echo "-----> Loading env"]
30
32
  end
metadata CHANGED
@@ -1,67 +1,81 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mina
3
- version: !ruby/object:Gem::Version
4
- version: 0.3.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 17
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 1
10
+ version: 0.3.1
5
11
  platform: ruby
6
- authors:
12
+ authors:
7
13
  - Rico Sta. Cruz
8
14
  - Michael Galero
9
15
  autorequire:
10
16
  bindir: bin
11
17
  cert_chain: []
12
- date: 2013-07-10 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
18
+
19
+ date: 2014-10-17 00:00:00 +02:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
15
23
  name: rake
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - '>='
19
- - !ruby/object:Gem::Version
20
- version: '0'
21
- type: :runtime
22
24
  prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - '>='
26
- - !ruby/object:Gem::Version
27
- version: '0'
28
- - !ruby/object:Gem::Dependency
29
- name: open4
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - '>='
33
- - !ruby/object:Gem::Version
34
- version: '0'
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
35
34
  type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: open4
36
38
  prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - '>='
40
- - !ruby/object:Gem::Version
41
- version: '0'
42
- - !ruby/object:Gem::Dependency
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 19
45
+ segments:
46
+ - 1
47
+ - 3
48
+ - 4
49
+ version: 1.3.4
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
43
53
  name: rspec
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - '>='
47
- - !ruby/object:Gem::Version
48
- version: '0'
49
- type: :development
50
54
  prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - '>='
54
- - !ruby/object:Gem::Version
55
- version: '0'
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 7
61
+ segments:
62
+ - 3
63
+ - 0
64
+ - 0
65
+ version: 3.0.0
66
+ type: :development
67
+ version_requirements: *id003
56
68
  description: Really fast deployer and server automation tool.
57
- email:
69
+ email:
58
70
  - rico@nadarei.co
59
71
  - mikong@nadarei.co
60
- executables:
72
+ executables:
61
73
  - mina
62
74
  extensions: []
75
+
63
76
  extra_rdoc_files: []
64
- files:
77
+
78
+ files:
65
79
  - .gitignore
66
80
  - .rspec
67
81
  - .travis.yml
@@ -69,13 +83,16 @@ files:
69
83
  - Gemfile
70
84
  - HISTORY.md
71
85
  - LICENSE
72
- - README.md
86
+ - Makefile
87
+ - Notes.md
73
88
  - Rakefile
89
+ - Readme.md
74
90
  - bin/mina
75
91
  - data/deploy.rb
76
92
  - data/deploy.sh.erb
77
93
  - lib/mina.rb
78
94
  - lib/mina/bundler.rb
95
+ - lib/mina/chruby.rb
79
96
  - lib/mina/default.rb
80
97
  - lib/mina/deploy.rb
81
98
  - lib/mina/deploy_helpers.rb
@@ -97,6 +114,7 @@ files:
97
114
  - manual/modules.md
98
115
  - mina.gemspec
99
116
  - spec/command_helper.rb
117
+ - spec/commands/cleanup_spec.rb
100
118
  - spec/commands/command_spec.rb
101
119
  - spec/commands/custom_config_spec.rb
102
120
  - spec/commands/deploy_spec.rb
@@ -111,31 +129,48 @@ files:
111
129
  - spec/dsl/to_spec.rb
112
130
  - spec/fixtures/custom_file_env/custom_deploy.rb
113
131
  - spec/fixtures/empty_env/config/deploy.rb
132
+ - spec/helpers/exec_helper_spec.rb
114
133
  - spec/helpers/output_helper_spec.rb
115
134
  - spec/spec_helper.rb
135
+ - support/Readme-footer.md
136
+ - support/Readme-header.md
137
+ - support/guide.md
138
+ - support/index.html
139
+ - support/to_md.rb
116
140
  - test_env/config/deploy.rb
141
+ has_rdoc: true
117
142
  homepage: http://github.com/nadarei/mina
118
143
  licenses: []
119
- metadata: {}
144
+
120
145
  post_install_message:
121
146
  rdoc_options: []
122
- require_paths:
147
+
148
+ require_paths:
123
149
  - lib
124
- required_ruby_version: !ruby/object:Gem::Requirement
125
- requirements:
126
- - - '>='
127
- - !ruby/object:Gem::Version
128
- version: '0'
129
- required_rubygems_version: !ruby/object:Gem::Requirement
130
- requirements:
131
- - - '>='
132
- - !ruby/object:Gem::Version
133
- version: '0'
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ hash: 3
156
+ segments:
157
+ - 0
158
+ version: "0"
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ hash: 3
165
+ segments:
166
+ - 0
167
+ version: "0"
134
168
  requirements: []
169
+
135
170
  rubyforge_project:
136
- rubygems_version: 2.0.2
171
+ rubygems_version: 1.6.2
137
172
  signing_key:
138
- specification_version: 4
173
+ specification_version: 3
139
174
  summary: Really fast deployer and server automation tool.
140
175
  test_files: []
141
- has_rdoc:
176
+
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 48b10c2f04fe8cd4a81515ad180b07e988e30315
4
- data.tar.gz: a6eb8c996ad4128d29096ce7f7307f007e0bc207
5
- SHA512:
6
- metadata.gz: 58ff29681d74382796c04253d9d29d7af8eb4c10b13788d6e66004975cd1c520a1b764de1f21b9cfd62e57e59a521f30e3c948c6b8eccfb8a8397e9560d1bb70
7
- data.tar.gz: e446b721204e02b30683df7f6bc785098bd809d83b7a0bf48b9c725d77666acaebd03138b877447096e9b355b0726effb661fe61cda7974e7342eb397591ece9