capium 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README.md +8 -1
  2. metadata +30 -40
  3. data/lib/capium.rb +0 -491
data/README.md CHANGED
@@ -34,7 +34,7 @@ And make sure you start capium on the last line of that same file:
34
34
 
35
35
  capium
36
36
 
37
- You should then be able to proceed as you would usually, you may want to familiarise yourself with the truncated list of tasks, you can get a full list with:
37
+ You should then be able to proceed as you would usually (`Capify .`), you may want to familiarise yourself with the truncated list of tasks, you can get a full list with:
38
38
 
39
39
  $ cap -T
40
40
 
@@ -56,12 +56,19 @@ If you want to try before you buy, here's the list of tasks included with this v
56
56
  cap deploy:update_code # Copies your project to the remote servers.
57
57
  cap deploy:upload # Copy files to the currently deployed version.
58
58
  cap lithium:setup # Prepares server for deployment of a Lith...
59
+ cap lithium:test_core # Run Lithium core tests
60
+ cap lithium:test_app # Run app tests
59
61
  cap lithium:update # Force Lithium installation to checkout a...
60
62
  cap lithium:clear_cache # Blow up all the cache files Lithium uses...
61
63
  cap lithium:configure_library_path # Sets the path to the class libraries use...
62
64
  cap invoke # Invoke a single command on the remote servers.
63
65
  cap shell # Begin an interactive Capistrano session.
64
66
 
67
+ ## Upcoming tasks
68
+
69
+ + Running tests automatically after a successful deployment
70
+ + Notifications (email)
71
+ + Minimizing JS files and CSS
65
72
 
66
73
  ## Bugs & Feedback
67
74
 
metadata CHANGED
@@ -1,66 +1,56 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: capium
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 2
10
- version: 0.0.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Mehdi Lahmam B.
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-08-14 00:00:00 Z
19
- dependencies: []
20
-
12
+ date: 2011-09-11 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: &70289175625260 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.8.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70289175625260
21
25
  description: Lithium app deployment using Capistrano made easy
22
26
  email: mehdi@lahmam.com
23
27
  executables: []
24
-
25
28
  extensions: []
26
-
27
29
  extra_rdoc_files: []
28
-
29
- files:
30
- - lib/capium.rb
30
+ files:
31
31
  - README.md
32
32
  homepage: http://rubygems.org/gems/capium
33
33
  licenses: []
34
-
35
34
  post_install_message:
36
35
  rdoc_options: []
37
-
38
- require_paths:
36
+ require_paths:
39
37
  - lib
40
- required_ruby_version: !ruby/object:Gem::Requirement
38
+ required_ruby_version: !ruby/object:Gem::Requirement
41
39
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
49
- required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
45
  none: false
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- hash: 3
55
- segments:
56
- - 0
57
- version: "0"
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
58
50
  requirements: []
59
-
60
51
  rubyforge_project:
61
- rubygems_version: 1.8.8
52
+ rubygems_version: 1.8.10
62
53
  signing_key:
63
54
  specification_version: 3
64
55
  summary: Capistrano deploy recipes for Lithium
65
56
  test_files: []
66
-
@@ -1,491 +0,0 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
2
- require 'benchmark'
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
-
20
- # =========================================================================
21
- # These variables may be set in the client capfile if their default values
22
- # are not sufficient.
23
- # =========================================================================
24
-
25
- _cset :scm, :subversion
26
- _cset :deploy_via, :checkout
27
-
28
- _cset(:deploy_to) { "/u/apps/#{application}" }
29
- _cset(:revision) { source.head }
30
-
31
- # Lithium variables
32
- _cset(:lithium_repo) { "git://github.com/UnionOfRAD/lithium.git"}
33
- _cset(:lithium_branch) { "master" }
34
-
35
- # =========================================================================
36
- # These variables should NOT be changed unless you are very confident in
37
- # what you are doing. Make sure you understand all the implications of your
38
- # changes if you do decide to muck with these!
39
- # =========================================================================
40
-
41
- _cset(:source) { Capistrano::Deploy::SCM.new(scm, self) }
42
- _cset(:real_revision) { source.local.query_revision(revision) { |cmd| with_env("LC_ALL", "C") { run_locally(cmd) } } }
43
-
44
- _cset(:strategy) { Capistrano::Deploy::Strategy.new(deploy_via, self) }
45
-
46
- # If overriding release name, please also select an appropriate setting for :releases below.
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
- _cset :shared_children, ['libraries']
52
- _cset :current_dir, "current"
53
-
54
- _cset(:releases_path) { File.join(deploy_to, version_dir) }
55
- _cset(:shared_path) { File.join(deploy_to, shared_dir) }
56
- _cset(:current_path) { File.join(deploy_to, current_dir) }
57
- _cset(:release_path) { File.join(releases_path, release_name) }
58
-
59
- _cset(:releases) { capture("ls -x #{releases_path}", :except => { :no_release => true }).split.sort }
60
- _cset(:current_release) { releases.length > 0 ? File.join(releases_path, releases.last) : nil }
61
- _cset(:previous_release) { releases.length > 1 ? File.join(releases_path, releases[-2]) : nil }
62
-
63
- _cset(:current_revision) { capture("cat #{current_path}/REVISION", :except => { :no_release => true }).chomp }
64
- _cset(:latest_revision) { capture("cat #{current_release}/REVISION", :except => { :no_release => true }).chomp }
65
- _cset(:previous_revision) { capture("cat #{previous_release}/REVISION", :except => { :no_release => true }).chomp if previous_release }
66
-
67
- _cset(:run_method) { fetch(:use_sudo, true) ? :sudo : :run }
68
-
69
- # some tasks, like symlink, need to always point at the latest release, but
70
- # they can also (occassionally) be called standalone. In the standalone case,
71
- # the timestamped release_path will be inaccurate, since the directory won't
72
- # actually exist. This variable lets tasks like symlink work either in the
73
- # standalone case, or during deployment.
74
- _cset(:latest_release) { exists?(:deploy_timestamped) ? release_path : current_release }
75
-
76
- # =========================================================================
77
- # These are helper methods that will be available to your recipes.
78
- # =========================================================================
79
-
80
- # Auxiliary helper method for the `deploy:check' task. Lets you set up your
81
- # own dependencies.
82
- def depend(location, type, *args)
83
- deps = fetch(:dependencies, {})
84
- deps[location] ||= {}
85
- deps[location][type] ||= []
86
- deps[location][type] << args
87
- set :dependencies, deps
88
- end
89
-
90
- # Temporarily sets an environment variable, yields to a block, and restores
91
- # the value when it is done.
92
- def with_env(name, value)
93
- saved, ENV[name] = ENV[name], value
94
- yield
95
- ensure
96
- ENV[name] = saved
97
- end
98
-
99
- # logs the command then executes it locally.
100
- # returns the command output as a string
101
- def run_locally(cmd)
102
- logger.trace "executing locally: #{cmd.inspect}" if logger
103
- output_on_stdout = nil
104
- elapsed = Benchmark.realtime do
105
- output_on_stdout = `#{cmd}`
106
- end
107
- if $?.to_i > 0 # $? is command exit code (posix style)
108
- raise Capistrano::LocalArgumentError, "Command #{cmd} returned status code #{$?}"
109
- end
110
- logger.trace "command finished in #{(elapsed * 1000).round}ms" if logger
111
- output_on_stdout
112
- end
113
-
114
- # If a command is given, this will try to execute the given command, as
115
- # described below. Otherwise, it will return a string for use in embedding in
116
- # another command, for executing that command as described below.
117
- #
118
- # If :run_method is :sudo (or :use_sudo is true), this executes the given command
119
- # via +sudo+. Otherwise is uses +run+. If :as is given as a key, it will be
120
- # passed as the user to sudo as, if using sudo. If the :as key is not given,
121
- # it will default to whatever the value of the :admin_runner variable is,
122
- # which (by default) is unset.
123
- #
124
- # THUS, if you want to try to run something via sudo, and what to use the
125
- # root user, you'd just to try_sudo('something'). If you wanted to try_sudo as
126
- # someone else, you'd just do try_sudo('something', :as => "bob"). If you
127
- # always wanted sudo to run as a particular user, you could do
128
- # set(:admin_runner, "bob").
129
- def try_sudo(*args)
130
- options = args.last.is_a?(Hash) ? args.pop : {}
131
- command = args.shift
132
- raise ArgumentError, "too many arguments" if args.any?
133
-
134
- as = options.fetch(:as, fetch(:admin_runner, nil))
135
- via = fetch(:run_method, :sudo)
136
- if command
137
- invoke_command(command, :via => via, :as => as)
138
- elsif via == :sudo
139
- sudo(:as => as)
140
- else
141
- ""
142
- end
143
- end
144
-
145
- # Same as sudo, but tries sudo with :as set to the value of the :runner
146
- # variable (which defaults to "app").
147
- def try_runner(*args)
148
- options = args.last.is_a?(Hash) ? args.pop : {}
149
- args << options.merge(:as => fetch(:runner, "app"))
150
- try_sudo(*args)
151
- end
152
-
153
-
154
- def capium()
155
- set :deploy_to, "/var/www/#{application}" if (deploy_to.empty?)
156
- after("deploy:setup", "lithium:setup")
157
- after("deploy:symlink", "lithium:configure_library_path", "lithium:clear_cache")
158
- end
159
-
160
- # =========================================================================
161
- # These are the tasks that are available to help with deploying web apps,
162
- # and specifically, Rails applications. You can have cap give you a summary
163
- # of them with `cap -T'.
164
- # =========================================================================
165
-
166
- namespace :deploy do
167
- desc <<-DESC
168
- Deploys your project. Handy wrapper to hook into the beginning of the deployment. Note that \
169
- this will generally only work for applications that have already been deployed \
170
- once. For a "cold" deploy, you'll want to take a look at the `deploy:cold' \
171
- task, which handles the cold start specifically.
172
- DESC
173
- task :default do
174
- update
175
- end
176
-
177
- desc <<-DESC
178
- Prepares one or more servers for deployment. Before you can use any \
179
- of the Capistrano deployment tasks with your project, you will need to \
180
- make sure all of your servers have been prepared with `cap deploy:setup'. When \
181
- you add a new server to your cluster, you can easily run the setup task \
182
- on just that server by specifying the HOSTS environment variable:
183
-
184
- $ cap HOSTS=new.server.com deploy:setup
185
-
186
- It is safe to run this task on servers that have already been set up; it \
187
- will not destroy any deployed revisions or data.
188
- DESC
189
- task :setup, :except => { :no_release => true } do
190
- dirs = [deploy_to, releases_path, shared_path]
191
- dirs += shared_children.map { |d| File.join(shared_path, d) }
192
- run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}"
193
- end
194
-
195
- desc <<-DESC
196
- Copies your project and updates the symlink. It does this in a \
197
- transaction, so that if either `update_code' or `symlink' fail, all \
198
- changes made to the remote servers will be rolled back, leaving your \
199
- system in the same state it was in before `update' was invoked. Usually, \
200
- you will want to call `deploy' instead of `update', but `update' can be \
201
- handy if you want to deploy, but not immediately restart your application.
202
- DESC
203
- task :update do
204
- transaction do
205
- update_code
206
- symlink
207
- end
208
- end
209
-
210
- desc <<-DESC
211
- Copies your project to the remote servers. This is the first stage \
212
- of any deployment; moving your updated code and assets to the deployment \
213
- servers. You will rarely call this task directly, however; instead, you \
214
- should call the `deploy' task (to do a complete deploy) or the `update' \
215
- task (if you want to perform the `restart' task separately).
216
-
217
- You will need to make sure you set the :scm variable to the source \
218
- control software you are using (it defaults to :subversion), and the \
219
- :deploy_via variable to the strategy you want to use to deploy (it \
220
- defaults to :checkout).
221
- DESC
222
- task :update_code, :except => { :no_release => true } do
223
- on_rollback { run "rm -rf #{release_path}; true" }
224
- strategy.deploy!
225
- finalize_update
226
- end
227
-
228
- desc <<-DESC
229
- [internal] Touches up the released code. This is called by update_code \
230
- after the basic deploy finishes. It assumes a Rails project was deployed, \
231
- so if you are deploying something else, you may want to override this \
232
- task with your own environment's requirements.
233
-
234
- This task will make the release group-writable (if the :group_writable \
235
- variable is set to true, which is the default). It will then set up \
236
- symlinks to the shared directory for the log, system, and tmp/pids \
237
- directories, and will lastly touch all assets in public/images, \
238
- public/stylesheets, and public/javascripts so that the times are \
239
- consistent (so that asset timestamping works). This touch process \
240
- is only carried out if the :normalize_asset_timestamps variable is \
241
- set to true, which is the default.
242
- DESC
243
- task :finalize_update, :except => { :no_release => true } do
244
- run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
245
- end
246
-
247
- desc <<-DESC
248
- Updates the symlink to the most recently deployed version. Capistrano works \
249
- by putting each new release of your application in its own directory. When \
250
- you deploy a new version, this task's job is to update the `current' symlink \
251
- to point at the new version. You will rarely need to call this task \
252
- directly; instead, use the `deploy' task (which performs a complete \
253
- deploy, including `restart') or the 'update' task (which does everything \
254
- except `restart').
255
- DESC
256
- task :symlink, :except => { :no_release => true } do
257
- on_rollback do
258
- if previous_release
259
- run "rm -f #{current_path}; ln -s #{previous_release} #{current_path}; true"
260
- else
261
- logger.important "no previous release to rollback to, rollback of symlink skipped"
262
- end
263
- end
264
-
265
- run "rm -f #{current_path} && ln -s #{latest_release} #{current_path}"
266
- end
267
-
268
- desc <<-DESC
269
- Copy files to the currently deployed version. This is useful for updating \
270
- files piecemeal, such as when you need to quickly deploy only a single \
271
- file. Some files, such as updated templates, images, or stylesheets, \
272
- might not require a full deploy, and especially in emergency situations \
273
- it can be handy to just push the updates to production, quickly.
274
-
275
- To use this task, specify the files and directories you want to copy as a \
276
- comma-delimited list in the FILES environment variable. All directories \
277
- will be processed recursively, with all files being pushed to the \
278
- deployment servers.
279
-
280
- $ cap deploy:upload FILES=templates,controller.rb
281
-
282
- Dir globs are also supported:
283
-
284
- $ cap deploy:upload FILES='config/apache/*.conf'
285
- DESC
286
- task :upload, :except => { :no_release => true } do
287
- files = (ENV["FILES"] || "").split(",").map { |f| Dir[f.strip] }.flatten
288
- abort "Please specify at least one file or directory to update (via the FILES environment variable)" if files.empty?
289
-
290
- files.each { |file| top.upload(file, File.join(current_path, file)) }
291
- end
292
-
293
- namespace :rollback do
294
- desc <<-DESC
295
- [internal] Points the current symlink at the previous revision.
296
- This is called by the rollback sequence, and should rarely (if
297
- ever) need to be called directly.
298
- DESC
299
- task :revision, :except => { :no_release => true } do
300
- if previous_release
301
- run "rm #{current_path}; ln -s #{previous_release} #{current_path}"
302
- else
303
- abort "could not rollback the code because there is no prior release"
304
- end
305
- end
306
-
307
- desc <<-DESC
308
- [internal] Removes the most recently deployed release.
309
- This is called by the rollback sequence, and should rarely
310
- (if ever) need to be called directly.
311
- DESC
312
- task :cleanup, :except => { :no_release => true } do
313
- run "if [ `readlink #{current_path}` != #{current_release} ]; then rm -rf #{current_release}; fi"
314
- end
315
-
316
- desc <<-DESC
317
- Rolls back to the previously deployed version. The `current' symlink will \
318
- be updated to point at the previously deployed version, and then the \
319
- current release will be removed from the servers.
320
- DESC
321
- task :code, :except => { :no_release => true } do
322
- revision
323
- cleanup
324
- end
325
-
326
- desc <<-DESC
327
- Rolls back to a previous version and restarts. This is handy if you ever \
328
- discover that you've deployed a lemon; `cap rollback' and you're right \
329
- back where you were, on the previously deployed version.
330
- DESC
331
- task :default do
332
- revision
333
- cleanup
334
- end
335
- end
336
-
337
- desc <<-DESC
338
- Clean up old releases. By default, the last 5 releases are kept on each \
339
- server (though you can change this with the keep_releases variable). All \
340
- other deployed revisions are removed from the servers. By default, this \
341
- will use sudo to clean up the old releases, but if sudo is not available \
342
- for your environment, set the :use_sudo variable to false instead.
343
- DESC
344
- task :cleanup, :except => { :no_release => true } do
345
- count = fetch(:keep_releases, 5).to_i
346
- if count >= releases.length
347
- logger.important "no old releases to clean up"
348
- else
349
- logger.info "keeping #{count} of #{releases.length} deployed releases"
350
-
351
- directories = (releases - releases.last(count)).map { |release|
352
- File.join(releases_path, release) }.join(" ")
353
-
354
- try_sudo "rm -rf #{directories}"
355
- end
356
- end
357
-
358
- desc <<-DESC
359
- Test deployment dependencies. Checks things like directory permissions, \
360
- necessary utilities, and so forth, reporting on the things that appear to \
361
- be incorrect or missing. This is good for making sure a deploy has a \
362
- chance of working before you actually run `cap deploy'.
363
-
364
- You can define your own dependencies, as well, using the `depend' method:
365
-
366
- depend :remote, :gem, "tzinfo", ">=0.3.3"
367
- depend :local, :command, "svn"
368
- depend :remote, :directory, "/u/depot/files"
369
- DESC
370
- task :check, :except => { :no_release => true } do
371
- dependencies = strategy.check!
372
-
373
- other = fetch(:dependencies, {})
374
- other.each do |location, types|
375
- types.each do |type, calls|
376
- if type == :gem
377
- dependencies.send(location).command(fetch(:gem_command, "gem")).or("`gem' command could not be found. Try setting :gem_command")
378
- end
379
-
380
- calls.each do |args|
381
- dependencies.send(location).send(type, *args)
382
- end
383
- end
384
- end
385
-
386
- if dependencies.pass?
387
- puts "You appear to have all necessary dependencies installed"
388
- else
389
- puts "The following dependencies failed. Please check them and try again:"
390
- dependencies.reject { |d| d.pass? }.each do |d|
391
- puts "--> #{d.message}"
392
- end
393
- abort
394
- end
395
- end
396
-
397
- desc <<-DESC
398
- Deploys and starts a `cold' application. This is useful if you have not \
399
- deployed your application before, or if your application is (for some \
400
- other reason) not currently running. It will deploy the code, run any \
401
- pending migrations, and then instead of invoking `deploy:restart', it will \
402
- invoke `deploy:start' to fire up the application servers.
403
- DESC
404
- task :cold do
405
- update
406
- end
407
-
408
- namespace :pending do
409
- desc <<-DESC
410
- Displays the `diff' since your last deploy. This is useful if you want \
411
- to examine what changes are about to be deployed. Note that this might \
412
- not be supported on all SCM's.
413
- DESC
414
- task :diff, :except => { :no_release => true } do
415
- system(source.local.diff(current_revision))
416
- end
417
-
418
- desc <<-DESC
419
- Displays the commits since your last deploy. This is good for a summary \
420
- of the changes that have occurred since the last deploy. Note that this \
421
- might not be supported on all SCM's.
422
- DESC
423
- task :default, :except => { :no_release => true } do
424
- from = source.next_revision(current_revision)
425
- system(source.local.log(from))
426
- end
427
- end
428
-
429
- end
430
-
431
- namespace :lithium do
432
-
433
- desc <<-DESC
434
- Prepares server for deployment of a Lithium application. \
435
-
436
- By default, it will create a shallow clone of the Lithium repository \
437
- inside {shared_path}/libraries/lithium and run deploy:lithium:update.
438
-
439
- For more info about shallow clones: \
440
- http://www.kernel.org/pub/software/scm/git/docs/git-clone.html \
441
-
442
- Further customization will require that you write your own task.
443
- DESC
444
- task :setup do
445
- run "cd #{shared_path}/libraries && #{try_sudo} git clone --depth 1 #{lithium_repo} lithium"
446
- set :git_flag_quiet, "-q "
447
- update
448
- end
449
- desc <<-DESC
450
- Force Lithium installation to checkout a new branch/tag. \
451
-
452
- By default, it will checkout the :lithium_branch you set in \
453
- deploy.rb, but you can change that on runtime by specifying \
454
- the BRANCH environment variable:
455
-
456
- $ cap deploy:lithium:update \\
457
- BRANCH="lithium-0.10"
458
-
459
- Further customization will require that you write your own task.
460
- DESC
461
- task :update do
462
- set :lithium_branch, ENV['BRANCH'] if ENV.has_key?('BRANCH')
463
- stream "cd #{shared_path}/libraries/lithium && #{try_sudo} git checkout #{git_flag_quiet}#{lithium_branch}"
464
- end
465
-
466
- desc <<-DESC
467
- Sets the path to the class libraries used by your Lithium application. \
468
- This directory contain a copy of the Lithium core.
469
- DESC
470
- task :configure_library_path do
471
- run "sed -i \"s=^define('LITHIUM_LIBRARY_PATH.*$=define('LITHIUM_LIBRARY_PATH', '#{shared_path}/libraries');=\" #{release_path}/config/bootstrap/libraries.php"
472
- end
473
-
474
- desc <<-DESC
475
- Blow up all the cache files Lithium uses, ensuring a clean restart.
476
- DESC
477
- task :clear_cache do
478
- run "rm -rf #{release_path}/resources/tmp/*"
479
-
480
- run [
481
- "mkdir -p #{release_path}/resources/tmp/cache/templates",
482
- "mkdir -p #{release_path}/resources/tmp/logs",
483
- "mkdir -p #{release_path}/resources/tmp/tests",
484
-
485
- "chmod -R 777 #{release_path}/resources",
486
- ].join(' && ')
487
- end
488
-
489
- end
490
-
491
- end # Capistrano::Configuration.instance(:must_exist).load do