capistrano-didi 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/capistrano-didi.gemspec +2 -2
- data/lib/didi/recipes/didi.rb +90 -56
- metadata +5 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/capistrano-didi.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "capistrano-didi"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Koen Van Winckel"]
|
12
|
-
s.date = "2012-03
|
12
|
+
s.date = "2012-05-03"
|
13
13
|
s.description = "didi is a collection of recipes for capistrano that allow drupal to be deployed, tested and used in a CI environment"
|
14
14
|
s.email = "koenvw@gmail.com"
|
15
15
|
s.executables = ["didify", "didi"]
|
data/lib/didi/recipes/didi.rb
CHANGED
@@ -34,6 +34,9 @@ set :db_host, 'localhost'
|
|
34
34
|
set :drupal_path, 'drupal'
|
35
35
|
set :srv_usr, 'www-data'
|
36
36
|
set :enable_robots, false
|
37
|
+
set :no_disable, true
|
38
|
+
set :local_database, nil
|
39
|
+
set :backup_database, true
|
37
40
|
|
38
41
|
ssh_options[:forward_agent] = true
|
39
42
|
#ssh_options[:verbose] = :debug #FIXME
|
@@ -46,22 +49,20 @@ ssh_options[:forward_agent] = true
|
|
46
49
|
_cset :settings, 'settings.php'
|
47
50
|
_cset :files, 'files'
|
48
51
|
_cset :dbbackups, 'db_backups'
|
49
|
-
_cset :shared_children, [domain, File.join(domain, files)]
|
50
52
|
_cset :drush_path, ''
|
51
53
|
|
52
|
-
_cset(:shared_settings) { File.join(shared_path,
|
53
|
-
_cset(:shared_files) { File.join(shared_path,
|
54
|
-
_cset(:dbbackups_path) { File.join(deploy_to, dbbackups,
|
54
|
+
_cset(:shared_settings) { domain.to_a.map { |d| File.join(shared_path, d, settings) } }
|
55
|
+
_cset(:shared_files) { domain.to_a.map { |d| File.join(shared_path, d, files) } }
|
56
|
+
_cset(:dbbackups_path) { domain.to_a.map { |d| File.join(deploy_to, dbbackups, d) } }
|
55
57
|
_cset(:drush) { "drush -r #{current_path}" + (domain == 'default' ? '' : " -l #{domain}") } # FIXME: not in use?
|
56
58
|
|
59
|
+
_cset(:release_settings) { domain.to_a.map { |d| File.join(release_path, drupal_path, 'sites', d, settings) } }
|
60
|
+
_cset(:release_files) { domain.to_a.map { |d| File.join(release_path, drupal_path, 'sites', d, files) } }
|
61
|
+
_cset(:release_domain) { domain.to_a.map { |d| File.join(release_path, drupal_path, 'sites', d) } }
|
57
62
|
|
58
|
-
_cset(:
|
59
|
-
_cset(:
|
60
|
-
_cset(:
|
61
|
-
|
62
|
-
_cset(:previous_release_settings) { releases.length > 1 ? File.join(previous_release, drupal_path, 'sites', domain, settings) : nil }
|
63
|
-
_cset(:previous_release_files) { releases.length > 1 ? File.join(previous_release, drupal_path, 'sites', domain, files) : nil }
|
64
|
-
_cset(:previous_release_domain) { releases.length > 1 ? File.join(previous_release, drupal_path, 'sites', domain) : nil }
|
63
|
+
_cset(:previous_release_settings) { releases.length > 1 ? domain.to_a.map { |d| File.join(previous_release, drupal_path, 'sites', d, settings) } : nil }
|
64
|
+
_cset(:previous_release_files) { releases.length > 1 ? domain.to_a.map { |d| File.join(previous_release, drupal_path, 'sites', d, files) } : nil }
|
65
|
+
_cset(:previous_release_domain) { releases.length > 1 ? domain.to_a.map { |d| File.join(previous_release, drupal_path, 'sites', d) } : nil }
|
65
66
|
|
66
67
|
# =========================================================================
|
67
68
|
# Extra dependecy checks
|
@@ -111,21 +112,23 @@ namespace :deploy do
|
|
111
112
|
Creates the necessary file structure and the shared Drupal settings file.
|
112
113
|
DESC
|
113
114
|
task :setup, :except => { :no_release => true } do
|
114
|
-
#try to create configuration file before writing directories to server
|
115
|
-
configuration = drupal_settings(drupal_version)
|
116
|
-
|
117
115
|
#Create shared directories
|
118
|
-
# FIXME: chown / chmod require user to be member of
|
116
|
+
# FIXME: chown / chmod require user to be member of
|
119
117
|
dirs = [deploy_to, releases_path, shared_path, dbbackups_path, shared_files]
|
120
|
-
dirs +=
|
118
|
+
dirs += domain.map { |d| File.join(shared_path, d) }
|
119
|
+
|
121
120
|
run <<-CMD
|
122
|
-
mkdir -p #{dirs.join(' ')}
|
123
|
-
#{try_sudo} chown #{user}:#{srv_usr} #{shared_files} &&
|
124
|
-
#{try_sudo} chmod g+w #{shared_files}
|
121
|
+
mkdir -p #{dirs.join(' ')}
|
122
|
+
#{try_sudo} chown #{user}:#{srv_usr} #{shared_files.to_a.join(' ')} &&
|
123
|
+
#{try_sudo} chmod g+w #{shared_files.to_a.join(' ')}
|
125
124
|
CMD
|
126
125
|
|
127
126
|
#create drupal config file
|
128
|
-
|
127
|
+
domain.to_a.each_with_index do |d, i|
|
128
|
+
configuration = drupal_settings(drupal_version, d)
|
129
|
+
put configuration, shared_settings[i]
|
130
|
+
end
|
131
|
+
|
129
132
|
end
|
130
133
|
|
131
134
|
desc "[internal] Rebuild files and settings symlinks"
|
@@ -139,19 +142,27 @@ namespace :deploy do
|
|
139
142
|
end
|
140
143
|
|
141
144
|
|
142
|
-
|
145
|
+
release_domain.each do |rd|
|
146
|
+
run "if [ ! -d #{rd} ]; then mkdir #{rd}; fi" # in case the default is not versioned
|
147
|
+
end
|
143
148
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
149
|
+
shared_files.each_with_index do |sf, i|
|
150
|
+
run <<-CMD
|
151
|
+
ln -nfs #{sf} #{release_files[i]} &&
|
152
|
+
ln -nfs #{shared_settings[i]} #{release_settings[i]}
|
153
|
+
CMD
|
154
|
+
end
|
148
155
|
|
149
156
|
if previous_release
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
157
|
+
# FIXME: executes on initial deploy:cold?
|
158
|
+
# FIXME: this breaks the current site untill deploy:symlink is executed ?
|
159
|
+
previous_release_domain.each_with_index do |prd, i|
|
160
|
+
run "if [ -d #{prd} ]; then chmod 777 #{prd}; fi" # if drupal changed the permissions of the folder
|
161
|
+
run <<-CMD
|
162
|
+
rm -f #{previous_release_settings[i]} &&
|
163
|
+
rm -f #{previous_release_files[i]}
|
164
|
+
CMD
|
165
|
+
end
|
155
166
|
end
|
156
167
|
end
|
157
168
|
|
@@ -236,24 +247,32 @@ namespace :drush do
|
|
236
247
|
|
237
248
|
desc "Clear the Drupal site cache"
|
238
249
|
task :cc do
|
239
|
-
|
250
|
+
domain.each do |d|
|
251
|
+
run "cd #{current_path}/#{drupal_path} && #{drush_path}drush" + (d == 'default' ? '' : " -l #{d}") + " cache-clear all"
|
252
|
+
end
|
240
253
|
end
|
241
254
|
|
242
255
|
desc "Revert all enabled feature modules on your site"
|
243
256
|
task :fra do
|
244
|
-
|
257
|
+
domain.each do |d|
|
258
|
+
run "cd #{current_path}/#{drupal_path} && #{drush_path}drush" + (d == 'default' ? '' : " -l #{d}") + " features-revert-all -y"
|
259
|
+
end
|
245
260
|
end
|
246
261
|
|
247
262
|
desc "Install Drupal along with modules/themes/configuration using the specified install profile"
|
248
263
|
task :si do
|
249
|
-
|
250
|
-
|
264
|
+
domain.each do |d|
|
265
|
+
dburl = "#{db_type}://#{db_username}:#{db_password}@#{db_host}/#{db_name.gsub("%domain", d)}"
|
266
|
+
run "cd #{current_path}/#{drupal_path} && #{drush_path}drush site-install #{profile} --db-url=#{dburl} --sites-subdir=#{d} --account-name=admin --account-pass=#{adminpass} --account-mail=#{sitemail} --site-mail='#{sitemail}' --site-name='#{site.gsub("%domain", d)}' -y"
|
267
|
+
end
|
251
268
|
bl
|
252
269
|
end
|
253
270
|
|
254
271
|
desc "[internal] Enable the baseline feature"
|
255
272
|
task :bl do
|
256
|
-
|
273
|
+
domain.each do |d|
|
274
|
+
run "cd #{current_path}/#{drupal_path} && #{drush_path}drush" + (d == 'default' ? '' : " -l #{d}") + " pm-enable #{baseline.gsub("%domain", d)} -y"
|
275
|
+
end
|
257
276
|
cc
|
258
277
|
end
|
259
278
|
desc "[internal] Enable the simpletest feature"
|
@@ -267,7 +286,9 @@ namespace :drush do
|
|
267
286
|
if drupal_version == 6
|
268
287
|
run "cd #{current_path}/#{drupal_path} && #{drush_path}drush vset --always-set site_offline 0"
|
269
288
|
else
|
270
|
-
|
289
|
+
domain.each do |d|
|
290
|
+
run "cd #{current_path}/#{drupal_path} && #{drush_path}drush" + (d == 'default' ? '' : " -l #{d}") + " vset --always-set maintenance_mode 0"
|
291
|
+
end
|
271
292
|
end
|
272
293
|
end
|
273
294
|
|
@@ -276,22 +297,27 @@ namespace :drush do
|
|
276
297
|
if drupal_version == 6
|
277
298
|
run "cd #{current_path}/#{drupal_path} && #{drush_path}drush vset --always-set site_offline 1"
|
278
299
|
else
|
279
|
-
|
300
|
+
domain.each do |d|
|
301
|
+
run "cd #{current_path}/#{drupal_path} && #{drush_path}drush" + (d == 'default' ? '' : " -l #{d}") + " vset --always-set maintenance_mode 1"
|
302
|
+
end
|
280
303
|
end
|
281
304
|
end
|
282
305
|
|
283
306
|
desc "Apply any database updates required (as with running update.php)"
|
284
307
|
task :updb do
|
285
|
-
|
308
|
+
domain.each do |d|
|
309
|
+
run "cd #{current_path}/#{drupal_path} && #{drush_path}drush" + (d == 'default' ? '' : " -l #{d}") + " updatedb -y"
|
310
|
+
end
|
286
311
|
end
|
287
312
|
|
288
313
|
desc "Update via drush, runs fra, updb and cc"
|
289
314
|
task :update do
|
290
|
-
dissite
|
315
|
+
dissite unless no_disable
|
291
316
|
updb
|
317
|
+
cc # fix for user_permissions constraint?
|
292
318
|
fra
|
293
|
-
|
294
|
-
|
319
|
+
cc # for good measure?
|
320
|
+
ensite unless no_disable
|
295
321
|
manage.block_robots unless enable_robots
|
296
322
|
end
|
297
323
|
|
@@ -365,29 +391,36 @@ end
|
|
365
391
|
|
366
392
|
namespace :manage do
|
367
393
|
|
394
|
+
desc "Block bots via robots.txt"
|
368
395
|
task :block_robots do
|
369
396
|
put "User-agent: *\nDisallow: /", "#{current_path}/#{drupal_path}/robots.txt"
|
370
397
|
end
|
371
398
|
|
372
399
|
task :dbdump_previous do
|
373
400
|
#Backup the previous release's database
|
374
|
-
if previous_release
|
401
|
+
if previous_release && backup_database
|
375
402
|
run "cd #{current_path}/#{drupal_path} && #{drush_path}drush sql-dump > #{ File.join(dbbackups_path, "#{releases[-2]}.sql") }"
|
376
403
|
end
|
377
404
|
end
|
378
405
|
|
379
406
|
desc 'Dump remote database and restore locally'
|
380
407
|
task :pull_dump do
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
408
|
+
if local_database.nil?
|
409
|
+
puts "NO LOCAL DATABASE FOUND, set :local_database in the config file.."
|
410
|
+
else
|
411
|
+
set(:runit, Capistrano::CLI.ui.ask("WARNING!! this will overwrite this local database: '#{local_database}', type 'yes' to continue: "))
|
412
|
+
if runit == 'yes'
|
413
|
+
sql_file = File.join(dbbackups_path, "#{releases.last}-pull.sql")
|
414
|
+
# dump & gzip remote file
|
415
|
+
run "cd #{current_path}/#{drupal_path} && #{drush_path}drush sql-dump > #{sql_file} && gzip -f #{sql_file}"
|
416
|
+
# copy to local
|
417
|
+
system "if [ ! -d build ]; then mkdir build; fi" # create build folder locally if needed
|
418
|
+
download "#{sql_file}.gz", "build/", :once => true, :via => :scp
|
419
|
+
run "rm #{sql_file}.gz"
|
420
|
+
# extract and restore
|
421
|
+
system "gunzip -f build/#{File.basename(sql_file)}.gz && echo \"DROP DATABASE #{local_database};CREATE DATABASE #{local_database}\" | mysql && mysql #{local_database} < build/#{File.basename(sql_file)}" if local_database
|
422
|
+
end
|
423
|
+
end
|
391
424
|
end
|
392
425
|
|
393
426
|
task :push_dump do
|
@@ -401,11 +434,12 @@ end
|
|
401
434
|
# =========================
|
402
435
|
|
403
436
|
# Builds initial contents of the Drupal website's settings file
|
404
|
-
def drupal_settings(version)
|
437
|
+
def drupal_settings(version, domain)
|
438
|
+
db_domain_name = db_name.gsub("%domain", domain)
|
405
439
|
if version.to_s == '6'
|
406
440
|
settings = <<-STRING
|
407
441
|
<?php
|
408
|
-
$db_url = "#{db_type}://#{db_username}:#{db_password}@#{db_host}/#{
|
442
|
+
$db_url = "#{db_type}://#{db_username}:#{db_password}@#{db_host}/#{db_domain_name}";
|
409
443
|
ini_set('arg_separator.output', '&');
|
410
444
|
ini_set('magic_quotes_runtime', 0);
|
411
445
|
ini_set('magic_quotes_sybase', 0);
|
@@ -424,7 +458,7 @@ ini_set('url_rewriter.tags', '');
|
|
424
458
|
settings = <<-STRING
|
425
459
|
<?php
|
426
460
|
$databases = array ('default' => array ('default' => array (
|
427
|
-
'database' => '#{
|
461
|
+
'database' => '#{db_domain_name}',
|
428
462
|
'username' => '#{db_username}',
|
429
463
|
'password' => '#{db_password}',
|
430
464
|
'host' => '#{db_host}',
|
@@ -442,4 +476,4 @@ ini_set('session.cookie_lifetime', 2000000);
|
|
442
476
|
end
|
443
477
|
end
|
444
478
|
|
445
|
-
end # Capistrano::Configuration.instance.load
|
479
|
+
end # Capistrano::Configuration.instance.load
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-didi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Koen Van Winckel
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-03
|
18
|
+
date: 2012-05-03 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
requirement: &id001 !ruby/object:Gem::Requirement
|