zend-framework-deploy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem "capistrano", "~> 2.5"
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.0"
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Fabio Napoleoni
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.markdown ADDED
@@ -0,0 +1,91 @@
1
+ # Deploying Zend Framework applications with zend-framework-deploy
2
+
3
+ Tired to manually deploy your Zend Framework projects, this gem is for you. It will use
4
+ the Capistrano framework adapted to fit ZF structure and files and removes Rails specific tasks.
5
+
6
+ ## Installation
7
+
8
+ $ gem install zend-framework-deploy
9
+
10
+ ## Usage
11
+
12
+ $ cd your-zf-project-root && zf-capify .
13
+
14
+ This command will create the required files inside your ZF project. You can also use `-m` switch to
15
+ use the [multistage extension](https://boxpanel.bluebox.net/public/the_vault/index.php/Capistrano_Multi_Stage_Instructions)
16
+ of capistrano. The `-m` switch accepts a comma separated list of stages to create.
17
+
18
+ ## Requirements
19
+
20
+ It depends on `capistrano` gem. If you want multistage support you should also install
21
+ `capistano-ext` gem (it's not listed as dependency). [RVM](http://rvm.beginrescueend.com/) is
22
+ strongly advised to install Ruby and RubyGems.
23
+
24
+ ## What tasks are included in the gem?
25
+
26
+ These are the tasks adapted for Zend Framework projects included in my gem
27
+
28
+ cap deploy # Deploys your project.
29
+ cap deploy:check # Test deployment dependencies.
30
+ cap deploy:cleanup # Clean up old releases.
31
+ cap deploy:install_zf # Install Zend Framework in library path for the dep...
32
+ cap deploy:pending # Displays the commits since your last deploy.
33
+ cap deploy:pending:diff # Displays the `diff' since your last deploy.
34
+ cap deploy:rollback # Rolls back to a previous version and restarts.
35
+ cap deploy:rollback:code # Rolls back to the previously deployed version.
36
+ cap deploy:setup # Prepares one or more servers for deployment.
37
+ cap deploy:symlink # Updates the symlink to the most recently deployed ...
38
+ cap deploy:update # Copies your project and updates the symlink.
39
+ cap deploy:update_code # Copies your project to the remote servers.
40
+ cap deploy:upload # Copy files to the currently deployed version.
41
+ cap invoke # Invoke a single command on the remote servers.
42
+ cap shell # Begin an interactive Capistrano session.
43
+ cap web:disable # Present a maintenance page to visitors.
44
+ cap web:enable # Makes the application web-accessible again.
45
+
46
+ ## Zend Framework installation
47
+
48
+ This gem provides a task named deploy:install_zf which is called by default deploy. This task relies on
49
+ `zf_path` capistrano variable, so you must provide it in your `deploy.rb` file. This variable should contain
50
+ the path for the ZF release, or if you have more than one version of ZF in your server, the base path for the
51
+ installations. In the latter case you should have a dir structure like this one (in my case `zf_path` is set
52
+ to `'/var/zend/`)
53
+
54
+ $ ls /var/zend/
55
+ ZendFramework-1.11.0
56
+ ZendFramework-1.11.5
57
+
58
+ When you're following this convention you can use a file in your scm to control what version of ZF is copied
59
+ in the library folder. To achieve this simply drop a file named `zf.version` in your `application/configs` folder
60
+ containing the required ZF version and the corresponding version is linked in your library folder.
61
+
62
+ This approach works as far as your `index.php` contains the code generated from the zf tool, i.e. the following
63
+ snippet of code is executed before requiring any ZF class.
64
+
65
+ // Ensure library/ is on include_path
66
+ set_include_path(implode(PATH_SEPARATOR, array(
67
+ realpath(APPLICATION_PATH . '/../library'),
68
+ get_include_path(),
69
+ )));
70
+
71
+ I prepared a sample empty zf-capified application on github, you can fork it [here](https://github.com/fabn/zf-capified-sample)
72
+
73
+ ## Thanks to
74
+
75
+ * Lee Hambley for his [Railsless Deploy Gem](https://github.com/leehambley/railsless-deploy)
76
+
77
+ ## Contributing to zend-framework-deploy
78
+
79
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
80
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
81
+ * Fork the project
82
+ * Start a feature/bugfix branch
83
+ * Commit and push until you are happy with your contribution
84
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
85
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
86
+
87
+ ## Copyright
88
+
89
+ Copyright (c) 2011 Fabio Napoleoni. See LICENSE.txt for
90
+ further details.
91
+
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "zend-framework-deploy"
18
+ gem.homepage = "http://github.com/fabn/zend-framework-deploy"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Deploy Zend Framework applications with Capistrano}
21
+ gem.description = %Q{Use this gem to deploy Zend Framework projects with Capistrano. It will adapt Capistrano configuration in order to be used with ZF project structure.}
22
+ gem.email = "f.napoleoni@gmail.com"
23
+ gem.authors = ["Fabio Napoleoni"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/zf-capify ADDED
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'fileutils'
5
+
6
+ CONFIG_DIR = 'application/configs'
7
+ stages = []
8
+
9
+ OptionParser.new do |opts|
10
+ opts.banner = "Usage: #{File.basename($0)} [path]"
11
+
12
+ opts.on("-m [stage1,stage2]", "--multistage [stage1,stage2]", Array, "Uses multistage configuration") do |stges|
13
+ stages = stges
14
+ end
15
+
16
+ opts.on("-h", "--help", "Displays this help info") do
17
+ puts opts
18
+ exit 0
19
+ end
20
+
21
+ begin
22
+ opts.parse!(ARGV)
23
+ rescue OptionParser::ParseError => e
24
+ warn e.message
25
+ puts opts
26
+ exit 1
27
+ end
28
+ end
29
+
30
+ if ARGV.empty?
31
+ abort "Please specify the directory to capify, e.g. `#{File.basename($0)} .'"
32
+ elsif !File.exists?(ARGV.first)
33
+ abort "`#{ARGV.first}' does not exist."
34
+ elsif !File.directory?(ARGV.first)
35
+ abort "`#{ARGV.first}' is not a directory."
36
+ elsif ARGV.length > 1
37
+ abort "Too many arguments; please specify only the directory to capify."
38
+ end
39
+
40
+ def unindent(string)
41
+ indentation = string[/\A\s*/]
42
+ string.strip.gsub(/^#{indentation}/, "")
43
+ end
44
+
45
+ files = {
46
+ "Capfile" => unindent(<<-FILE),
47
+ require 'rubygems'
48
+ require 'zend-framework-deploy'
49
+ load '#{CONFIG_DIR}/deploy'
50
+ FILE
51
+
52
+ "#{CONFIG_DIR}/deploy.rb" => 'set :application, "set your application name here"
53
+ set :repository, "set your repository location here"
54
+ set :deploy_to, "set path where to deploy application"
55
+ set :zf_path, "set Zend Framework (remote) installation path here"
56
+
57
+ set :scm, :subversion
58
+ # Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
59
+
60
+ role :web, "your web-server here" # Your HTTP server, Apache/etc
61
+ '}
62
+
63
+ # multistage patch
64
+ unless stages.empty?
65
+ files["#{CONFIG_DIR}/deploy.rb"] << <<-MULTI
66
+
67
+ # multistage setup, see https://boxpanel.bluebox.net/public/the_vault/index.php/Capistrano_Multi_Stage_Instructions
68
+ set :default_stage, "#{stages.first}"
69
+ set :stages, %w(#{stages.join(' ')})
70
+ require 'capistrano/ext/multistage'
71
+ MULTI
72
+ files.merge!(
73
+ stages.inject({}) do |hash, file|
74
+ hash["#{CONFIG_DIR}/deploy/" + file + '.rb'] = "# #{file} stage configuration goes here\n"
75
+ hash
76
+ end
77
+ )
78
+ puts "Multistage configuration selected, remember to install capistrano-ext gem with '[sudo] gem install capistrano-ext'"
79
+ end
80
+
81
+ base = ARGV.shift
82
+ files.each do |file, content|
83
+ file = File.join(base, file)
84
+ if File.exists?(file)
85
+ warn "[skip] '#{file}' already exists"
86
+ elsif File.exists?(file.downcase)
87
+ warn "[skip] '#{file.downcase}' exists, which could conflict with `#{file}'"
88
+ else
89
+ unless File.exists?(File.dirname(file))
90
+ puts "[add] making directory '#{File.dirname(file)}'"
91
+ FileUtils.mkdir(File.dirname(file))
92
+ end
93
+ puts "[add] writing '#{file}'"
94
+ File.open(file, "w") { |f| f.write(content) }
95
+ end
96
+ end
97
+
98
+ puts "[done] zf-capified!"
@@ -0,0 +1,498 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ require 'capistrano/recipes/deploy/scm'
4
+ require 'capistrano/recipes/deploy/strategy'
5
+
6
+ def _cset(name, *args, &block)
7
+ unless exists?(name)
8
+ set(name, *args, &block)
9
+ end
10
+ end
11
+
12
+ # =========================================================================
13
+ # These variables MUST be set in the client capfiles. If they are not set,
14
+ # the deploy will fail with an error.
15
+ # =========================================================================
16
+
17
+ _cset(:application) { abort "Please specify the name of your application, set :application, 'foo'" }
18
+ _cset(:repository) { abort "Please specify the repository that houses your application's code, set :repository, 'foo'" }
19
+ # this should be required
20
+ _cset(:deploy_to) { abort "Please specify where to deploy your application, set :deploy_to, '/some/path'" }
21
+ # zend framework(s) path installation (we don't have bundler...)
22
+ _cset(:zf_path) { abort "Please specify where is located zend framework on server, set :zf_path, '/path/to/zend/framework'" }
23
+
24
+ # =========================================================================
25
+ # These variables may be set in the client capfile if their default values
26
+ # are not sufficient.
27
+ # =========================================================================
28
+
29
+ _cset :scm, :subversion
30
+ _cset :deploy_via, :checkout
31
+
32
+ _cset(:revision) { source.head }
33
+ # multistage config directory
34
+ _cset:stage_dir, "application/configs/deploy"
35
+
36
+ # =========================================================================
37
+ # These variables should NOT be changed unless you are very confident in
38
+ # what you are doing. Make sure you understand all the implications of your
39
+ # changes if you do decide to muck with these!
40
+ # =========================================================================
41
+
42
+ _cset(:source) { Capistrano::Deploy::SCM.new(scm, self) }
43
+ _cset(:real_revision) { source.local.query_revision(revision) { |cmd| with_env("LC_ALL", "C") { run_locally(cmd) } } }
44
+
45
+ _cset(:strategy) { Capistrano::Deploy::Strategy.new(deploy_via, self) }
46
+
47
+ _cset(:release_name) { set :deploy_timestamped, true; Time.now.utc.strftime("%Y%m%d%H%M%S") }
48
+
49
+ _cset :version_dir, "releases"
50
+ _cset :shared_dir, "shared"
51
+ # makes directories used by zend framework default project structure, see http://framework.zend.com/manual/en/project-structure.project.html
52
+ _cset :shared_children, %w(system data) + %w(cache indexes locales logs sessions uploads).map { |d| File.join("data", d) }
53
+ _cset :current_dir, "current"
54
+
55
+ _cset(:releases_path) { File.join(deploy_to, version_dir) }
56
+ _cset(:shared_path) { File.join(deploy_to, shared_dir) }
57
+ _cset(:current_path) { File.join(deploy_to, current_dir) }
58
+ _cset(:release_path) { File.join(releases_path, release_name) }
59
+
60
+ _cset(:releases) { capture("ls -xt #{releases_path}").split.reverse }
61
+ _cset(:current_release) { File.join(releases_path, releases.last) }
62
+ _cset(:previous_release) { releases.length > 1 ? File.join(releases_path, releases[-2]) : nil }
63
+
64
+ _cset(:current_revision) { capture("cat #{current_path}/REVISION").chomp }
65
+ _cset(:latest_revision) { capture("cat #{current_release}/REVISION").chomp }
66
+ _cset(:previous_revision) { capture("cat #{previous_release}/REVISION").chomp }
67
+
68
+ _cset(:run_method) { fetch(:use_sudo, true) ? :sudo : :run }
69
+
70
+ # some tasks, like symlink, need to always point at the latest release, but
71
+ # they can also (occassionally) be called standalone. In the standalone case,
72
+ # the timestamped release_path will be inaccurate, since the directory won't
73
+ # actually exist. This variable lets tasks like symlink work either in the
74
+ # standalone case, or during deployment.
75
+ _cset(:latest_release) { exists?(:deploy_timestamped) ? release_path : current_release }
76
+
77
+ # Maintenance base filename
78
+ _cset :maintenance_basename, "maintenance"
79
+
80
+ # =========================================================================
81
+ # These are helper methods that will be available to your recipes.
82
+ # =========================================================================
83
+
84
+ # Auxiliary helper method for the `deploy:check' task. Lets you set up your
85
+ # own dependencies.
86
+ def depend(location, type, *args)
87
+ deps = fetch(:dependencies, {})
88
+ deps[location] ||= {}
89
+ deps[location][type] ||= []
90
+ deps[location][type] << args
91
+ set :dependencies, deps
92
+ end
93
+
94
+ # Temporarily sets an environment variable, yields to a block, and restores
95
+ # the value when it is done.
96
+ def with_env(name, value)
97
+ saved, ENV[name] = ENV[name], value
98
+ yield
99
+ ensure
100
+ ENV[name] = saved
101
+ end
102
+
103
+ # logs the command then executes it locally.
104
+ # returns the command output as a string
105
+ def run_locally(cmd)
106
+ logger.trace "executing locally: #{cmd.inspect}" if logger
107
+ `#{cmd}`
108
+ end
109
+
110
+ # If a command is given, this will try to execute the given command, as
111
+ # described below. Otherwise, it will return a string for use in embedding in
112
+ # another command, for executing that command as described below.
113
+ #
114
+ # If :run_method is :sudo (or :use_sudo is true), this executes the given command
115
+ # via +sudo+. Otherwise is uses +run+. If :as is given as a key, it will be
116
+ # passed as the user to sudo as, if using sudo. If the :as key is not given,
117
+ # it will default to whatever the value of the :admin_runner variable is,
118
+ # which (by default) is unset.
119
+ #
120
+ # THUS, if you want to try to run something via sudo, and what to use the
121
+ # root user, you'd just to try_sudo('something'). If you wanted to try_sudo as
122
+ # someone else, you'd just do try_sudo('something', :as => "bob"). If you
123
+ # always wanted sudo to run as a particular user, you could do
124
+ # set(:admin_runner, "bob").
125
+ def try_sudo(*args)
126
+ options = args.last.is_a?(Hash) ? args.pop : {}
127
+ command = args.shift
128
+ raise ArgumentError, "too many arguments" if args.any?
129
+
130
+ as = options.fetch(:as, fetch(:admin_runner, nil))
131
+ via = fetch(:run_method, :sudo)
132
+ if command
133
+ invoke_command(command, :via => via, :as => as)
134
+ elsif via == :sudo
135
+ sudo(:as => as)
136
+ else
137
+ ""
138
+ end
139
+ end
140
+
141
+ # Same as sudo, but tries sudo with :as set to the value of the :runner
142
+ # variable (which defaults to "app").
143
+ def try_runner(*args)
144
+ options = args.last.is_a?(Hash) ? args.pop : {}
145
+ args << options.merge(:as => fetch(:runner, "app"))
146
+ try_sudo(*args)
147
+ end
148
+
149
+ # check if remote file exist
150
+ # inspired by http://stackoverflow.com/questions/1661586/how-can-you-check-to-see-if-a-file-exists-on-the-remote-server-in-capistrano/1662001#1662001
151
+ def remote_file_exists?(full_path)
152
+ 'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
153
+ end
154
+
155
+ # =========================================================================
156
+ # These are the tasks that are available to help with deploying web apps,
157
+ # and specifically, Rails applications. You can have cap give you a summary
158
+ # of them with `cap -T'.
159
+ # =========================================================================
160
+
161
+ namespace :deploy do
162
+ desc <<-DESC
163
+ Deploys your project. Handy wrapper to hook into the beginning of the deployment. Note that \
164
+ this will generally only work for applications that have already been deployed \
165
+ once. For a "cold" deploy, you'll want to take a look at the `deploy:cold' \
166
+ task, which handles the cold start specifically.
167
+ DESC
168
+ task :default do
169
+ update
170
+ end
171
+
172
+ desc <<-DESC
173
+ Prepares one or more servers for deployment. Before you can use any \
174
+ of the Capistrano deployment tasks with your project, you will need to \
175
+ make sure all of your servers have been prepared with `cap deploy:setup'. When \
176
+ you add a new server to your cluster, you can easily run the setup task \
177
+ on just that server by specifying the HOSTS environment variable:
178
+
179
+ $ cap HOSTS=new.server.com deploy:setup
180
+
181
+ It is safe to run this task on servers that have already been set up; it \
182
+ will not destroy any deployed revisions or data.
183
+ DESC
184
+ task :setup, :except => { :no_release => true } do
185
+ dirs = [deploy_to, releases_path, shared_path]
186
+ dirs += shared_children.map { |d| File.join(shared_path, d) }
187
+ run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}"
188
+ end
189
+
190
+ desc <<-DESC
191
+ Copies your project and updates the symlink. It does this in a \
192
+ transaction, so that if either `update_code' or `symlink' fail, all \
193
+ changes made to the remote servers will be rolled back, leaving your \
194
+ system in the same state it was in before `update' was invoked. Usually, \
195
+ you will want to call `deploy' instead of `update', but `update' can be \
196
+ handy if you want to deploy, but not immediately restart your application.
197
+ DESC
198
+ task :update do
199
+ transaction do
200
+ update_code
201
+ symlink
202
+ end
203
+ end
204
+
205
+ desc <<-DESC
206
+ Copies your project to the remote servers. This is the first stage \
207
+ of any deployment; moving your updated code and assets to the deployment \
208
+ servers. You will rarely call this task directly, however; instead, you \
209
+ should call the `deploy' task (to do a complete deploy) or the `update' \
210
+ task (if you want to perform the `restart' task separately).
211
+
212
+ You will need to make sure you set the :scm variable to the source \
213
+ control software you are using (it defaults to :subversion), and the \
214
+ :deploy_via variable to the strategy you want to use to deploy (it \
215
+ defaults to :checkout).
216
+ DESC
217
+ task :update_code, :except => { :no_release => true } do
218
+ on_rollback { run "rm -rf #{release_path}; true" }
219
+ strategy.deploy!
220
+ finalize_update
221
+ end
222
+
223
+ desc <<-DESC
224
+ Install Zend Framework in library path for the deployed application. \
225
+ If multiple versions of ZF exists in the :zf_path and a config file \
226
+ zf.version is found in the application/configs folder, then it try to link \
227
+ the given version. Otherwise the :zf_path is assumed to be the root path of the \
228
+ full Zend Framework release.
229
+ DESC
230
+ task :install_zf, :except => { :no_release => true } do
231
+ version_file = "#{release_path}/application/configs/zf.version"
232
+ # get the zf root as defined in the configuration
233
+ zf_root = "#{zf_path}"
234
+ # append version if zf.version file exists
235
+ zf_root << "/ZendFramework-#{capture("cat #{version_file}").strip}" if remote_file_exists? version_file
236
+ # check correctness of given version of ZF
237
+ run "test -d #{zf_root}/library/Zend -a -d #{zf_root}/extras/library/ZendX"
238
+ # link Zend Framework libraries in the library path
239
+ run "ln -s #{zf_root}/library/Zend #{zf_root}/extras/library/ZendX #{release_path}/library"
240
+ end
241
+
242
+ desc <<-DESC
243
+ [internal] Touches up the released code. This is called by update_code \
244
+ after the basic deploy finishes. It assumes a standard ZF project was deployed, \
245
+ so if you are deploying something else, you may want to override this \
246
+ task with your own environment's requirements.
247
+
248
+ This task will make the release group-writable (if the :group_writable \
249
+ variable is set to true, which is the default). It will then set up \
250
+ symlinks to the shared directory for the data and system, directories. \
251
+ Lastly it will install Zend Framework library in the library folder \
252
+ using the install_zf task provided.
253
+ DESC
254
+ task :finalize_update, :except => { :no_release => true } do
255
+ run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
256
+
257
+ # mkdir -p is making sure that the directories are there for some SCM's that don't
258
+ # save empty folders, link the shared data folder
259
+ run <<-CMD
260
+ rm -rf #{latest_release}/data &&
261
+ ln -s #{shared_path}/data #{latest_release}/data
262
+ CMD
263
+ # install Zend Framework in library folder
264
+ install_zf
265
+ # link system subdir
266
+ run "rm -rf #{latest_release}/public/system && ln -s #{shared_path}/system #{latest_release}/public/system"
267
+ end
268
+
269
+ desc <<-DESC
270
+ Updates the symlink to the most recently deployed version. Capistrano works \
271
+ by putting each new release of your application in its own directory. When \
272
+ you deploy a new version, this task's job is to update the `current' symlink \
273
+ to point at the new version. You will rarely need to call this task \
274
+ directly; instead, use the `deploy' task (which performs a complete \
275
+ deploy, including `restart') or the 'update' task (which does everything \
276
+ except `restart').
277
+ DESC
278
+ task :symlink, :except => { :no_release => true } do
279
+ on_rollback do
280
+ if previous_release
281
+ run "rm -f #{current_path}; ln -s #{previous_release} #{current_path}; true"
282
+ else
283
+ logger.important "no previous release to rollback to, rollback of symlink skipped"
284
+ end
285
+ end
286
+
287
+ run "rm -f #{current_path} && ln -s #{latest_release} #{current_path}"
288
+ end
289
+
290
+ desc <<-DESC
291
+ Copy files to the currently deployed version. This is useful for updating \
292
+ files piecemeal, such as when you need to quickly deploy only a single \
293
+ file. Some files, such as updated templates, images, or stylesheets, \
294
+ might not require a full deploy, and especially in emergency situations \
295
+ it can be handy to just push the updates to production, quickly.
296
+
297
+ To use this task, specify the files and directories you want to copy as a \
298
+ comma-delimited list in the FILES environment variable. All directories \
299
+ will be processed recursively, with all files being pushed to the \
300
+ deployment servers.
301
+
302
+ $ cap deploy:upload FILES=templates,controller.rb
303
+
304
+ Dir globs are also supported:
305
+
306
+ $ cap deploy:upload FILES='config/apache/*.conf'
307
+ DESC
308
+ task :upload, :except => { :no_release => true } do
309
+ files = (ENV["FILES"] || "").split(",").map { |f| Dir[f.strip] }.flatten
310
+ abort "Please specify at least one file or directory to update (via the FILES environment variable)" if files.empty?
311
+
312
+ files.each { |file| top.upload(file, File.join(current_path, file)) }
313
+ end
314
+
315
+ namespace :rollback do
316
+ desc <<-DESC
317
+ [internal] Points the current symlink at the previous revision.
318
+ This is called by the rollback sequence, and should rarely (if
319
+ ever) need to be called directly.
320
+ DESC
321
+ task :revision, :except => { :no_release => true } do
322
+ if previous_release
323
+ run "rm #{current_path}; ln -s #{previous_release} #{current_path}"
324
+ else
325
+ abort "could not rollback the code because there is no prior release"
326
+ end
327
+ end
328
+
329
+ desc <<-DESC
330
+ [internal] Removes the most recently deployed release.
331
+ This is called by the rollback sequence, and should rarely
332
+ (if ever) need to be called directly.
333
+ DESC
334
+ task :cleanup, :except => { :no_release => true } do
335
+ run "if [ `readlink #{current_path}` != #{current_release} ]; then rm -rf #{current_release}; fi"
336
+ end
337
+
338
+ desc <<-DESC
339
+ Rolls back to the previously deployed version. The `current' symlink will \
340
+ be updated to point at the previously deployed version, and then the \
341
+ current release will be removed from the servers.
342
+ DESC
343
+ task :code, :except => { :no_release => true } do
344
+ revision
345
+ cleanup
346
+ end
347
+
348
+ desc <<-DESC
349
+ Rolls back to a previous version and restarts. This is handy if you ever \
350
+ discover that you've deployed a lemon; `cap rollback' and you're right \
351
+ back where you were, on the previously deployed version.
352
+ DESC
353
+ task :default do
354
+ revision
355
+ cleanup
356
+ end
357
+ end
358
+
359
+ desc <<-DESC
360
+ Clean up old releases. By default, the last 5 releases are kept on each \
361
+ server (though you can change this with the keep_releases variable). All \
362
+ other deployed revisions are removed from the servers. By default, this \
363
+ will use sudo to clean up the old releases, but if sudo is not available \
364
+ for your environment, set the :use_sudo variable to false instead.
365
+ DESC
366
+ task :cleanup, :except => { :no_release => true } do
367
+ count = fetch(:keep_releases, 5).to_i
368
+ if count >= releases.length
369
+ logger.important "no old releases to clean up"
370
+ else
371
+ logger.info "keeping #{count} of #{releases.length} deployed releases"
372
+
373
+ directories = (releases - releases.last(count)).map { |release|
374
+ File.join(releases_path, release) }.join(" ")
375
+
376
+ try_sudo "rm -rf #{directories}"
377
+ end
378
+ end
379
+
380
+ desc <<-DESC
381
+ Test deployment dependencies. Checks things like directory permissions, \
382
+ necessary utilities, and so forth, reporting on the things that appear to \
383
+ be incorrect or missing. This is good for making sure a deploy has a \
384
+ chance of working before you actually run `cap deploy'.
385
+
386
+ You can define your own dependencies, as well, using the `depend' method:
387
+
388
+ depend :remote, :gem, "tzinfo", ">=0.3.3"
389
+ depend :local, :command, "svn"
390
+ depend :remote, :directory, "/u/depot/files"
391
+ DESC
392
+ task :check, :except => { :no_release => true } do
393
+ dependencies = strategy.check!
394
+
395
+ other = fetch(:dependencies, {})
396
+ other.each do |location, types|
397
+ types.each do |type, calls|
398
+ if type == :gem
399
+ dependencies.send(location).command(fetch(:gem_command, "gem")).or("`gem' command could not be found. Try setting :gem_command")
400
+ end
401
+
402
+ calls.each do |args|
403
+ dependencies.send(location).send(type, *args)
404
+ end
405
+ end
406
+ end
407
+
408
+ if dependencies.pass?
409
+ puts "You appear to have all necessary dependencies installed"
410
+ else
411
+ puts "The following dependencies failed. Please check them and try again:"
412
+ dependencies.reject { |d| d.pass? }.each do |d|
413
+ puts "--> #{d.message}"
414
+ end
415
+ abort
416
+ end
417
+ end
418
+
419
+ namespace :pending do
420
+ desc <<-DESC
421
+ Displays the `diff' since your last deploy. This is useful if you want \
422
+ to examine what changes are about to be deployed. Note that this might \
423
+ not be supported on all SCM's.
424
+ DESC
425
+ task :diff, :except => { :no_release => true } do
426
+ system(source.local.diff(current_revision))
427
+ end
428
+
429
+ desc <<-DESC
430
+ Displays the commits since your last deploy. This is good for a summary \
431
+ of the changes that have occurred since the last deploy. Note that this \
432
+ might not be supported on all SCM's.
433
+ DESC
434
+ task :default, :except => { :no_release => true } do
435
+ from = source.next_revision(current_revision)
436
+ system(source.local.log(from))
437
+ end
438
+ end
439
+
440
+ end
441
+
442
+ namespace :web do
443
+ desc <<-DESC
444
+ Present a maintenance page to visitors. Disables your application's web \
445
+ interface by writing a "#{maintenance_basename}.html" file to each web server. The \
446
+ servers must be configured to detect the presence of this file, and if \
447
+ it is present, always display it instead of performing the request.
448
+
449
+ By default, the maintenance page will just say the site is down for \
450
+ "maintenance", and will be back "shortly", but you can customize the \
451
+ page by specifying the REASON and UNTIL environment variables:
452
+
453
+ $ cap deploy:web:disable \\
454
+ REASON="hardware upgrade" \\
455
+ UNTIL="12pm Central Time"
456
+
457
+ Further customization will require that you write your own task.
458
+ DESC
459
+ task :disable, :roles => :web, :except => { :no_release => true } do
460
+ require 'erb'
461
+ on_rollback { run "rm #{shared_path}/system/#{maintenance_basename}.html" }
462
+
463
+ warn <<-EOHTACCESS
464
+
465
+ # Please add something like this to your site's htaccess to redirect users to the maintenance page.
466
+ # More Info: http://www.shiftcommathree.com/articles/make-your-rails-maintenance-page-respond-with-a-503
467
+
468
+ ErrorDocument 503 /system/#{maintenance_basename}.html
469
+ RewriteEngine On
470
+ RewriteCond %{REQUEST_URI} !\.(css|gif|jpg|png)$
471
+ RewriteCond %{DOCUMENT_ROOT}/system/#{maintenance_basename}.html -f
472
+ RewriteCond %{SCRIPT_FILENAME} !#{maintenance_basename}.html
473
+ RewriteRule ^.*$ - [redirect=503,last]
474
+ EOHTACCESS
475
+
476
+ reason = ENV['REASON']
477
+ deadline = ENV['UNTIL']
478
+
479
+ # get maintainance template from capistrano gem
480
+ cap_path = Gem.searcher.find("capistrano").full_gem_path
481
+ template = File.read(File.join(cap_path, "lib", "capistrano", "recipes", "templates", "maintenance.rhtml"))
482
+ result = ERB.new(template).result(binding)
483
+
484
+ put result, "#{shared_path}/system/#{maintenance_basename}.html", :mode => 0644
485
+ end
486
+
487
+ desc <<-DESC
488
+ Makes the application web-accessible again. Removes the \
489
+ "#{maintenance_basename}.html" page generated by deploy:web:disable, which (if your \
490
+ web servers are configured correctly) will make your application \
491
+ web-accessible again.
492
+ DESC
493
+ task :enable, :roles => :web, :except => { :no_release => true } do
494
+ run "rm #{shared_path}/system/#{maintenance_basename}.html"
495
+ end
496
+ end
497
+
498
+ end # Capistrano::Configuration.instance(:must_exist).load do
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{zend-framework-deploy}
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 = ["Fabio Napoleoni"]
12
+ s.date = %q{2011-05-03}
13
+ s.default_executable = %q{zf-capify}
14
+ s.description = %q{Use this gem to deploy Zend Framework projects with Capistrano. It will adapt Capistrano configuration in order to be used with ZF project structure.}
15
+ s.email = %q{f.napoleoni@gmail.com}
16
+ s.executables = ["zf-capify"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.markdown"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ "Gemfile",
24
+ "LICENSE.txt",
25
+ "README.markdown",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/zf-capify",
29
+ "lib/zend-framework-deploy.rb",
30
+ "zend-framework-deploy.gemspec"
31
+ ]
32
+ s.homepage = %q{http://github.com/fabn/zend-framework-deploy}
33
+ s.licenses = ["MIT"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.7}
36
+ s.summary = %q{Deploy Zend Framework applications with Capistrano}
37
+
38
+ if s.respond_to? :specification_version then
39
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_runtime_dependency(%q<capistrano>, ["~> 2.5"])
44
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
45
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
46
+ else
47
+ s.add_dependency(%q<capistrano>, ["~> 2.5"])
48
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<capistrano>, ["~> 2.5"])
53
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
55
+ end
56
+ end
57
+
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zend-framework-deploy
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Fabio Napoleoni
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-03 00:00:00 +02:00
19
+ default_executable: zf-capify
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ prerelease: false
24
+ name: capistrano
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 9
31
+ segments:
32
+ - 2
33
+ - 5
34
+ version: "2.5"
35
+ requirement: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ type: :development
38
+ prerelease: false
39
+ name: bundler
40
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 23
46
+ segments:
47
+ - 1
48
+ - 0
49
+ - 0
50
+ version: 1.0.0
51
+ requirement: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ type: :development
54
+ prerelease: false
55
+ name: jeweler
56
+ version_requirements: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 15
62
+ segments:
63
+ - 1
64
+ - 6
65
+ - 0
66
+ version: 1.6.0
67
+ requirement: *id003
68
+ description: Use this gem to deploy Zend Framework projects with Capistrano. It will adapt Capistrano configuration in order to be used with ZF project structure.
69
+ email: f.napoleoni@gmail.com
70
+ executables:
71
+ - zf-capify
72
+ extensions: []
73
+
74
+ extra_rdoc_files:
75
+ - LICENSE.txt
76
+ - README.markdown
77
+ files:
78
+ - .document
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.markdown
82
+ - Rakefile
83
+ - VERSION
84
+ - bin/zf-capify
85
+ - lib/zend-framework-deploy.rb
86
+ - zend-framework-deploy.gemspec
87
+ has_rdoc: true
88
+ homepage: http://github.com/fabn/zend-framework-deploy
89
+ licenses:
90
+ - MIT
91
+ post_install_message:
92
+ rdoc_options: []
93
+
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: 3
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ requirements: []
115
+
116
+ rubyforge_project:
117
+ rubygems_version: 1.3.7
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Deploy Zend Framework applications with Capistrano
121
+ test_files: []
122
+