mina 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/.travis.yml +13 -0
- data/Gemfile +10 -0
- data/HISTORY.md +148 -0
- data/LICENSE +23 -0
- data/README.md +620 -0
- data/Rakefile +33 -0
- data/bin/mina +49 -0
- data/data/deploy.rb +30 -0
- data/data/deploy.sh.erb +98 -0
- data/lib/mina.rb +20 -0
- data/lib/mina/bundler.rb +23 -0
- data/lib/mina/default.rb +97 -0
- data/lib/mina/deploy.rb +57 -0
- data/lib/mina/deploy_helpers.rb +25 -0
- data/lib/mina/git.rb +14 -0
- data/lib/mina/helpers.rb +278 -0
- data/lib/mina/rails.rb +69 -0
- data/lib/mina/rake.rb +6 -0
- data/lib/mina/settings.rb +32 -0
- data/lib/mina/tools.rb +14 -0
- data/lib/mina/version.rb +5 -0
- data/mina.gemspec +17 -0
- data/spec/command_helper.rb +52 -0
- data/spec/commands/command_spec.rb +65 -0
- data/spec/commands/deploy_spec.rb +36 -0
- data/spec/commands/outside_project_spec.rb +35 -0
- data/spec/commands/real_deploy_spec.rb +53 -0
- data/spec/commands/verbose_spec.rb +20 -0
- data/spec/dsl/queue_spec.rb +49 -0
- data/spec/dsl/settings_in_rake_spec.rb +42 -0
- data/spec/dsl/settings_spec.rb +60 -0
- data/spec/dsl/to_spec.rb +20 -0
- data/spec/spec_helper.rb +20 -0
- data/test_env/config/deploy.rb +54 -0
- metadata +117 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-c --order rand -t ~ssh
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Why use bundler?
|
2
|
+
# Well, not all development dependencies install on all rubies. Moreover, `gem
|
3
|
+
# install mina --development` doesn't work, as it will also try to install
|
4
|
+
# development dependencies of our dependencies, and those are not conflict free.
|
5
|
+
# So, here we are, `bundle install`.
|
6
|
+
|
7
|
+
source :rubygems
|
8
|
+
gemspec
|
9
|
+
|
10
|
+
gem 'rake', "~> #{ENV['rake'] || "0.9"}.0"
|
data/HISTORY.md
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
v0.1.0 - Jun 06, 2012
|
2
|
+
---------------------
|
3
|
+
|
4
|
+
Renamed to Mina from Van Helsing.
|
5
|
+
|
6
|
+
|
7
|
+
v0.0.1.pre7 - Jun 06, 2012
|
8
|
+
--------------------------
|
9
|
+
|
10
|
+
### Added:
|
11
|
+
* __`vh rails[command]` and `vh rake[command]` tasks.__
|
12
|
+
* __Add `vh run`.__
|
13
|
+
* `-S` as an alias for `--simulate`.
|
14
|
+
* the `#set_default` helper.
|
15
|
+
* the `bundle_prefix` setting.
|
16
|
+
* New `term_mode` setting.
|
17
|
+
|
18
|
+
### Changed:
|
19
|
+
* `--simulate` show things without the `ssh` command or shellescaping.
|
20
|
+
|
21
|
+
v0.0.1.pre6 - Jun 06, 2012
|
22
|
+
--------------------------
|
23
|
+
|
24
|
+
Thanks to @sosedoff for his contributions that made it to this release.
|
25
|
+
|
26
|
+
### Added:
|
27
|
+
* __Rubinius support.__
|
28
|
+
* __Ruby 1.8 support.__
|
29
|
+
* Prelimenary JRuby support.
|
30
|
+
* MIT license.
|
31
|
+
* Highlight errors as red in deploy.
|
32
|
+
* Use popen4 instead of popen3. Support JRuby via IO.popen4.
|
33
|
+
|
34
|
+
### Changed:
|
35
|
+
* __Rename `to :restart` to `to :launch`.__
|
36
|
+
* __Make deploys fail if renaming the build (eg, not setup properly) fails.__
|
37
|
+
|
38
|
+
### Tests:
|
39
|
+
* Added `rake spec` (aliased as just `rake`) task. It tests with Rake 0.8 and 0.9 both.
|
40
|
+
* Integrate with [Travis CI](http://travis-ci.org).
|
41
|
+
* Make the SSH test more portable.
|
42
|
+
* Removed `rake spec:verbose`.
|
43
|
+
|
44
|
+
v0.0.1.pre5 - Jun 05, 2012
|
45
|
+
--------------------------
|
46
|
+
|
47
|
+
### Added:
|
48
|
+
* Add `--trace` to the `vh help` screen.
|
49
|
+
* Rake 0.8 compatibility.
|
50
|
+
* Ruby 1.8.7 compatibility.
|
51
|
+
|
52
|
+
### Changed:
|
53
|
+
* Use `:domain` instead of `:host`.
|
54
|
+
|
55
|
+
### Misc:
|
56
|
+
* Allow rake 0.8 testing using `rake=0.8 rspec`.
|
57
|
+
* Add more README examples.
|
58
|
+
|
59
|
+
v0.0.1.pre4 - Jun 05, 2012
|
60
|
+
--------------------------
|
61
|
+
|
62
|
+
### Added:
|
63
|
+
* `--simulate` switch.
|
64
|
+
* `--verbose` switch.
|
65
|
+
* The help screen now shows command line switches (like `--verbose`).
|
66
|
+
* Build in `tmp/` instead of in `releases/`.
|
67
|
+
* Use `verbose_mode` and `simulate_mode` instead. Using 'verbose' causes
|
68
|
+
problems.
|
69
|
+
* New `#deploy_script` helper, to make things more transparent.
|
70
|
+
|
71
|
+
### Misc:
|
72
|
+
* Added a test for an actual deployment.
|
73
|
+
* Make the `test_env` runnable even without a net connection.
|
74
|
+
* New tests for actual deployment. Just do `rspec -t ssh`.
|
75
|
+
* Cleanup `git:clone` code.
|
76
|
+
* A buncha code cleanups.
|
77
|
+
|
78
|
+
v0.0.1.pre3 - Jun 04, 2012
|
79
|
+
--------------------------
|
80
|
+
|
81
|
+
### Added:
|
82
|
+
* A help screen. You can see it with `vh --help`, `vh -h` or just plain `vh`.
|
83
|
+
* Implemented `vh --version`.
|
84
|
+
* Sequential release versions. Yay!
|
85
|
+
* Added the `build_path` setting, which supercedes the now-removed `release_path`.
|
86
|
+
|
87
|
+
### Removed:
|
88
|
+
* `release_path` has been deprecated.
|
89
|
+
|
90
|
+
### Fixed:
|
91
|
+
* Stupid critical bug fix: fix `vh:setup` giving the world access to deploy_to.
|
92
|
+
* Ensure that SSH stderr output is shown properly.
|
93
|
+
* Make `#invoke` work with tasks with arguments (eg, :'site:scrape[ensogo]')
|
94
|
+
|
95
|
+
### Changed:
|
96
|
+
* Edit the default deploy.rb to have a description for the deploy task.
|
97
|
+
* Make `vh -T` show `vh` instead of `rake`.
|
98
|
+
* Make `vh setup` ensure ownership of the `deploy_to` path.
|
99
|
+
* Make deploy steps more explicit by echoing more statuses.
|
100
|
+
* When deploys fail, you now don't see the default Ruby backtrace. It now
|
101
|
+
behaves like Rake where you need to add `--trace` to see the trace.
|
102
|
+
|
103
|
+
### Misc:
|
104
|
+
* Fixed the error that sometimes happens when invoking `vh` without a deploy.rb.
|
105
|
+
* Update the sample deploy.rb file to be more readable.
|
106
|
+
* The *test_env/* project can now be deployed without problems, so you can try
|
107
|
+
things out.
|
108
|
+
* Lots of new tests.
|
109
|
+
* rspec test order is now randomized.
|
110
|
+
* rspec output is colored (thanks to .rspec).
|
111
|
+
* Better script indentation when running in simulation mode.
|
112
|
+
* In symlinking `./current/`, use `ln -nfs` instead of `rm -f && ln -s`.
|
113
|
+
|
114
|
+
v0.0.1.pre2 - Jun 03, 2012
|
115
|
+
--------------------------
|
116
|
+
|
117
|
+
### Added:
|
118
|
+
* Implement `vh init` which creates a sample *deploy.rb*.
|
119
|
+
* Implement 'vh setup'.
|
120
|
+
* Added the configurable `:releases_path` setting, so you may change where to keep releases.
|
121
|
+
* Added documentation via Reacco.
|
122
|
+
* Allow settings to throw errors on missing settings by adding a bang (e.g.,
|
123
|
+
`bundle_path!` or `settings.bundle_path!`)
|
124
|
+
|
125
|
+
### Changed:
|
126
|
+
* Allow `bundle:install` to skip having shared bundle paths if `:bundle_path` is set to nil.
|
127
|
+
* Rename `force_unlock` to `deploy:force_unlock`.
|
128
|
+
* Rename `vh:link_shared_paths` to `deploy:link_shared_paths`.
|
129
|
+
* Invoking `deploy:force_unlock` now shows the command it uses.
|
130
|
+
|
131
|
+
### Fixed:
|
132
|
+
* The `bundle:install` task now honors the `bundle_path` setting.
|
133
|
+
* Fixed `deploy:force_unlock` always throwing an error.
|
134
|
+
* The `deploy:force_unlock` task now honors the `lock_file`
|
135
|
+
setting, so the user may change the location of the lock file.
|
136
|
+
* Fixed `rails:assets_precompile` not compiling if no older assets found.
|
137
|
+
|
138
|
+
### Removed:
|
139
|
+
* Deprecate `#validate_set`.
|
140
|
+
|
141
|
+
### Other things:
|
142
|
+
* Move deploy settings to deploy.rb.
|
143
|
+
* Rename the `default` addon to `deploy`.
|
144
|
+
|
145
|
+
v0.0.1.pre1 - Jun 02, 2012
|
146
|
+
--------------------------
|
147
|
+
|
148
|
+
Initial version.
|
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
LICENSE
|
2
|
+
|
3
|
+
The MIT License
|
4
|
+
|
5
|
+
Copyright (c) 2012 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/README.md
ADDED
@@ -0,0 +1,620 @@
|
|
1
|
+
# Mina [![status](https://secure.travis-ci.org/nadarei/mina.png?branch=master)](http://travis-ci.org/nadarei/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 ran 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
|
+
|
15
|
+
Features
|
16
|
+
--------
|
17
|
+
|
18
|
+
* __Really fast.__ Mina only makes one SSH connection per deploy. It
|
19
|
+
builds a Bash script and executes it remotely, reducing the overhead of
|
20
|
+
creating SSH connections to do processing locally (like Vlad or Capistrano
|
21
|
+
does).
|
22
|
+
|
23
|
+
* __Safe deploys.__ New releases are built on a temp folder. If the deploy
|
24
|
+
script fails at any point, the build is deleted and it'd be as if nothing
|
25
|
+
happened.
|
26
|
+
|
27
|
+
* __Locks.__ Deploy scripts rely on a lockfile ensuring only one deploy can
|
28
|
+
happen at a time.
|
29
|
+
|
30
|
+
* __Works with anything.__ While Mina is built with Rails projects it
|
31
|
+
mind, it can be used on just about any type of project deployable via SSH,
|
32
|
+
Ruby or not.
|
33
|
+
|
34
|
+
* __Built with Rake.__ Setting up tasks will be very familiar! No YAML files
|
35
|
+
here. Everything is written in Ruby, giving you the power to be as flexible in
|
36
|
+
your configuration as needed.
|
37
|
+
|
38
|
+
Setting up a project
|
39
|
+
--------------------
|
40
|
+
|
41
|
+
Let's deploy a project using Mina.
|
42
|
+
|
43
|
+
### Step 1: Create a config/deploy.rb
|
44
|
+
|
45
|
+
In your project, type `mina init` to create a sample of this file.
|
46
|
+
|
47
|
+
This is just a Rake file with tasks!
|
48
|
+
|
49
|
+
$ mina init
|
50
|
+
Created config/deploy.rb.
|
51
|
+
|
52
|
+
See [About deploy.rb](#about_deployrb) for more info on what *deploy.rb* is.
|
53
|
+
|
54
|
+
### Step 2: Set up your server
|
55
|
+
|
56
|
+
Make a directory in your server called `/var/www/flipstack.com` (in *deploy_to*)
|
57
|
+
change it's ownership to the correct user.
|
58
|
+
|
59
|
+
# SSH into your server, then:
|
60
|
+
$ mkdir /var/www/flipstack.com
|
61
|
+
$ chown -R username /var/www/flipstack.com
|
62
|
+
|
63
|
+
# Make sure 'username' is the same as what's on deploy.rb
|
64
|
+
|
65
|
+
### Step 3: Run 'mina setup'
|
66
|
+
|
67
|
+
Now do `mina setup` to set up the [folder structure](#directory_structure) in this
|
68
|
+
path. This will connect to your server via SSH and create the right directories.
|
69
|
+
|
70
|
+
$ mina setup
|
71
|
+
-----> Creating folders... done.
|
72
|
+
|
73
|
+
See [directory structure](#directory_structure) for more info.
|
74
|
+
|
75
|
+
### Step 4: Deploy!
|
76
|
+
|
77
|
+
Use `mina deploy` to run the `deploy` task defined in *config/deploy.rb*.
|
78
|
+
|
79
|
+
$ mina deploy
|
80
|
+
-----> Deploying to 2012-06-12-040248
|
81
|
+
...
|
82
|
+
Lots of things happening...
|
83
|
+
...
|
84
|
+
-----> Done.
|
85
|
+
|
86
|
+
Command line options
|
87
|
+
--------------------
|
88
|
+
|
89
|
+
* `--verbose` - This will show commands being done on the server. Off by
|
90
|
+
default.
|
91
|
+
|
92
|
+
* `--simulate` - This will not invoke any SSH connections; instead, it will
|
93
|
+
simply output the script it builds.
|
94
|
+
|
95
|
+
About deploy.rb
|
96
|
+
---------------
|
97
|
+
|
98
|
+
The file `deploy.rb` is simply a Rakefile invoked by Rake. In fact, `mina` is
|
99
|
+
mostly an alias that invokes Rake to load `deploy.rb`.
|
100
|
+
|
101
|
+
As it's all Rake, you can define tasks that you can invoke using `mina`. In this
|
102
|
+
example, it provides the `mina restart` command.
|
103
|
+
|
104
|
+
``` ruby
|
105
|
+
# Sample config/deploy.rb
|
106
|
+
set :domain, 'your.server.com'
|
107
|
+
|
108
|
+
task :restart do
|
109
|
+
queue 'sudo service restart apache'
|
110
|
+
end
|
111
|
+
```
|
112
|
+
|
113
|
+
The magic of Mina is in the new commands it gives you.
|
114
|
+
|
115
|
+
The `queue` command queues up Bash commands to be ran on the remote server.
|
116
|
+
If you invoke `mina restart`, it will invoke the task above and run the queued
|
117
|
+
commands on the remote server `your.server.com` via SSH.
|
118
|
+
|
119
|
+
See [the command queue](#the_command_queue) for more information on the *queue*
|
120
|
+
command.
|
121
|
+
|
122
|
+
The command queue
|
123
|
+
-----------------
|
124
|
+
|
125
|
+
At the heart of it, Mina is merely sugar on top of Rake to queue commands
|
126
|
+
and execute them remotely at the end.
|
127
|
+
|
128
|
+
Take a look at this minimal *deploy.rb* configuration:
|
129
|
+
|
130
|
+
``` ruby
|
131
|
+
set :user, 'john'
|
132
|
+
set :domain, 'flipstack.com'
|
133
|
+
|
134
|
+
task :logs do
|
135
|
+
queue 'echo "Contents of the log file are as follows:"'
|
136
|
+
queue "tail -f /var/log/apache.log"
|
137
|
+
end
|
138
|
+
```
|
139
|
+
|
140
|
+
Once you type `mina logs` in your terminal, it invokes the *queue*d commands
|
141
|
+
remotely on the server using the command `ssh john@flipstack.com`.
|
142
|
+
|
143
|
+
```
|
144
|
+
# Run it in simulation mode so we see the command it will invoke:
|
145
|
+
$ mina logs --simulate
|
146
|
+
(
|
147
|
+
echo "Contents of the log file are as follows:"
|
148
|
+
tail -f /var/log/apache.log
|
149
|
+
) | ssh john@flipstack.com -- bash -
|
150
|
+
```
|
151
|
+
|
152
|
+
Subtasks
|
153
|
+
--------
|
154
|
+
|
155
|
+
Mina provides the helper `invoke` to invoke other tasks from a
|
156
|
+
task.
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
task :down do
|
160
|
+
invoke :maintenance_on
|
161
|
+
invoke :restart
|
162
|
+
end
|
163
|
+
|
164
|
+
task :maintenance_on
|
165
|
+
queue 'touch maintenance.txt'
|
166
|
+
end
|
167
|
+
|
168
|
+
task :restart
|
169
|
+
queue 'sudo service restart apache'
|
170
|
+
end
|
171
|
+
```
|
172
|
+
|
173
|
+
In this example above, if you type `mina down`, it simply invokes the other
|
174
|
+
subtasks which queues up their commands. The commands will be ran after
|
175
|
+
everything.
|
176
|
+
|
177
|
+
Deploying
|
178
|
+
---------
|
179
|
+
|
180
|
+
Mina provides the `deploy` command which *queue*s up a deploy script for
|
181
|
+
you.
|
182
|
+
|
183
|
+
``` ruby
|
184
|
+
set :domain, 'flipstack.com'
|
185
|
+
set :user, 'flipstack'
|
186
|
+
set :deploy_to, '/var/www/flipstack.com'
|
187
|
+
set :repository, 'http://github.com/flipstack/flipstack.git'
|
188
|
+
|
189
|
+
task :deploy do
|
190
|
+
deploy do
|
191
|
+
# Put things that prepare the empty release folder here.
|
192
|
+
# Commands queued here will be ran on a new release directory.
|
193
|
+
invoke :'git:clone'
|
194
|
+
invoke :'bundle:install'
|
195
|
+
|
196
|
+
# These are instructions to start the app after it's been prepared.
|
197
|
+
to :launch do
|
198
|
+
queue 'touch tmp/restart.txt'
|
199
|
+
end
|
200
|
+
|
201
|
+
# This optional block defines how a broken release should be cleaned up.
|
202
|
+
to :clean do
|
203
|
+
queue 'log "failed deployment"'
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
```
|
208
|
+
|
209
|
+
It works by capturing the *queue*d commands inside the block, wrapping them
|
210
|
+
in a deploy script, then *queue*ing them back in.
|
211
|
+
|
212
|
+
How deploying works
|
213
|
+
-------------------
|
214
|
+
|
215
|
+
Here is an example of a deploy! (Note that some commands have been simplified
|
216
|
+
to illustrate the point better.)
|
217
|
+
|
218
|
+
### Step 1: Build it
|
219
|
+
|
220
|
+
The deploy process builds a new temp folder with instructions you provide.
|
221
|
+
In this example, it will do `git:clone` and `bundle:install`.
|
222
|
+
|
223
|
+
```
|
224
|
+
$ mina deploy --verbose
|
225
|
+
-----> Creating the build path
|
226
|
+
$ mkdir tmp/build-128293482394
|
227
|
+
-----> Cloning the Git repository
|
228
|
+
$ git clone https://github.com/flipstack/flipstack.git . -n --recursive
|
229
|
+
Cloning... done.
|
230
|
+
-----> Installing gem dependencies using Bundler
|
231
|
+
$ bundle install --without development:test
|
232
|
+
Using i18n (0.6.0)
|
233
|
+
Using multi_json (1.0.4)
|
234
|
+
...
|
235
|
+
Your bundle is complete! It was installed to ./vendor/bundle
|
236
|
+
```
|
237
|
+
|
238
|
+
### Step 2: Move it to releases
|
239
|
+
|
240
|
+
Once the project has been built, it will be moved to `releases/`. A symlink
|
241
|
+
called `current/` will be created to point to the active release.
|
242
|
+
|
243
|
+
```
|
244
|
+
-----> Moving to releases/4
|
245
|
+
$ mv "./tmp/build-128293482394" "releases/4"
|
246
|
+
-----> Symlinking to current
|
247
|
+
$ ln -nfs releases/4 current
|
248
|
+
```
|
249
|
+
|
250
|
+
### Step 3: Launch it
|
251
|
+
|
252
|
+
Invoke the commands queued up in the `to :launch` block. These often
|
253
|
+
commands to restart the webserver process. Once this in complete, you're done!
|
254
|
+
|
255
|
+
```
|
256
|
+
-----> Launching
|
257
|
+
$ cd releases/4
|
258
|
+
$ sudo service nginx restart
|
259
|
+
-----> Done. Deployed v4
|
260
|
+
```
|
261
|
+
|
262
|
+
### What about failure?
|
263
|
+
|
264
|
+
If it fails at any point, the release path will be deleted. If any commands are
|
265
|
+
queued using the `to :clean` block, they will be ran. It will be as if nothing
|
266
|
+
happened.
|
267
|
+
|
268
|
+
```
|
269
|
+
# Lets see what happens if a build fails:
|
270
|
+
-----> Launching
|
271
|
+
$ cd releases/4
|
272
|
+
$ sudo service nginx restart
|
273
|
+
Starting nginx... error: can't start service
|
274
|
+
-----> ERROR: Deploy failed.
|
275
|
+
-----> Cleaning up build
|
276
|
+
$ rm -rf tmp/build-128293482394
|
277
|
+
-----> Unlinking current
|
278
|
+
$ ln -nfs releases/3 current
|
279
|
+
OK
|
280
|
+
```
|
281
|
+
|
282
|
+
Directory structure
|
283
|
+
-------------------
|
284
|
+
|
285
|
+
The deploy procedures make the assumption that you have a folder like so:
|
286
|
+
|
287
|
+
/var/www/flipstack.com/ # The deploy_to path
|
288
|
+
|- releases/ # Holds releases, one subdir per release
|
289
|
+
| |- 2012-06-12-838948
|
290
|
+
| |- 2012-06-23-034828
|
291
|
+
| '- ...
|
292
|
+
|- shared/ # Holds files shared between releases
|
293
|
+
| |- logs/ # Log files are usually stored here
|
294
|
+
| `- ...
|
295
|
+
'- current/ # A symlink to the current release in releases/
|
296
|
+
|
297
|
+
It also assumes that the `deploy_to` path is fully writeable/readable for the
|
298
|
+
user we're going to SSH with.
|
299
|
+
|
300
|
+
Configuring settings
|
301
|
+
--------------------
|
302
|
+
|
303
|
+
Settings are managed using the `set` and `settings` methods. This convention is
|
304
|
+
inspired by Sinatra and Vlad.
|
305
|
+
|
306
|
+
``` ruby
|
307
|
+
set :version, "v2.0.5"
|
308
|
+
|
309
|
+
settings.version #=> "v2.0.5"
|
310
|
+
settings.version? #=> true
|
311
|
+
```
|
312
|
+
|
313
|
+
You can also retrieve settings without the `settings.` prefix.
|
314
|
+
|
315
|
+
``` ruby
|
316
|
+
set :version, "v2.0.5"
|
317
|
+
|
318
|
+
version #=> "v2.0.5"
|
319
|
+
version? #=> true
|
320
|
+
```
|
321
|
+
|
322
|
+
### Dynamic values
|
323
|
+
|
324
|
+
You can also give settings using a lambda. When the setting is retrieved, it
|
325
|
+
will be evaluated.
|
326
|
+
|
327
|
+
``` ruby
|
328
|
+
set :tag, lambda { "release/#{version}" }
|
329
|
+
set :version, "v2.0.5"
|
330
|
+
|
331
|
+
tag #=> "release/v2.0.5"
|
332
|
+
```
|
333
|
+
|
334
|
+
### Inside and outside tasks
|
335
|
+
|
336
|
+
All of these are accessible inside and outside tasks.
|
337
|
+
|
338
|
+
``` ruby
|
339
|
+
set :admin_email, "johnsmith@gmail.com"
|
340
|
+
|
341
|
+
task :email do
|
342
|
+
set :message, "Deploy is done"
|
343
|
+
|
344
|
+
system "echo #{message} | mail #{admin_email}"
|
345
|
+
end
|
346
|
+
```
|
347
|
+
|
348
|
+
### Validations
|
349
|
+
|
350
|
+
If you would like an error to be thrown if a setting is not present, add a bang
|
351
|
+
at the end.
|
352
|
+
|
353
|
+
``` ruby
|
354
|
+
task :restart do
|
355
|
+
queue "#{settings.nginx_path!}/sbin/nginx restart"
|
356
|
+
end
|
357
|
+
|
358
|
+
# $ mina restart
|
359
|
+
# Error: You must set the :nginx_path setting
|
360
|
+
```
|
361
|
+
|
362
|
+
Defaults
|
363
|
+
--------
|
364
|
+
|
365
|
+
There are a few deploy-related tasks and settings that are on by default.
|
366
|
+
|
367
|
+
### Base settings
|
368
|
+
|
369
|
+
* `verbose_mode` - True if the `--verbose` flag is on, false otherwise. Used to
|
370
|
+
signal if commands are to be shown.
|
371
|
+
|
372
|
+
* `simulate_mode` - True if `--simulate` flag is on, false otherwise. Used to
|
373
|
+
signal if no SSH connections are to be made, and the scripts will just be
|
374
|
+
printed locally.
|
375
|
+
|
376
|
+
* `term_mode` - If set to `:pretty`, prettifies the output with indentations.
|
377
|
+
(Default with deploys.)
|
378
|
+
|
379
|
+
### SSH settings
|
380
|
+
|
381
|
+
* `domain` - Hostname to SSH to. *Required.*
|
382
|
+
|
383
|
+
* `user` - Username to connect to SSH with. Optional.
|
384
|
+
|
385
|
+
* `identity_file` - Local path to the SSH key to use. Optional.
|
386
|
+
|
387
|
+
``` ruby
|
388
|
+
# Example:
|
389
|
+
set :domain, 'flipstack.me'
|
390
|
+
set :user, 'flipstack_www'
|
391
|
+
set :identity_file, 'flipstack.pem'
|
392
|
+
```
|
393
|
+
|
394
|
+
### Deploy settings
|
395
|
+
|
396
|
+
* `deploy_to` - Path to deploy to. *Required.*
|
397
|
+
|
398
|
+
* `releases_path` - The path to where releases are kept. Defaults to
|
399
|
+
`releases`.
|
400
|
+
|
401
|
+
* `shared_path` - Where shared files are kept. Defaults to
|
402
|
+
`shared`.
|
403
|
+
|
404
|
+
* `current_path` - The path to the symlink to the current release. Defaults to
|
405
|
+
`current`.
|
406
|
+
|
407
|
+
* `lock_file` - The deploy lock file. A deploy does not start if this file is
|
408
|
+
found. Defaults to `deploy.lock`.
|
409
|
+
|
410
|
+
|
411
|
+
``` ruby
|
412
|
+
# Example:
|
413
|
+
set :deploy_to, '/var/www/flipstack.me'
|
414
|
+
set :releases_path, 'releases'
|
415
|
+
set :shared_path, 'shared'
|
416
|
+
set :current_path, 'current'
|
417
|
+
set :lock_file, 'deploy.lock'
|
418
|
+
|
419
|
+
# This means the following paths will be
|
420
|
+
# created on `mina setup`:
|
421
|
+
# /var/www/flipstack.me/
|
422
|
+
# /var/www/flipstack.me/releases/
|
423
|
+
# /var/www/flipstack.me/shared/
|
424
|
+
```
|
425
|
+
|
426
|
+
### Task - setup
|
427
|
+
|
428
|
+
Prepares the `deploy_to` directory for deployments. Sets up subdirectories and
|
429
|
+
sets permissions in the path.
|
430
|
+
|
431
|
+
$ mina setup
|
432
|
+
-----> Setting up
|
433
|
+
$ mkdir -p /var/www/kickstack.me
|
434
|
+
$ chmod g+r,a+rwx /var/www/kickstack.me
|
435
|
+
$ mkdir -p /var/www/kickstack.me/releases
|
436
|
+
$ mkdir -p /var/www/kickstack.me/shared
|
437
|
+
...
|
438
|
+
|
439
|
+
### Task - deploy:force_unlock
|
440
|
+
|
441
|
+
Removes the deploy lock file. If a deploy is terminated midway, it may leave a
|
442
|
+
lock file to signal that deploys shouldn't be made. This forces the removal of
|
443
|
+
that lock file.
|
444
|
+
|
445
|
+
$ mina deploy
|
446
|
+
-----> ERROR: another deployment is ongoing.
|
447
|
+
Delete the lock file to continue.
|
448
|
+
|
449
|
+
$ mina deploy:force_unlock
|
450
|
+
-----> Unlocking
|
451
|
+
$ rm /var/www/kickstack.me/deploy.lock
|
452
|
+
|
453
|
+
$ mina deploy
|
454
|
+
# The deploy should proceed now
|
455
|
+
|
456
|
+
Addons: Git
|
457
|
+
-----------
|
458
|
+
|
459
|
+
To deploy projects using git, add this to your `deploy.rb`:
|
460
|
+
|
461
|
+
``` ruby
|
462
|
+
require 'mina/git'
|
463
|
+
|
464
|
+
set :repository, 'https://github.com/you/your-app.git'
|
465
|
+
```
|
466
|
+
|
467
|
+
### Settings
|
468
|
+
|
469
|
+
This introduces the following settings:
|
470
|
+
|
471
|
+
* `repository` - The repository path to clone from. *Required.*
|
472
|
+
|
473
|
+
* `revision` - The SHA1 of the commit to be deployed. Defaults to whatever is
|
474
|
+
the current HEAD in your local copy.
|
475
|
+
|
476
|
+
### Task - git:clone
|
477
|
+
|
478
|
+
Clones from the repo into the current folder.
|
479
|
+
|
480
|
+
Addons: Bundler
|
481
|
+
---------------
|
482
|
+
|
483
|
+
To manage Bundler installations, add this to your `deploy.rb`:
|
484
|
+
|
485
|
+
``` ruby
|
486
|
+
require 'mina/bundler'
|
487
|
+
```
|
488
|
+
|
489
|
+
### Settings
|
490
|
+
|
491
|
+
This introduces the following settings:
|
492
|
+
|
493
|
+
* `bundle_path` - The path where bundles are going to be installed. Defaults to
|
494
|
+
`./vendor/bundler`.
|
495
|
+
|
496
|
+
* `bundle_options` - Options that will be passed onto `bundle install`.
|
497
|
+
Defaults to
|
498
|
+
`--without development:test --path "#{bundle_path}" --binstubs bin/
|
499
|
+
--deployment"`.
|
500
|
+
|
501
|
+
### Task - bundle:install
|
502
|
+
|
503
|
+
Invokes `bundle:install` on the current directory, creating the bundle
|
504
|
+
path (specified in `bundle_path`), and invoking `bundle install`.
|
505
|
+
|
506
|
+
The `bundle_path` is only created if `bundle_path` is set (which is on
|
507
|
+
by default).
|
508
|
+
|
509
|
+
Addons: Rails
|
510
|
+
-------------
|
511
|
+
|
512
|
+
To manage Rails project installations, add this to your `deploy.rb`:
|
513
|
+
|
514
|
+
``` ruby
|
515
|
+
require 'mina/rails'
|
516
|
+
```
|
517
|
+
|
518
|
+
### Settings
|
519
|
+
|
520
|
+
This introduces the following settings. All of them are optional.
|
521
|
+
|
522
|
+
* `bundle_prefix` - Prefix to run commands via Bundler. Defaults to
|
523
|
+
`RAILS_ENV="#{rails_env}" bundle exec`.
|
524
|
+
|
525
|
+
* `rake` - The `rake` command. Defaults to `#{bundle_prefix} rake`.
|
526
|
+
|
527
|
+
* `rails` - The `rails` command. Defaults to `#{bundle_prefix} rails`.
|
528
|
+
|
529
|
+
* `rails_env` - The environment to run rake commands in. Defaults to
|
530
|
+
`production`.
|
531
|
+
|
532
|
+
### Task - rails:db_migrate
|
533
|
+
|
534
|
+
Invokes rake to migrate the database using `rake db:migrate`.
|
535
|
+
|
536
|
+
### Task - rails:assets_precompile
|
537
|
+
|
538
|
+
Precompiles assets. This invokes `rake assets:precomplie`.
|
539
|
+
|
540
|
+
It also checks the current version to see if it has assets compiled. If it does,
|
541
|
+
it reuses them, skipping the compilation step. To stop this behavior, invoke
|
542
|
+
the `mina` command with `force_assets=1`.
|
543
|
+
|
544
|
+
### Task - rails:assets_precompile:force
|
545
|
+
|
546
|
+
Precompiles assets. This always skips the "reuse old assets if possible" step.
|
547
|
+
|
548
|
+
Development & testing
|
549
|
+
---------------------
|
550
|
+
|
551
|
+
To test out stuff in development:
|
552
|
+
|
553
|
+
# Run specs
|
554
|
+
$ rspec
|
555
|
+
$ rspec -t ssh # Run SSH tests (read test_env/config/deploy.rb first)
|
556
|
+
$ rake=0.9 rspec
|
557
|
+
$ rake=0.8 rspec
|
558
|
+
|
559
|
+
# Alias your 'mina' to use it everywhere
|
560
|
+
$ alias mina="`pwd -LP`/bin/mina"
|
561
|
+
|
562
|
+
### Doing test deploys
|
563
|
+
|
564
|
+
Try out the test environment:
|
565
|
+
|
566
|
+
$ cd test_env
|
567
|
+
$ mina deploy --simulate
|
568
|
+
$ mina deploy
|
569
|
+
|
570
|
+
# There's an rspec task for it too
|
571
|
+
$ rspec -t ssh
|
572
|
+
|
573
|
+
### Gem management
|
574
|
+
|
575
|
+
# To release the gem:
|
576
|
+
# Install the Git changelog helper: https://gist.github.com/2880525
|
577
|
+
$ vim lib/mina/version.rb
|
578
|
+
$ git clog -w
|
579
|
+
$ vim HISTORY.md
|
580
|
+
$ rake release
|
581
|
+
|
582
|
+
$ rake build # Builds the gem file
|
583
|
+
$ rake install # Installs the gem locally
|
584
|
+
|
585
|
+
Issues
|
586
|
+
------
|
587
|
+
|
588
|
+
File issues at the [issue tracker][issues] (github.com). You may also look at
|
589
|
+
the [Trello board][trello] (trello.com) we use for development.
|
590
|
+
|
591
|
+
Acknowledgements
|
592
|
+
----------------
|
593
|
+
|
594
|
+
© 2012, Nadarei. Released under the [MIT
|
595
|
+
License](http://www.opensource.org/licenses/mit-license.php).
|
596
|
+
|
597
|
+
Mina is authored and maintained by [Rico Sta. Cruz][rsc] and [Michael
|
598
|
+
Galero][mg] with help from its [contributors][c]. It is sponsored by our
|
599
|
+
startup, [Nadarei][nd].
|
600
|
+
|
601
|
+
* [Nadarei](http://nadarei.co) (nadarei.co)
|
602
|
+
* [Github](http://github.com/nadarei) (@nadarei)
|
603
|
+
|
604
|
+
Rico:
|
605
|
+
|
606
|
+
* [My website](http://ricostacruz.com) (ricostacruz.com)
|
607
|
+
* [Github](http://github.com/rstacruz) (@rstacruz)
|
608
|
+
* [Twitter](http://twitter.com/rstacruz) (@rstacruz)
|
609
|
+
|
610
|
+
Michael:
|
611
|
+
|
612
|
+
* [My website][mg] (michaelgalero.com)
|
613
|
+
* [Github](http://github.com/mikong) (@mikong)
|
614
|
+
|
615
|
+
[rsc]: http://ricostacruz.com
|
616
|
+
[mg]: http://devblog.michaelgalero.com/
|
617
|
+
[c]: http://github.com/nadarei/mina/contributors
|
618
|
+
[nd]: http://nadarei.co
|
619
|
+
[issues]: https://github.com/nadarei/mina/issues
|
620
|
+
[trello]: https://trello.com/board/mina/4fc8b3023d9c9a4d72e573e6
|