deployer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +4 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.textile +290 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/bin/enhancify +74 -0
- data/deployer.gemspec +65 -0
- data/lib/deployer.rb +36 -0
- data/lib/deployer/helpers.rb +27 -0
- data/lib/deployer/initializer.rb +5 -0
- data/lib/deployer/tasks/deployer.rake +18 -0
- data/lib/tasks/apache.rb +49 -0
- data/lib/tasks/commands.rb +17 -0
- data/lib/tasks/db.rb +49 -0
- data/lib/tasks/environment.rb +21 -0
- data/lib/tasks/gems.rb +16 -0
- data/lib/tasks/global.rb +57 -0
- data/lib/tasks/nginx.rb +47 -0
- data/lib/tasks/passenger.rb +11 -0
- data/lib/tasks/plugin.rb +24 -0
- data/lib/tasks/repository.rb +51 -0
- data/setup/deploy.rb +102 -0
- metadata +87 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Michael van Rooijen
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,290 @@
|
|
1
|
+
h1. Deployer
|
2
|
+
|
3
|
+
p. Deployer is a deployment engine (Ruby Gem) that enhances Capistrano with a set of useful automated deployment tasks and a base structure. It favors convention over configuration, and it simplifies Rails Application Deployment with Capistrano.
|
4
|
+
|
5
|
+
p. It assumes you are using Passenger to serve your Rails applications.
|
6
|
+
|
7
|
+
h2. Why?
|
8
|
+
|
9
|
+
p. I wanted a tool that'd enhance Capistrano's default setup, and I wanted it to cause me a minimal amount of hassle and time consumption to set up as well for every time I want to deploy a new application.
|
10
|
+
|
11
|
+
|
12
|
+
h2. Getting Started
|
13
|
+
|
14
|
+
p. install the gem
|
15
|
+
|
16
|
+
bc. sudo gem install deployer
|
17
|
+
|
18
|
+
p. create a new Rails app
|
19
|
+
|
20
|
+
bc. rails my_application
|
21
|
+
|
22
|
+
p. move into the Rails app and execute the "capify" and "enhancify" commands
|
23
|
+
|
24
|
+
bc. cd my_application
|
25
|
+
capify .
|
26
|
+
enhancify .
|
27
|
+
|
28
|
+
p. enhancify is a command, provided by deployer that will inject some code into the Capfile and replace the config/deploy.rb with the one used for *Deployer*.
|
29
|
+
If the deploy.rb file already exists, it will simply rename it to "deploy.old.1.rb", and if that also exists it will rename it to deploy.old.2.rb, etc. etc. So you will never accidentally overwrite your initial deploy.rb file.
|
30
|
+
|
31
|
+
p. This is what the deploy.rb looks like: "config/deploy.rb":http://github.com/meskyanichi/deployer/blob/master/setup/deploy.rb
|
32
|
+
|
33
|
+
p. *Next, open the config/deploy.rb file and edit the following variables.*
|
34
|
+
|
35
|
+
bc. set :ip, "123.45.678.90" # the ip address that points to your production server
|
36
|
+
set :user, "root" # the user that will connect to the production server
|
37
|
+
set :remote, "origin" # the remote that should be deployed
|
38
|
+
set :branch, "master" # the branch that should be deployed
|
39
|
+
set :domain, "example.com" # (or set :domain, "subdomain.example.com"
|
40
|
+
set :subdomain, false # and set :subdomain, true)
|
41
|
+
|
42
|
+
p. For the sake of *testing*, be sure to *NOT* test this out on your main domain, unless you don't have an application running there that is. In the above example you can see how you set this up for a subdomain for your application to deploy a sample Rails Application to try out *Deployer*.
|
43
|
+
|
44
|
+
bc. set :domain, "test.mydomain.com"
|
45
|
+
set :subdomain, true
|
46
|
+
|
47
|
+
p. _This is what you must do if you wish to try it out on a subdomain. In this case: test.mydomain.com_
|
48
|
+
|
49
|
+
p. And *that's it!* You are now ready to do the following through *Deployer*:
|
50
|
+
|
51
|
+
* Create a remote git repository
|
52
|
+
* Push your initial commit to the remote repository
|
53
|
+
* Create the production environment to where you will deploy your application to
|
54
|
+
* Let *Deployer* create a simple Apache2 or NginX virtual-host file, transfer it to your remote server and restart the web-server
|
55
|
+
* And, of course, deploy and run your Rails application!
|
56
|
+
|
57
|
+
p. Here is are the quick-reference comments of the config/deploy.rb file
|
58
|
+
|
59
|
+
bc. # Quick Reference
|
60
|
+
# Configure the essential configurations below and do the following:
|
61
|
+
#
|
62
|
+
# Create Local and Remote Repository:
|
63
|
+
# git init
|
64
|
+
# cap deploy:repository:create
|
65
|
+
#
|
66
|
+
# Initial Deployment:
|
67
|
+
# git add .
|
68
|
+
# git commit -am "Initial commit for deployment"
|
69
|
+
# git push origin master
|
70
|
+
# cap deploy:initial
|
71
|
+
#
|
72
|
+
# Then For Every Update Just Do:
|
73
|
+
# git add .
|
74
|
+
# git commit -am "some other commit"
|
75
|
+
# git push origin master
|
76
|
+
# cap deploy
|
77
|
+
#
|
78
|
+
# For Apache2 Users
|
79
|
+
# cap deploy:apache:create
|
80
|
+
# cap deploy:apache:destroy
|
81
|
+
# cap deploy:apache:restart
|
82
|
+
# cap deploy:apache:destroy_all
|
83
|
+
#
|
84
|
+
# For NginX Users
|
85
|
+
# cap deploy:nginx:create
|
86
|
+
# cap deploy:nginx:destroy
|
87
|
+
# cap deploy:nginx:restart
|
88
|
+
# cap deploy:nginx:destroy_all
|
89
|
+
#
|
90
|
+
# For a Full List of Commands
|
91
|
+
# cap -T
|
92
|
+
|
93
|
+
p. *NOTE*
|
94
|
+
|
95
|
+
p. The Apache2 and NginX tasks are totally OPTIONAL. Before you use these, please scroll down this page and see what it's all about. It essentially parses an initial *apache* or *nginx* virtual host file. Once parsed, it will transfer this inside the sites-available / sites-enabled folders. Afterwards *Apache* or *Nginx* will automatically get restarted. So basically you COULD deploy a web application without ever manually *SSH*'ing into the production box. I use this, but again, please read more about this before attempting it just so you know whats going on if it doesn't work for you. It depends on various things. It's optional so you don't have to use these methods since we're talking about *deployment* and not *server management*, it's just a simple little extra that *Deployer* provides, nothing really fancy.
|
96
|
+
|
97
|
+
p. There are more tasks, but these will be your main commands. It's pretty straightforward.
|
98
|
+
|
99
|
+
p. To list all commands:
|
100
|
+
|
101
|
+
bc. cap -T
|
102
|
+
|
103
|
+
|
104
|
+
h3. Automated Tasks
|
105
|
+
|
106
|
+
p. *Deployer* will invoke various built-in tasks to try and deploy your application successfully.
|
107
|
+
|
108
|
+
p. On the initial deployment *cap deploy:initial*. This procedure only has to be performed once.
|
109
|
+
|
110
|
+
* It will setup the production environment, releases and shared folder
|
111
|
+
* It will populate the shared folder with the folders you specified in the deploy.rb file
|
112
|
+
* It will sync your applications *database.yml* file to the shared/db folder
|
113
|
+
* It will sync the *deployer.rake* task from the to the shared/lib/tasks folder
|
114
|
+
* It will deploy your application
|
115
|
+
|
116
|
+
p. And the deployment procedure that follows (*cap deploy*), does the following:
|
117
|
+
|
118
|
+
* It will create a new folder in the releases folder and deploy your application to it
|
119
|
+
* It will ensure that the shared folder has all the folders you specified in the *deploy.rb*
|
120
|
+
* It will setup built-in symlink setups for your database.yml, production log and deployer.rake
|
121
|
+
* It will also setup any additional symlinks you may have specified inside the *deploy.rb* from the release folder to the shared folder
|
122
|
+
* It will ensure all gems that are specified inside the *config/environment.rb* are installed. Will attempt to ignore exceptions
|
123
|
+
* It will ensure the database is present and migrated to the latest version
|
124
|
+
* It will then perform any *custom* tasks you might have specified inside the *deploy.rb* file within the *after_deploy* method definition
|
125
|
+
* It will then set the correct passenger permissions
|
126
|
+
* It will then restart passenger
|
127
|
+
|
128
|
+
p. The *cap deploy:initial* will call *cap deploy* at the end. So an initial version will be released. After that, just do the following to released a new version as you normally would:
|
129
|
+
|
130
|
+
bc. git add .
|
131
|
+
git commit -am "next version commit"
|
132
|
+
git push origin master
|
133
|
+
cap deploy
|
134
|
+
|
135
|
+
|
136
|
+
h2. Additional Configuration
|
137
|
+
|
138
|
+
*Shared Folders and Symlinks*
|
139
|
+
|
140
|
+
p. I wanted to keep this as simple as possible as well. By default, *Deployer* will create folders for storing the production.log in and other necessary stuff.
|
141
|
+
It will properly symlink it from the shared folder to the Rails application. However! You will most likely have some other things you must keep in a shared folder, such as assets
|
142
|
+
or other files. This can be done easily with *Deployer*.
|
143
|
+
|
144
|
+
p. Again, inside of config/deploy.rb
|
145
|
+
|
146
|
+
bc. set :additional_shared_folders,
|
147
|
+
%w(public/assets db)
|
148
|
+
|
149
|
+
p. In this example two paths will be created.
|
150
|
+
|
151
|
+
* /var/rails/:domain/shared/public/assets
|
152
|
+
* /var/rails/:domain/shared/db
|
153
|
+
|
154
|
+
p. *Deployer* will ensure these are available after every deployment. And will append any folders if you change the values here and re-deploy.
|
155
|
+
|
156
|
+
p. Now, what use are these folders if you do not have the ability to add symlinks from these folders to the application.
|
157
|
+
|
158
|
+
bc. set :additional_shared_symlinks,
|
159
|
+
%w(public/assets db/production.sqlite3)
|
160
|
+
|
161
|
+
p. In this example two symlinks will be created from the shared_path to the current Rails application release.
|
162
|
+
As you can see the first symlink is a "path" symlink, which does not point to a direct file, but rather a folder.
|
163
|
+
|
164
|
+
p. The second symlink will be a link from the shared/db/production.sqlite3 to the current rails applications' db/production.sqlite3 file.
|
165
|
+
|
166
|
+
*NOTE*
|
167
|
+
|
168
|
+
p. One important thing to note here is that notice how the symlinks are mirrored to the Rails applications folder structure. This will always be the case. If you have some crazy architecture inside your Rails application: *rails_root/my/awesome/folder/structure/is/very/long* then you MUST create the following folder structure for the shared path: *shared/my/awesome/folder/structure/is/very/long*. This is a convention and it saves a lot of overhead in your configuration file by just defining a path once and using that same path for both the current and shared path.
|
169
|
+
|
170
|
+
p. *Additional (Optional) (Server) Configuration*
|
171
|
+
|
172
|
+
p. Here you can specify that you want to pull/push from/to a git repository that's located on a DIFFERENT server. Leave this commented out or remove it if your git repository resides on the same server as your Rails application. If you choose to store your git repository on a separate server by uncommenting the following line, then you lose the ability to create/reset/destroy/reinitialize it through *Deployer*. This is no big deal though. All you have to do is create the git repository manually on that specific server and then issue the *git remote add origin repository_url* and it will work fine with the rest of *Deployer*.
|
173
|
+
|
174
|
+
bc. set :repository_url, "root@example.com:/path/to/repository.git"
|
175
|
+
|
176
|
+
p. And then here is the last bit of server configuration you can specify.
|
177
|
+
|
178
|
+
bc. # Default Configuration (Git/Repository Apache/NginX)
|
179
|
+
# The settings below are default, you do not need to set these, unless you want to specify other parameters.
|
180
|
+
# If you find that the settings below are fine, then you can leave them commented out or just remove them.
|
181
|
+
#
|
182
|
+
# set :apache_initialize_utility_path, '/etc/init.d/apache2' # Only applies if running Apache and using the Apache Tasks
|
183
|
+
# set :apache_sites_available_path, '/etc/apache2/sites-available' # Only applies if running Apache and using the Apache Tasks
|
184
|
+
# set :nginx_initialize_utility_path, '/etc/init.d/nginx' # Only applies if running NginX and using the NginX Tasks
|
185
|
+
# set :nginx_sites_enabled_path, '/opt/nginx/conf/sites-enabled' # Only applies if running NginX and using the NginX Tasks
|
186
|
+
|
187
|
+
p. Again, very straightforward. I even added comments. One thing to note here is that these are commented out by default and you don't have to "uncomment" them to get the defaults. If you like the default settings you can leave it commented out, or just remove the lines. Or of course, uncomment them and leave them unchanged. Whatever you want.
|
188
|
+
|
189
|
+
|
190
|
+
h3. *Adding Application Specific Deployment Tasks*
|
191
|
+
|
192
|
+
p. Inside the *namespace :deploy do* block you can define your own deployment tasks that are specific to your application.
|
193
|
+
|
194
|
+
bc.. # Application Specific Deployment Tasks
|
195
|
+
namespace :deploy do
|
196
|
+
|
197
|
+
desc "This is my custom task."
|
198
|
+
task :my_custom_task do
|
199
|
+
run "ls #{shared_path}"
|
200
|
+
end
|
201
|
+
|
202
|
+
namespace :nested do
|
203
|
+
desc "This is my nested custom task."
|
204
|
+
task :my_custom_task do
|
205
|
+
puts "ls #{shared_path}"
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
p. Again, very straightforward. Just define your tasks as you normally would with Capistrano.
|
214
|
+
Then, to invoke them during each deployment you must add them inside the *after_deploy*, method like so:
|
215
|
+
|
216
|
+
bc. def after_deploy
|
217
|
+
run_custom_task "my_custom_task"
|
218
|
+
run_custom_task "nested:my_custom_task"
|
219
|
+
end
|
220
|
+
|
221
|
+
p. This method will be invoked right before *Deployer* sets permissions on, and restarts the your Rails application.
|
222
|
+
|
223
|
+
|
224
|
+
h3. Built-in Additional Tasks
|
225
|
+
|
226
|
+
p. *Deployer* has some built-in tasks that are often used by developers.
|
227
|
+
|
228
|
+
p. *Whenever*, To update the crontab on deployment:
|
229
|
+
|
230
|
+
bc. def after_deploy
|
231
|
+
run_custom_task "whenever:update_crontab"
|
232
|
+
end
|
233
|
+
|
234
|
+
p. *Delayed Job*, To start/stop daemons
|
235
|
+
|
236
|
+
bc. def after_deploy
|
237
|
+
run_custom_task "delayed_job:start"
|
238
|
+
run_custom_task "delayed_job:start n=3" # "n" specifies the amount of daemons that should run
|
239
|
+
run_custom_task "delayed_job:stop"
|
240
|
+
end
|
241
|
+
|
242
|
+
|
243
|
+
h2. Assumptions / Conventions
|
244
|
+
|
245
|
+
p. Deployer favors Convention of Configuration. There are a few things you need to be aware of before you start using it. Just so it doesn't confuse you.
|
246
|
+
|
247
|
+
p. By filling in the 4 variables (ip, domain, subdomain, user) you are practically set to create a remote git repository, push your local repository to it, create your production environment, deploy to your production environment from your remote repository and even let *Deployer* parse the simple apache2 and nginx configuration vhost files and transfer them to the server. Of course, you can also just choose to do setup your virtual hosts manually, it is totally optional. The availability of this option depends on your OS architecture/webserver installation path.
|
248
|
+
|
249
|
+
p. Now, just to clear some things up with some facts about the conventions:
|
250
|
+
|
251
|
+
*Rails Application Deployment Path*
|
252
|
+
|
253
|
+
bc. /var/rails/:domain
|
254
|
+
|
255
|
+
*Git Repository Path* unless specified otherwise in the configuration file.
|
256
|
+
|
257
|
+
bc. /var/git/:domain.git
|
258
|
+
|
259
|
+
*If using the Apache2 create/destroy/restart/destroy_all features, Apache2's sites-available path must be the following*, unless specified otherwise in the configuration file.
|
260
|
+
|
261
|
+
bc. /etc/apache2/sites-available/
|
262
|
+
|
263
|
+
*If using the NginX create/destroy/restart/destroy_all features, NginX's sites-enabled path must be the following*, unless specified otherwise in the configuration file.
|
264
|
+
|
265
|
+
bc. /opt/nginx/conf/sites-enabled/
|
266
|
+
|
267
|
+
p. Additionally, you must be able to start/stop the NginX webserver through these commands: "/etc/init.d/nginx start" and "/etc/init.d/nginx stop"
|
268
|
+
If you don't have this functionality, but want it, check out: "http://github.com/meskyanichi/rails-nginx-passenger-ubuntu":http://github.com/meskyanichi/rails-nginx-passenger-ubuntu
|
269
|
+
For NginX you must also add this: *include sites-enabled/** inside the nginx configuration file, inside the *server{}* block to include all settings that *Deployer* transfers into the sites-enabled
|
270
|
+
|
271
|
+
* Assumes you are using Phusion Passenger for deployment
|
272
|
+
* Assumes Git Repository will be located on the same server as where the actual application will be deployed. Unless specified otherwise in the configuration file.
|
273
|
+
* The config/database.yml will be transferred to the shared/config/database.yml and symlinked to on the initial deployment. You can re-sync it later with *cap deploy:db:sync_yaml*.
|
274
|
+
* I have overwritten/adjusted the "rake gems:install" command in production mode to try and force a successful gem installation process.
|
275
|
+
There are occasions where there are unexpected exceptions raised when trying to issue the rake task. For example when you have an "Uninitialized Constant" inside the environment.rb which "is" initialized in development mode because you have the gem installed locally, but fails in the production environment because it does not have the gem. *Deployer* shall try to install any gem specified inside the config/environment.rb regardless of what exception is being raised to ensure all gem dependencies are installed on deployment.
|
276
|
+
|
277
|
+
|
278
|
+
*NOTE*
|
279
|
+
|
280
|
+
p. This is a _very early_ release. A lot may be subject to change, for the good!
|
281
|
+
|
282
|
+
|
283
|
+
h2. Suggestions, Requests, Idea's?
|
284
|
+
|
285
|
+
Tell, Ask, Fork and Help!
|
286
|
+
|
287
|
+
|
288
|
+
h2. Copyright
|
289
|
+
|
290
|
+
Copyright (c) 2010 Michael van Rooijen. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "deployer"
|
8
|
+
gem.summary = %Q{Deployer is a deployment engine (Ruby Gem) that enhances Capistrano with a set of useful automated deployment tasks. It favors convention over configuration, and it simplifies Rails Application Deployment with Capistrano.}
|
9
|
+
gem.description = %Q{Deployer is a deployment engine (Ruby Gem) that enhances Capistrano with a set of useful automated deployment tasks. It favors convention over configuration, and it simplifies Rails Application Deployment with Capistrano.}
|
10
|
+
gem.email = "meskyanichi@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/meskyanichi/deployer"
|
12
|
+
gem.authors = ["Michael van Rooijen"]
|
13
|
+
gem.add_dependency "capistrano", ">= 2.5.13"
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/test_*.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :test => :check_dependencies
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "deployer #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/enhancify
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
options = {}
|
4
|
+
|
5
|
+
optparse = OptionParser.new do |opts|
|
6
|
+
opts.banner = "\nUsage: enhancify [path]\n "
|
7
|
+
end
|
8
|
+
|
9
|
+
begin
|
10
|
+
optparse.parse!
|
11
|
+
rescue OptionParser::InvalidOption
|
12
|
+
puts "\nInvalid Option. See the list of available options below.\n"
|
13
|
+
puts optparse
|
14
|
+
puts "\n "
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
|
18
|
+
if ARGV.empty?
|
19
|
+
puts "Please specify the path to the Capfile."
|
20
|
+
puts "example: enhancify /path/to/rails_root"
|
21
|
+
exit
|
22
|
+
end
|
23
|
+
|
24
|
+
if Dir.entries(ARGV[0]).include?("Capfile")
|
25
|
+
puts "[Deployer] => Found Capfile!"
|
26
|
+
PATH = File.expand_path(ARGV[0])
|
27
|
+
CAPFILE = File.expand_path(File.join(ARGV[0], "Capfile"))
|
28
|
+
else
|
29
|
+
puts "[Deployer] => Could not find Capfile in #{File.expand_path(ARGV[0])}!"
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
|
33
|
+
if File.directory?(File.join(PATH, "config"))
|
34
|
+
puts "[Deployer] => Found config folder!"
|
35
|
+
else
|
36
|
+
puts "[Deployer] => Could not find the \"config\" folder. Creating it now!"
|
37
|
+
%x(mkdir #{File.join(PATH, 'config')})
|
38
|
+
end
|
39
|
+
|
40
|
+
if File.exist?(File.join(PATH, "config", "deploy.rb"))
|
41
|
+
old_versions = Dir.entries(File.join(PATH, 'config')).map {|entree| entree if entree =~ /deploy\.old\.(\d+)\.rb$/}.compact!
|
42
|
+
if old_versions.empty?
|
43
|
+
puts "[Deployer] => Found only the original version of deploy.rb. Renaming it to deploy.old.1.rb."
|
44
|
+
%x(mv #{File.join(PATH, 'config', 'deploy.rb')} #{File.join(PATH, 'config', 'deploy.old.1.rb')})
|
45
|
+
else
|
46
|
+
puts "[Deployer] => Found old versions of deploy.rb file."
|
47
|
+
version = old_versions.last.match('^deploy\.old\.(\d+)\.rb$')[1].to_i + 1
|
48
|
+
puts "[Deployer] => Renaming deploy.rb to deploy.old.#{version}.rb"
|
49
|
+
%x(mv #{File.join(PATH, 'config', 'deploy.rb')} #{File.join(PATH, 'config', "deploy.old.#{version}.rb")})
|
50
|
+
end
|
51
|
+
else
|
52
|
+
puts "[Deployer] => Could not find deploy.rb. Creating a new one!"
|
53
|
+
end
|
54
|
+
|
55
|
+
puts "[Deployer] => Writing new deploy.rb."
|
56
|
+
File.open(File.join(File.dirname(__FILE__), '..', 'setup', 'deploy.rb'), "r") do |template|
|
57
|
+
File.open(File.join(PATH, 'config', 'deploy.rb'), 'w') do |file|
|
58
|
+
file.write(template.read)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
unless File.open(File.join('Capfile'), 'r').read.include?('require "deployer/initializer"')
|
63
|
+
puts "[Deployer] => Adding Deployer Loader inside #{PATH}/Capfile."
|
64
|
+
File.open(File.join(PATH, 'Capfile'), "a") do |capfile|
|
65
|
+
capfile << <<-CAPFILE
|
66
|
+
\n
|
67
|
+
require "deployer/initializer"
|
68
|
+
load deployer
|
69
|
+
CAPFILE
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
puts "[Deployer] => Finished Enhancing Capistrano!"
|
74
|
+
exit
|
data/deployer.gemspec
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{deployer}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Michael van Rooijen"]
|
12
|
+
s.date = %q{2010-01-11}
|
13
|
+
s.default_executable = %q{enhancify}
|
14
|
+
s.description = %q{Deployer is a deployment engine (Ruby Gem) that enhances Capistrano with a set of useful automated deployment tasks. It favors convention over configuration, and it simplifies Rails Application Deployment with Capistrano.}
|
15
|
+
s.email = %q{meskyanichi@gmail.com}
|
16
|
+
s.executables = ["enhancify"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.textile"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".gitignore",
|
24
|
+
"LICENSE",
|
25
|
+
"README.textile",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/enhancify",
|
29
|
+
"deployer.gemspec",
|
30
|
+
"lib/deployer.rb",
|
31
|
+
"lib/deployer/helpers.rb",
|
32
|
+
"lib/deployer/initializer.rb",
|
33
|
+
"lib/deployer/tasks/deployer.rake",
|
34
|
+
"lib/tasks/apache.rb",
|
35
|
+
"lib/tasks/commands.rb",
|
36
|
+
"lib/tasks/db.rb",
|
37
|
+
"lib/tasks/environment.rb",
|
38
|
+
"lib/tasks/gems.rb",
|
39
|
+
"lib/tasks/global.rb",
|
40
|
+
"lib/tasks/nginx.rb",
|
41
|
+
"lib/tasks/passenger.rb",
|
42
|
+
"lib/tasks/plugin.rb",
|
43
|
+
"lib/tasks/repository.rb",
|
44
|
+
"setup/deploy.rb"
|
45
|
+
]
|
46
|
+
s.homepage = %q{http://github.com/meskyanichi/deployer}
|
47
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
48
|
+
s.require_paths = ["lib"]
|
49
|
+
s.rubygems_version = %q{1.3.5}
|
50
|
+
s.summary = %q{Deployer is a deployment engine (Ruby Gem) that enhances Capistrano with a set of useful automated deployment tasks. It favors convention over configuration, and it simplifies Rails Application Deployment with Capistrano.}
|
51
|
+
|
52
|
+
if s.respond_to? :specification_version then
|
53
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
54
|
+
s.specification_version = 3
|
55
|
+
|
56
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
57
|
+
s.add_runtime_dependency(%q<capistrano>, [">= 2.5.13"])
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<capistrano>, [">= 2.5.13"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<capistrano>, [">= 2.5.13"])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
data/lib/deployer.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Load Deployer Helpers
|
2
|
+
require File.join(File.dirname(__FILE__), 'deployer', 'helpers')
|
3
|
+
|
4
|
+
# This configuration is *conventional*
|
5
|
+
set :application, ip
|
6
|
+
set :deploy_to, "/var/rails/#{domain}"
|
7
|
+
set :repository_path, "/var/git/#{domain}.git"
|
8
|
+
set :repository, "#{user}@#{application}:#{repository_path}"
|
9
|
+
set :repository, repository_url if respond_to?(:repository_url)
|
10
|
+
|
11
|
+
set :scm, "git"
|
12
|
+
set :use_sudo, true
|
13
|
+
role :web, application
|
14
|
+
role :app, application
|
15
|
+
role :db, application
|
16
|
+
default_run_options[:pty] = true
|
17
|
+
|
18
|
+
# Default Configuration
|
19
|
+
set :remote, "origin" unless respond_to?(:remote)
|
20
|
+
set :branch, "master" unless respond_to?(:branch)
|
21
|
+
set :apache_initialize_utility_path, "/etc/init.d/apache2" unless respond_to?(:apache_initialize_utility_path)
|
22
|
+
set :apache_sites_available_path, "/etc/apache2/sites-available" unless respond_to?(:apache_sites_available_path)
|
23
|
+
set :nginx_initialize_utility_path, "/etc/init.d/nginx" unless respond_to?(:nginx_initialize_utility_path)
|
24
|
+
set :nginx_sites_enabled_path, "/opt/nginx/conf/sites-enabled" unless respond_to?(:nginx_sites_enabled_path)
|
25
|
+
|
26
|
+
# Load Deployment Tasks
|
27
|
+
load_tasks("global")
|
28
|
+
load_tasks("passenger")
|
29
|
+
load_tasks("apache")
|
30
|
+
load_tasks("nginx")
|
31
|
+
load_tasks("plugin")
|
32
|
+
load_tasks("db")
|
33
|
+
load_tasks("gems")
|
34
|
+
load_tasks("repository")
|
35
|
+
load_tasks("environment")
|
36
|
+
load_tasks("commands")
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Creates a tmp directory and writes Apache and NginX configuration files to it
|
2
|
+
def create_tmp_file(contents)
|
3
|
+
system 'mkdir tmp'
|
4
|
+
file = File.new("tmp/#{domain}", "w")
|
5
|
+
file << contents
|
6
|
+
file.close
|
7
|
+
end
|
8
|
+
|
9
|
+
# Alias for initializing custom deployment tasks
|
10
|
+
def run_custom_task(task)
|
11
|
+
system "cap deploy:#{task}"
|
12
|
+
end
|
13
|
+
|
14
|
+
# A Helper Method that assists in loading in tasks from the tasks folder
|
15
|
+
def load_tasks(tasks)
|
16
|
+
load File.join(File.dirname(__FILE__), '..', 'tasks', "#{tasks}.rb")
|
17
|
+
end
|
18
|
+
|
19
|
+
# A Method that logs a message
|
20
|
+
def log(message)
|
21
|
+
puts "\n\n[Deployer] => #{message}.. \n\n"
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns the RAILS_ENV=production string to reduce overhead
|
25
|
+
def env
|
26
|
+
"RAILS_ENV=production"
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
namespace :deployer_gems do
|
2
|
+
|
3
|
+
task :base do
|
4
|
+
begin
|
5
|
+
$gems_rake_task = true
|
6
|
+
require 'rubygems'
|
7
|
+
require 'rubygems/gem_runner'
|
8
|
+
Rake::Task[:environment].invoke
|
9
|
+
rescue
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Installs all required gems."
|
14
|
+
task :install => :base do
|
15
|
+
current_gems.each { |gem| gem.install }
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/lib/tasks/apache.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# apache_initialize_utility_path
|
2
|
+
# apache_sites_available_path
|
3
|
+
|
4
|
+
namespace :deploy do
|
5
|
+
namespace :apache do
|
6
|
+
|
7
|
+
desc "Adds Apache2 configuration and enables it."
|
8
|
+
task :create do
|
9
|
+
log "Adding Apache2 Virtual Host for #{domain}"
|
10
|
+
config = <<-CONFIG
|
11
|
+
<VirtualHost *:80>
|
12
|
+
ServerName #{domain}
|
13
|
+
#{unless subdomain then "ServerAlias www.#{domain}" end}
|
14
|
+
DocumentRoot #{File.join(deploy_to, 'current', 'public')}
|
15
|
+
</VirtualHost>
|
16
|
+
CONFIG
|
17
|
+
|
18
|
+
system 'mkdir tmp'
|
19
|
+
file = File.new("tmp/#{domain}", "w")
|
20
|
+
file << config
|
21
|
+
file.close
|
22
|
+
system "rsync -vr tmp/#{domain} #{user}@#{application}:#{File.join(apache_sites_available_path, domain)}"
|
23
|
+
File.delete("tmp/#{domain}")
|
24
|
+
run "sudo a2ensite #{domain}"
|
25
|
+
run "sudo #{apache_initialize_utility_path} restart"
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "Restarts Apache2."
|
29
|
+
task :restart do
|
30
|
+
run "sudo #{apache_initialize_utility_path} restart"
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Removes Apache2 configuration and disables it."
|
34
|
+
task :destroy do
|
35
|
+
log "Removing Apache2 Virtual Host for #{domain}"
|
36
|
+
begin run("a2dissite #{domain}"); rescue; end
|
37
|
+
begin run("sudo rm #{File.join(apache_sites_available_path, domain)}"); rescue; end
|
38
|
+
run("sudo #{apache_initialize_utility_path} restart")
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Destroys Git Repository, Rails Environment and Apache2 Configuration."
|
42
|
+
task :destroy_all do
|
43
|
+
system "cap deploy:repository:destroy"
|
44
|
+
run "rm -rf #{deploy_to}"
|
45
|
+
system "cap deploy:apache:destroy"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
namespace :deploy do
|
2
|
+
namespace :remote_command do
|
3
|
+
|
4
|
+
desc "Run a command from the Rails Root on the remote server. Specify command='my_command'."
|
5
|
+
task :rails_root do
|
6
|
+
log "Executing \"#{ENV['command']}\" from the Rails Root on the server."
|
7
|
+
run "cd #{current_path}; #{ENV['command']}"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Run a command on the remote server. Specify command='my_command'."
|
11
|
+
task :default do
|
12
|
+
log "Executing \"#{ENV['command']}\" on the server."
|
13
|
+
run "#{ENV['command']}"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/lib/tasks/db.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
namespace :deploy do
|
2
|
+
namespace :db do
|
3
|
+
|
4
|
+
desc "Syncs the database.yml file from the local machine to the remote machine"
|
5
|
+
task :sync_yaml do
|
6
|
+
log "Syncing database yaml to the production server"
|
7
|
+
unless File.exist?("config/database.yml")
|
8
|
+
puts "There is no config/database.yml.\n "
|
9
|
+
exit
|
10
|
+
end
|
11
|
+
system "rsync -vr --exclude='.DS_Store' config/database.yml #{user}@#{application}:#{shared_path}/config/"
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Create Production Database"
|
15
|
+
task :create do
|
16
|
+
log "Creating the Production Database"
|
17
|
+
run "cd #{current_path}; rake db:create #{env}"
|
18
|
+
end
|
19
|
+
|
20
|
+
namespace :migrate do
|
21
|
+
|
22
|
+
desc "Migrate Production Database"
|
23
|
+
task :default do
|
24
|
+
log "Migrating the Production Database"
|
25
|
+
run "cd #{current_path}; rake db:migrate #{env}"
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "Resets the Production Database"
|
29
|
+
task :reset do
|
30
|
+
log "Resetting the Production Database"
|
31
|
+
run "cd #{current_path}; rake db:migrate:reset #{env}"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Destroys Production Database"
|
37
|
+
task :drop do
|
38
|
+
log "Destroying the Production Database"
|
39
|
+
run "cd #{current_path}; rake db:drop #{env}"
|
40
|
+
end
|
41
|
+
|
42
|
+
desc "Populates the Production Database"
|
43
|
+
task :seed do
|
44
|
+
log "Populating the Production Database"
|
45
|
+
run "cd #{current_path}; rake db:seed #{env}"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
namespace :deploy do
|
2
|
+
namespace :environment do
|
3
|
+
|
4
|
+
desc "Creates the production environment"
|
5
|
+
task :create do
|
6
|
+
system "cap deploy:setup"
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "Destroys the production environment"
|
10
|
+
task :destroy do
|
11
|
+
run "rm -rf #{deploy_to}"
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Resets the production environment"
|
15
|
+
task :reset do
|
16
|
+
run "rm -rf #{deploy_to}"
|
17
|
+
system "cap deploy:setup"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/lib/tasks/gems.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
namespace :deploy do
|
2
|
+
namespace :gems do
|
3
|
+
|
4
|
+
desc "Installs any 'not-yet-installed' gems on the production server or a single gem when the gem= is specified."
|
5
|
+
task :install do
|
6
|
+
if ENV['gem']
|
7
|
+
log "Installing #{ENV['gem']}"
|
8
|
+
run "gem install #{ENV['gem']}"
|
9
|
+
else
|
10
|
+
log "Installing gem dependencies"
|
11
|
+
run "cd #{current_path}; rake deployer_gems:install #{env}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
data/lib/tasks/global.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
namespace :deploy do
|
2
|
+
|
3
|
+
desc "Initializes a bunch of tasks in order after the last deployment process."
|
4
|
+
task :restart do
|
5
|
+
system "cap deploy:setup_shared_path"
|
6
|
+
system "cap deploy:setup_symlinks"
|
7
|
+
system "cap deploy:gems:install"
|
8
|
+
system "cap deploy:db:create"
|
9
|
+
system "cap deploy:db:migrate"
|
10
|
+
after_deploy if respond_to?(:after_deploy)
|
11
|
+
system "cap deploy:set_permissions"
|
12
|
+
system "cap deploy:passenger:restart"
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Executes the initial procedures for deploying a Ruby on Rails Application."
|
16
|
+
task :initial do
|
17
|
+
system "cap deploy:setup"
|
18
|
+
system "cap deploy:setup_shared_path"
|
19
|
+
system "cap deploy:db:sync_yaml"
|
20
|
+
system "cap deploy:sync_tasks"
|
21
|
+
system "cap deploy"
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Sets permissions for Rails Application"
|
25
|
+
task :set_permissions do
|
26
|
+
log "Setting Permissions"
|
27
|
+
run "chown -R www-data:www-data #{deploy_to}"
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Creates symbolic links from shared folder"
|
31
|
+
task :setup_symlinks do
|
32
|
+
log "Setting up Symbolic Links"
|
33
|
+
run "mkdir -p #{File.join(current_path, 'lib', 'tasks')}"
|
34
|
+
shared_symlinks = %w(config/database.yml lib/tasks/deployer.rake)
|
35
|
+
shared_symlinks += additional_shared_symlinks if respond_to?(:additional_shared_symlinks)
|
36
|
+
shared_symlinks.each do |symlink|
|
37
|
+
run "ln -nfs #{File.join(shared_path, symlink)} #{File.join(current_path, symlink)}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Sets up the shared path"
|
42
|
+
task :setup_shared_path do
|
43
|
+
log "Setting up the shared path"
|
44
|
+
shared_folders = %w(config lib/tasks)
|
45
|
+
shared_folders += additional_shared_folders if respond_to?(:additional_shared_folders)
|
46
|
+
shared_folders.each do |folder|
|
47
|
+
run "mkdir -p #{shared_path}/#{folder}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "Syncs the rake tasks for installing gems."
|
52
|
+
task :sync_tasks do
|
53
|
+
log "Adding Deployer Rake tasks to shared path."
|
54
|
+
system "rsync -vr --exclude='.DS_Store' #{File.join(File.dirname(__FILE__), '..', 'deployer', 'tasks', 'deployer.rake')} #{user}@#{application}:#{File.join(shared_path, 'lib', 'tasks')}"
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
data/lib/tasks/nginx.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
namespace :deploy do
|
2
|
+
namespace :nginx do
|
3
|
+
|
4
|
+
desc "Adds NginX configuration and enables it."
|
5
|
+
task :create do
|
6
|
+
log "Adding NginX Virtual Host for #{domain}"
|
7
|
+
config = <<-CONFIG
|
8
|
+
server {
|
9
|
+
listen 80;
|
10
|
+
server_name #{unless subdomain then "www.#{domain} #{domain}" else domain end};
|
11
|
+
root #{File.join(deploy_to, 'current', 'public')};
|
12
|
+
passenger_enabled on;
|
13
|
+
}
|
14
|
+
CONFIG
|
15
|
+
|
16
|
+
create_tmp_file(config)
|
17
|
+
run "mkdir -p #{nginx_sites_enabled_path}"
|
18
|
+
system "rsync -vr tmp/#{domain} #{user}@#{application}:#{File.join(nginx_sites_enabled_path, domain)}"
|
19
|
+
File.delete("tmp/#{domain}")
|
20
|
+
system 'cap deploy:nginx:restart'
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Restarts NginX."
|
24
|
+
task :restart do
|
25
|
+
Net::SSH.start(application, user) {|ssh| ssh.exec "#{nginx_initialize_utility_path} stop"}
|
26
|
+
Net::SSH.start(application, user) {|ssh| ssh.exec "#{nginx_initialize_utility_path} start"}
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Removes NginX configuration and disables it."
|
30
|
+
task :destroy do
|
31
|
+
log "Removing NginX Virtual Host for #{domain}"
|
32
|
+
begin
|
33
|
+
run("rm #{File.join(nginx_sites_enabled_path, domain)}")
|
34
|
+
ensure
|
35
|
+
system 'cap deploy:nginx:restart'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "Destroys Git Repository, Rails Environment and Nginx Configuration."
|
40
|
+
task :destroy_all do
|
41
|
+
system "cap deploy:repository:destroy"
|
42
|
+
run "rm -rf #{deploy_to}"
|
43
|
+
system "cap deploy:nginx:destroy"
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
data/lib/tasks/plugin.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
namespace :deploy do
|
2
|
+
namespace :whenever do
|
3
|
+
|
4
|
+
desc "Update the crontab file for the Whenever Gem."
|
5
|
+
task :update_crontab, :roles => :db do
|
6
|
+
log "Updating the Crontab"
|
7
|
+
run "cd #{release_path} && whenever --update-crontab #{domain}"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
namespace :delayed_job do
|
12
|
+
desc "Starts the Delayed Job Daemon(s)."
|
13
|
+
task :start do
|
14
|
+
log "Starting #{(ENV['n'] + ' ') if ENV['n']}Delayed Job Daemon(s)"
|
15
|
+
run "#{env} #{current_path}/script/delayed_job #{"-n #{ENV['n']} " if ENV['n']}start"
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Stops the Delayed Job Daemon(s)."
|
19
|
+
task :stop do
|
20
|
+
log "Stopping Delayed Job Daemon(s)"
|
21
|
+
run "#{env} #{current_path}/script/delayed_job stop"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
namespace :deploy do
|
2
|
+
namespace :repository do
|
3
|
+
|
4
|
+
task :base do
|
5
|
+
if respond_to?(:repository_url)
|
6
|
+
log "You cannot interact with your repository through Deployer Tasks as long as you have the \"repository_url\" defined."
|
7
|
+
log "Deployer only handles repositories that are located on the same server location as to where the actual Rails Application will be deployed."
|
8
|
+
log "If you wish to have this functionality, please comment out the \"repository_url\" inside the config/deploy.rb."
|
9
|
+
log "If you wish to use the git repository from a different server, then manually add it to git: git remote add origin repository_url"
|
10
|
+
exit
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Creates the remote Git repository."
|
15
|
+
task :create do
|
16
|
+
base
|
17
|
+
log "Creating remote Git repository"
|
18
|
+
run "mkdir -p #{repository_path}"
|
19
|
+
run "cd #{repository_path} && git --bare init"
|
20
|
+
system "git remote rm #{remote}"
|
21
|
+
system "git remote add #{remote} #{repository[:repository]}"
|
22
|
+
p "#{repository[:repository]} was added to your git repository as #{remote}/master."
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Creates the remote Git repository."
|
26
|
+
task :destroy do
|
27
|
+
base
|
28
|
+
log "destroying remote Git repository"
|
29
|
+
run "rm -rf #{repository_path}"
|
30
|
+
system "git remote rm #{remote}"
|
31
|
+
p "#{repository[:repository]} (#{remote}/master) was removed from your git repository."
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Resets the remote Git repository."
|
35
|
+
task :reset do
|
36
|
+
base
|
37
|
+
log "Resetting remove Git repository"
|
38
|
+
system "cap deploy:repository:destroy"
|
39
|
+
system "cap deploy:repository:create"
|
40
|
+
end
|
41
|
+
|
42
|
+
desc "Reinitializes #{remote}/master."
|
43
|
+
task :reinitialize do
|
44
|
+
base
|
45
|
+
system "git remote rm #{remote}"
|
46
|
+
system "git remote add #{remote} #{repository[:repository]}"
|
47
|
+
p "#{repository[:repository]} (#{remote}/master) was added to your git repository."
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
data/setup/deploy.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# Quick Reference
|
2
|
+
# Configure the essential configurations below and do the following:
|
3
|
+
#
|
4
|
+
# For more information:
|
5
|
+
# http://github.com/meskyanichi/deployer
|
6
|
+
#
|
7
|
+
# Create Local and Remote Repository:
|
8
|
+
# git init
|
9
|
+
# cap deploy:repository:create
|
10
|
+
#
|
11
|
+
# Initial Deployment:
|
12
|
+
# git add .
|
13
|
+
# git commit -am "Initial commit for deployment"
|
14
|
+
# git push origin master
|
15
|
+
# cap deploy:initial
|
16
|
+
#
|
17
|
+
# Then For Every Update Just Do:
|
18
|
+
# git add .
|
19
|
+
# git commit -am "some other commit"
|
20
|
+
# git push origin master
|
21
|
+
# cap deploy
|
22
|
+
#
|
23
|
+
# For Apache2 Users
|
24
|
+
# cap deploy:apache:create
|
25
|
+
# cap deploy:apache:destroy
|
26
|
+
# cap deploy:apache:restart
|
27
|
+
# cap deploy:apache:destroy_all
|
28
|
+
#
|
29
|
+
# For NginX Users
|
30
|
+
# cap deploy:nginx:create
|
31
|
+
# cap deploy:nginx:destroy
|
32
|
+
# cap deploy:nginx:restart
|
33
|
+
# cap deploy:nginx:destroy_all
|
34
|
+
#
|
35
|
+
# For a Full List of Commands
|
36
|
+
# cap -T
|
37
|
+
|
38
|
+
|
39
|
+
# Essential Configuration
|
40
|
+
# Assumes Application and Git Repository are located on the same server
|
41
|
+
set :ip, "123.45.678.90" # the ip address that points to your production server
|
42
|
+
set :user, "root" # the user that will connect to the production server
|
43
|
+
set :remote, "origin" # the remote that should be deployed
|
44
|
+
set :branch, "master" # the branch that should be deployed
|
45
|
+
set :domain, "example.com" # (or set :domain, "subdomain.example.com"
|
46
|
+
set :subdomain, false # and set :subdomain, true)
|
47
|
+
|
48
|
+
# Optional
|
49
|
+
# If the Git Repository resides/should reside on a different server than where the application deploys,
|
50
|
+
# then uncomment the following line and specify the repository_url/user
|
51
|
+
# NOTE: The Tasks "cap deploy:repository:create/destroy/reset" won't work if you use this!
|
52
|
+
# You will have to manually create the repository yourself on the specified server.
|
53
|
+
#
|
54
|
+
# set :repository_url, "root@example.com:/path/to/repository.git"
|
55
|
+
|
56
|
+
|
57
|
+
# Set up additional shared folders
|
58
|
+
set :additional_shared_folders,
|
59
|
+
%w(public/assets db)
|
60
|
+
|
61
|
+
# Set up additional shared symlinks
|
62
|
+
# These are mirrored to the Rails Applications' structure
|
63
|
+
# public/assets = RAILS_ROOT/public/assets => SHARED_PATH/public/assets
|
64
|
+
# db/production.sqlite3 = RAILS_ROOT/db/production.sqlite3 => SHARED_PATH/db/production.sqlite3
|
65
|
+
set :additional_shared_symlinks,
|
66
|
+
%w(public/assets db/production.sqlite3)
|
67
|
+
|
68
|
+
|
69
|
+
# Additional Application Specific Tasks and Callbacks
|
70
|
+
# In here you can specify which Application Specific tasks you would like to run right before the application
|
71
|
+
# re-sets permissions and restarts passenger. You invoke the by simply calling "run_custom_task".
|
72
|
+
#
|
73
|
+
def after_deploy
|
74
|
+
run_custom_task "my_custom_task"
|
75
|
+
run_custom_task "nested:my_custom_task"
|
76
|
+
end
|
77
|
+
|
78
|
+
# Application Specific Deployment Tasks
|
79
|
+
# In here you may specify any application specific and/or other tasks that are not handled by Deployer
|
80
|
+
namespace :deploy do
|
81
|
+
desc "This is my custom task."
|
82
|
+
task :my_custom_task do
|
83
|
+
run "ls -la #{shared_path}"
|
84
|
+
end
|
85
|
+
|
86
|
+
namespace :nested do
|
87
|
+
desc "This is my nested custom task."
|
88
|
+
task :my_custom_task do
|
89
|
+
system "ls -la"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
# Default Configuration Apache/NginX
|
96
|
+
# The settings below are default, you do not need to set these, unless you want to specify other parameters.
|
97
|
+
# If you find that the settings below are fine, then you can leave them commented out or just remove them.
|
98
|
+
#
|
99
|
+
# set :apache_initialize_utility_path, '/etc/init.d/apache2' # Only applies if running Apache and using the Apache Tasks
|
100
|
+
# set :apache_sites_available_path, '/etc/apache2/sites-available' # Only applies if running Apache and using the Apache Tasks
|
101
|
+
# set :nginx_initialize_utility_path, '/etc/init.d/nginx' # Only applies if running NginX and using the NginX Tasks
|
102
|
+
# set :nginx_sites_enabled_path, '/opt/nginx/conf/sites-enabled' # Only applies if running NginX and using the NginX Tasks
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: deployer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael van Rooijen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-11 00:00:00 +01:00
|
13
|
+
default_executable: enhancify
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: capistrano
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.5.13
|
24
|
+
version:
|
25
|
+
description: Deployer is a deployment engine (Ruby Gem) that enhances Capistrano with a set of useful automated deployment tasks. It favors convention over configuration, and it simplifies Rails Application Deployment with Capistrano.
|
26
|
+
email: meskyanichi@gmail.com
|
27
|
+
executables:
|
28
|
+
- enhancify
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.textile
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.textile
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- bin/enhancify
|
42
|
+
- deployer.gemspec
|
43
|
+
- lib/deployer.rb
|
44
|
+
- lib/deployer/helpers.rb
|
45
|
+
- lib/deployer/initializer.rb
|
46
|
+
- lib/deployer/tasks/deployer.rake
|
47
|
+
- lib/tasks/apache.rb
|
48
|
+
- lib/tasks/commands.rb
|
49
|
+
- lib/tasks/db.rb
|
50
|
+
- lib/tasks/environment.rb
|
51
|
+
- lib/tasks/gems.rb
|
52
|
+
- lib/tasks/global.rb
|
53
|
+
- lib/tasks/nginx.rb
|
54
|
+
- lib/tasks/passenger.rb
|
55
|
+
- lib/tasks/plugin.rb
|
56
|
+
- lib/tasks/repository.rb
|
57
|
+
- setup/deploy.rb
|
58
|
+
has_rdoc: true
|
59
|
+
homepage: http://github.com/meskyanichi/deployer
|
60
|
+
licenses: []
|
61
|
+
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options:
|
64
|
+
- --charset=UTF-8
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.3.5
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Deployer is a deployment engine (Ruby Gem) that enhances Capistrano with a set of useful automated deployment tasks. It favors convention over configuration, and it simplifies Rails Application Deployment with Capistrano.
|
86
|
+
test_files: []
|
87
|
+
|