capistrano-ash 1.3.4 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjUwNmQyZTMxMTNiYjMwMjU3NmEwNDRjODkyOTMyYWY0ZDBkMDQxZA==
4
+ N2Q3MzdiNTQ0ZTAyOWIzMzJiNzUyODE4NTU1NDhkNDllNmFjNTRkOQ==
5
5
  data.tar.gz: !binary |-
6
- YzlmNGZkZjk0NjJkMDAyNDYxYmZhMDE2MzVhYjY3YTA2NGRiYzAwZg==
6
+ MWEyMmFmOWVmM2ZlODcyYzQ5YTJlZTA4ZTFjODhkYTA4NDBmODliNQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YThjYzdhMDg5ODQxYWI2YzNlMjdiOTQ0YzgzZWMwMmMyMWM5NjU2OGY3MWI1
10
- MmU4Y2M0MDBiNmQ1ZTIzMDNmYTMwZjFhODI0MjdhOTc5MWVlZjBmMzFiZmU5
11
- Y2FhOTZlMzgwYzM4ZDM3YzI0YWNlYjFmODk1OGIwNzJjYjI5YjY=
9
+ OGE4ZjljMDdkMTAzZjk4YzQ1NWY3YTk0MzhlOTM3NGRiMDJhYmExZTc4YTQx
10
+ ZTMwYzQzODY2NTE4NzNmNzQ2NWUxNmUyOTQ1NTM5MzI4MTc3YmQ4YjIzZmM0
11
+ MmY2ZDQ2OWZkYzZhOGY3YjA5YjcxOTQ2MGEzNWZjYTVhNmM2NzE=
12
12
  data.tar.gz: !binary |-
13
- NTc0NzQ0NTMyMjQwYmM5ZjMxNWFmYWZlNTlkOTIyZThlMWVlZjRkM2U0ZDk4
14
- YWY4ZjhhODIyZTQ2ZDY5ZmI2NjNhYWZhMDNhZTAxMTVhMjBiYzkzNTAwMzc2
15
- MjMwNjdjZmU5MTM5OWIzMzZkMWQzNTBiOTA5M2VmMWYyYWYzYjI=
13
+ ODBiOTRiNjUyY2FlMTlhNzA3YzBkMzJlNzM5MzZkMzk3NTJmODE5YWYzOTY4
14
+ OWI5ZjA3MDU5Yzc4MDVkMzA4MTE4MTAwODAyMGIzYWNmNmU2NzdkZWMxMmQ2
15
+ ZjA1NTFhODM1NDUzOTllYzE0NTBmODY0MDNiNjJiMjI5NDlmZjU=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.4
1
+ 1.3.5
@@ -25,6 +25,7 @@ configuration.load do
25
25
  after "deploy:setup_shared", "deploy:setup_backup"
26
26
  after "deploy:finalize_update", "ash:htaccess"
27
27
  after "deploy", "deploy:cleanup"
28
+ after "deploy", "seo:robots"
28
29
 
29
30
  # --------------------------------------------
30
31
  # Default variables
@@ -38,7 +39,7 @@ configuration.load do
38
39
  set :dbpass, proc{Capistrano::CLI.password_prompt("Database password for '#{dbuser}':")}
39
40
  set :dbname, proc{text_prompt("Database name: ")}
40
41
  _cset :mysqldump, "mysqldump"
41
- _cset :dump_options, "--single-transaction --create-options --quick"
42
+ _cset :dump_options, "--single-transaction --create-options --quick --triggers --routines"
42
43
 
43
44
  # Source Control
44
45
  set :group_writable, false
@@ -53,7 +54,7 @@ configuration.load do
53
54
  set :copy_strategy, :checkout
54
55
  set :copy_compression, :bz2
55
56
  set :copy_exclude, [".svn", ".git*", ".DS_Store", "*.sample", "LICENSE*", "Capfile",
56
- "RELEASE*", "*.rb", "*.sql", "nbproject", "_template"]
57
+ "RELEASE*", "config/deploy", "*.rb", "*.sql", "nbproject", "_template"]
57
58
 
58
59
  # phpMyAdmin version
59
60
  set :pma_version, "3.4.5"
@@ -137,29 +138,44 @@ configuration.load do
137
138
  will use sudo to clean up the old releases, but if sudo is not available \
138
139
  for your environment, set the :use_sudo variable to false instead. \
139
140
 
140
- Overridden to set/reset file and directory permissions
141
+ OVERRIDES:
142
+ + set/reset file and directory permissions
143
+ + remove old releases per host instead of assuming the releases are \
144
+ the same for every host
145
+
146
+ see http://blog.perplexedlabs.com/2010/09/08/improved-deploycleanup-for-capistrano/
141
147
  DESC
142
148
  task :cleanup, :except => { :no_release => true } do
143
149
  count = fetch(:keep_releases, 5).to_i
144
- local_releases = capture("ls -xt #{releases_path}").split.reverse
145
- if count >= local_releases.length
146
- logger.important "no old releases to clean up"
147
- else
148
- logger.info "keeping #{count} of #{local_releases.length} deployed releases"
149
- directories = (local_releases - local_releases.last(count)).map { |release|
150
- File.join(releases_path, release) }.join(" ")
151
-
152
- directories.split(" ").each do |dir|
153
- # adding a chown -R method to fix permissions on the directory
154
- # this should help with issues related to permission denied
155
- # as in issues #28 and #30
156
- try_sudo "chown -R #{user}:#{user} #{dir}"
157
-
158
- set_perms_dirs(dir)
159
- set_perms_files(dir)
160
- end
150
+ cmd = "ls -xt #{releases_path}"
151
+ run cmd do |channel, stream, data|
152
+ local_releases = data.split.reverse
153
+ if count >= local_releases.length
154
+ logger.important "no old releases to clean up on #{channel[:server]}"
155
+ else
156
+ logger.info "keeping #{count} of #{local_releases.length} deployed releases on #{channel[:server]}"
157
+
158
+ directories = (local_releases - local_releases.last(count)).map { |release|
159
+ File.join(releases_path, release)
160
+ }.join(" ")
161
+
162
+ directories.split(" ").each do |dir|
163
+ begin
164
+ # adding a chown -R method to fix permissions on the directory
165
+ # this should help with issues related to permission denied
166
+ # as in issues #28 and #30
167
+ run "#{sudo} chown -R #{user}:#{user} #{dir}" if remote_dir_exists?(dir)
168
+
169
+ set_perms_dirs(dir)
170
+ set_perms_files(dir)
171
+ rescue Exception => e
172
+ logger.important e.message
173
+ logger.info "Moving on to the next directory..."
174
+ end
175
+ end
161
176
 
162
- try_sudo "rm -rf #{directories}"
177
+ run "#{sudo} rm -rf #{directories}", :hosts => [channel[:server]]
178
+ end
163
179
  end
164
180
  end
165
181
  end
@@ -200,6 +216,39 @@ configuration.load do
200
216
  end
201
217
  end
202
218
 
219
+ # --------------------------------------------
220
+ # SEO - robots.txt files
221
+ # --------------------------------------------
222
+ namespace :seo do
223
+ desc <<-DESC
224
+ Creates a robots.txt appropriate for the environment
225
+
226
+ staging => block all robots from indexing the site
227
+ production => allow robots to index the site
228
+ DESC
229
+ task :robots, :roles => :web do
230
+ case "#{stage}"
231
+ when 'staging'
232
+ # block all robots from indexing anything
233
+ robots_txt = <<-EOF
234
+ User-agent: *
235
+ Disallow: /
236
+ EOF
237
+ when 'production'
238
+ # allow all robots to index anything
239
+ robots_txt = <<-EOF
240
+ User-agent: *
241
+ Disallow:
242
+ EOF
243
+ else
244
+ logger.important "SKIPPING creation of robots.txt because the #{stage} stage was unanticipated. You should override the `seo:robots` task with your own implementation."
245
+ end
246
+
247
+ # echo the file out into the root of the latest_release directory
248
+ put robots_txt, "#{latest_release}/robots.txt"
249
+ end
250
+ end
251
+
203
252
  # --------------------------------------------
204
253
  # PHP tasks
205
254
  # --------------------------------------------
@@ -217,6 +266,24 @@ configuration.load do
217
266
  end
218
267
  end
219
268
 
269
+ # --------------------------------------------
270
+ # NGINX tasks
271
+ # --------------------------------------------
272
+ namespace :nginx do
273
+ %w(start stop restart status).each do |cmd|
274
+ desc "[internal] - #{cmd.upcase} nginx and php-fpm"
275
+ task cmd.to_sym, :roles => :web do
276
+
277
+ nginx_cmd = fetch(:nginx_init_command, "/etc/init.d/nginx")
278
+ phpfpm_cmd = fetch(:phpfpm_init_command, "/etc/init.d/php-fpm")
279
+
280
+ run "#{sudo} #{nginx_cmd} #{cmd}"
281
+ run "#{sudo} #{phpfpm_cmd} #{cmd}"
282
+ end
283
+ end
284
+ end
285
+
286
+
220
287
  # --------------------------------------------
221
288
  # Remote/Local database migration tasks
222
289
  # --------------------------------------------
@@ -348,7 +415,7 @@ configuration.load do
348
415
  You can specify which files or directories to exclude from being \
349
416
  backed up (i.e., log files, sessions, cache) by setting the \
350
417
  :backup_exclude variable
351
- set(:backup_exclude) { [ "var/", "tmp/", logs/debug.log ] }
418
+ set(:backup_exclude) { [ "var/", "tmp/", "logs/debug.log" ] }
352
419
  DESC
353
420
  task :web, :roles => :web do
354
421
  if previous_release
@@ -369,17 +436,22 @@ configuration.load do
369
436
  # --------------------------
370
437
  # SET/RESET PERMISSIONS
371
438
  # --------------------------
372
- set_perms_dirs("#{tmp_backups_path}/#{release_name}", 755)
373
- set_perms_files("#{tmp_backups_path}/#{release_name}", 644)
439
+ begin
440
+ set_perms_dirs("#{tmp_backups_path}/#{release_name}", 755)
441
+ set_perms_files("#{tmp_backups_path}/#{release_name}", 644)
374
442
 
375
- # create the tarball of the previous release
376
- set :archive_name, "release_B4_#{release_name}.tar.gz"
377
- logger.debug "Creating a Tarball of the previous release in #{backups_path}/#{archive_name}"
378
- run "cd #{tmp_backups_path} && tar -cvpf - ./#{release_name}/ | gzip -c --best > #{backups_path}/#{archive_name}"
443
+ # create the tarball of the previous release
444
+ set :archive_name, "release_B4_#{release_name}.tar.gz"
445
+ logger.debug "Creating a Tarball of the previous release in #{backups_path}/#{archive_name}"
446
+ run "cd #{tmp_backups_path} && tar -cvpf - ./#{release_name}/ | gzip -c --best > #{backups_path}/#{archive_name}"
379
447
 
380
- # remove the the temporary copy
381
- logger.debug "Removing the tempory copy"
382
- run "rm -rf #{tmp_backups_path}/#{release_name}"
448
+ # remove the the temporary copy
449
+ logger.debug "Removing the temporary copy"
450
+ run "rm -rf #{tmp_backups_path}/#{release_name}"
451
+ rescue Exception => e
452
+ logger.debug e.message
453
+ logger.info "Error setting permissions on backed up files but continuing on..."
454
+ end
383
455
  else
384
456
  logger.important "no previous release to backup; backup of files skipped"
385
457
  end
@@ -392,8 +464,13 @@ configuration.load do
392
464
  dump_options = fetch(:dump_options, "--single-transaction --create-options --quick")
393
465
 
394
466
  puts "Backing up the database now and putting dump file in the previous release directory"
467
+
468
+ # create the temporary copy for the release directory
469
+ # which we'll tarball in the backup:web task
470
+ run "mkdir -p #{tmp_backups_path}/#{release_name}"
471
+
395
472
  # define the filename (include the current_path so the dump file will be within the directory)
396
- filename = "#{current_path}/#{dbname}_dump-#{Time.now.to_s.gsub(/ /, "_")}.sql.gz"
473
+ filename = "#{tmp_backups_path}/#{release_name}/#{dbname}_dump-#{Time.now.to_s.gsub(/ /, "_")}.sql.gz"
397
474
  # dump the database for the proper environment
398
475
  run "#{mysqldump} #{dump_options} -u #{dbuser} -p #{dbname} | gzip -c --best > #{filename}" do |ch, stream, out|
399
476
  ch.send_data "#{dbpass}\n" if out =~ /^Enter password:/
@@ -423,11 +500,11 @@ configuration.load do
423
500
 
424
501
  # fix permissions on the the files and directories before removing them
425
502
  archives.split(" ").each do |backup|
426
- set_perms_dirs("#{backup}", 755) if File.directory?(backup)
427
- set_perms_files("#{backup}", 644)
503
+ set_perms_dirs("#{backup}", 755) if remote_dir_exists?(backup)
504
+ set_perms_files("#{backup}", 644) if remote_dir_exists?(backup)
428
505
  end
429
506
 
430
- try_sudo "rm -rf #{archives}"
507
+ run "rm -rf #{archives}"
431
508
  rescue Exception => e
432
509
  logger.important e.message
433
510
  end
@@ -544,6 +621,51 @@ configuration.load do
544
621
  end
545
622
  end
546
623
 
624
+ # --------------------------------------------
625
+ # Track changes made to remote release file directory via a throw away git repo
626
+ # --------------------------------------------
627
+ namespace :watchdog do
628
+ desc "Track changes made to remote release file directory via a throw away git repo"
629
+ task :default, :roles => :web do
630
+ watchdog.init_git_repo
631
+ watchdog.init_git_ignore
632
+ watchdog.commit
633
+ watchdog.check_status
634
+ end
635
+
636
+ desc <<-DESC
637
+ [internal] initialize a git repo in the latest release directory to track changes anybody makes to the filesystem
638
+ DESC
639
+ task :init_git_repo, :roles => :web do
640
+ logger.important "Creating a local git repo in #{latest_release} to track changes done outside of our git-flow process"
641
+ run "cd #{latest_release} && git init ." unless remote_dir_exists?("#{latest_release}/.git")
642
+ end
643
+
644
+ desc <<-DESC
645
+ [internal] copy the .gitignore file from the cached-copy directory to only commit what we really care about
646
+ DESC
647
+ task :init_git_ignore, :roles => :web do
648
+ logger.important "Copying the .gitignore file from the cached-copy directory"
649
+ run "ln -s #{shared_path}/cached-copy/.gitignore #{latest_release}/.gitignore"
650
+ end
651
+
652
+ desc <<-DESC
653
+ [internal] Adds and commits the files in the latest release directory
654
+ DESC
655
+ task :commit, :roles => :web do
656
+ logger.important "Adding and committing the files in the latest release directory"
657
+ run "cd #{latest_release} && git add . && git commit -m 'Keeping track of changes done outside of AAI git-flow'"
658
+ end
659
+
660
+ desc <<-DESC
661
+ [internal] Adds and commits the files in the latest release directory
662
+ DESC
663
+ task :check_status, :roles => :web do
664
+ logger.important "Checking status of git repo for any changes in watched files/directories"
665
+ run "cd #{latest_release} && git status"
666
+ end
667
+
668
+ end
547
669
 
548
670
  # --------------------------------------------
549
671
  # Remote File/Directory test tasks
@@ -44,10 +44,10 @@ end
44
44
 
45
45
  # set the permissions for files recurisvely from the starting directory (dir_path)
46
46
  def set_perms_files(dir_path, perm = 644)
47
- try_sudo "find #{dir_path} -type f -print0 | xargs -0 chmod #{perm}"
47
+ run "find #{dir_path} -type f -print0 | xargs -0 #{sudo} chmod #{perm}" if remote_dir_exists?(dir_path)
48
48
  end
49
49
 
50
50
  # set the permissions for directories recurisvely from the starting directory (dir_path)
51
51
  def set_perms_dirs(dir_path, perm = 755)
52
- try_sudo "find #{dir_path} -type d -print0 | xargs -0 chmod #{perm}" if File.directory?(dir_path)
52
+ run "find #{dir_path} -type d -print0 | xargs -0 #{sudo} chmod #{perm}" if remote_dir_exists?(dir_path)
53
53
  end
@@ -15,6 +15,7 @@ configuration.load do
15
15
  #
16
16
  # --------------------------------------------
17
17
  depend :remote, :command, 'drush'
18
+ depend :remote, :command, 'rsync'
18
19
 
19
20
  # --------------------------------------------
20
21
  # Setting defaults
@@ -57,7 +58,7 @@ configuration.load do
57
58
  desc "Setup local files necessary for deployment"
58
59
  task :setup_local do
59
60
  # attempt to create files needed for proper deployment
60
- system("cp .htaccess htaccess.dist")
61
+ system("cp .htaccess htaccess.dist") unless local_file_exists?("htaccess.dist")
61
62
  end
62
63
 
63
64
  desc "Setup shared application directories and permissions after initial setup"
@@ -130,9 +131,14 @@ configuration.load do
130
131
  task :db, :roles => :db do
131
132
  if previous_release
132
133
  puts "Backing up the database now and putting dump file in the previous release directory"
134
+
135
+ # create the temporary copy for the release directory
136
+ # which we'll tarball in the backup:web task
137
+ run "mkdir -p #{tmp_backups_path}/#{release_name}"
138
+
133
139
  multisites.each_pair do |folder, url|
134
140
  # define the filename (include the current_path so the dump file will be within the directory)
135
- filename = "#{current_path}/#{folder}_dump-#{Time.now.to_s.gsub(/ /, "_")}.sql.gz"
141
+ filename = "#{tmp_backups_path}/#{release_name}/#{folder}_dump-#{Time.now.to_s.gsub(/ /, "_")}.sql.gz"
136
142
  # dump the database for the proper environment
137
143
  run "#{drush_bin} -l #{url} -r #{current_path} sql-dump | gzip -c --best > #{filename}"
138
144
  end
@@ -8,11 +8,26 @@ configuration = Capistrano::Configuration.respond_to?(:instance) ?
8
8
  Capistrano.configuration(:must_exist)
9
9
 
10
10
  configuration.load do
11
+
12
+ # --------------------------------------------
13
+ # Deployment dependencies
14
+ #
15
+ # $ cap <stage> deploy:check
16
+ #
17
+ # --------------------------------------------
18
+ depend :remote, :command, 'rsync'
19
+
20
+ # --------------------------------------------
21
+ # Magento Variables
22
+ # --------------------------------------------
23
+ set :enable_modules, []
24
+ set :disable_modules, %w(Ash_Bar)
25
+
11
26
  # --------------------------------------------
12
27
  # Task chains
13
28
  # --------------------------------------------
14
29
  after "deploy:setup", "deploy:setup_local"
15
- # after "deploy:setup_shared", "pma:install"
30
+ # after "deploy:setup_shared", "pma:install"
16
31
  after "deploy:finalize_update", "magento:activate_config"
17
32
  # after "deploy:create_symlink", "magento:symlink"
18
33
 
@@ -20,6 +35,8 @@ configuration.load do
20
35
  # before/after callbacks not firing for 'deploy:symlink'
21
36
  # or 'deploy:create_symlink'
22
37
  after "deploy", "magento:symlink"
38
+ after "magento:symlink", "magento:enable_mods"
39
+ after "magento:enable_mods", "magento:disable_mods"
23
40
  after "magento:symlink", "magento:purge_cache"
24
41
  before "magento:purge_cache", "compass"
25
42
 
@@ -30,9 +47,11 @@ configuration.load do
30
47
  desc "Setup local files necessary for deployment"
31
48
  task :setup_local do
32
49
  # attempt to create files needed for proper deployment
33
- system("cp .htaccess htaccess.dist")
34
- system("cp app/etc/local.xml app/etc/local.xml.staging")
35
- system("cp app/etc/local.xml app/etc/local.xml.production")
50
+ system("cp .htaccess htaccess.dist") unless local_file_exists?("htaccess.dist")
51
+ stages = fetch(:stages, %w(staging production))
52
+ stages.each do |env|
53
+ system("cp app/etc/local.xml app/etc/local.xml.#{env}") unless local_file_exists?("app/etc/local.xml.#{env}")
54
+ end
36
55
  end
37
56
 
38
57
  desc "Setup shared application directories and permissions after initial setup"
@@ -55,8 +74,8 @@ configuration.load do
55
74
  desc "[internal] Touches up the released code. This is called by update_code after the basic deploy finishes."
56
75
  task :finalize_update, :roles => :web, :except => { :no_release => true } do
57
76
  # synchronize media directory with shared data
58
- try_sudo "rsync -rltDvzog #{latest_release}/media/ #{shared_path}/media/"
59
- try_sudo "chmod -R 777 #{shared_path}/media/"
77
+ run "rsync -rltDvzog #{latest_release}/media/ #{shared_path}/media/"
78
+ run "#{sudo} chmod -R 777 #{shared_path}/media/"
60
79
 
61
80
  # remove directories that will be shared
62
81
  run "rm -Rf #{latest_release}/includes"
@@ -108,7 +127,7 @@ configuration.load do
108
127
 
109
128
  desc "Purge Magento cache directory"
110
129
  task :purge_cache, :roles => :web, :except => { :no_release => true } do
111
- try_sudo "rm -Rf #{shared_path}/var/cache/*"
130
+ run "#{sudo} rm -Rf #{shared_path}/var/cache/*"
112
131
  end
113
132
 
114
133
  desc "Watch Magento system log"
@@ -131,8 +150,9 @@ configuration.load do
131
150
 
132
151
  desc "Clear the Magento Cache"
133
152
  task :cc, :roles => [:web, :app], :except => { :no_release => true } do
153
+ run "#{sudo} chown -R #{user}:#{user} #{shared_path}/var/*"
134
154
  magento.purge_cache
135
- try_sudo "rm -rf #{shared_path}/var/full_page_cache/*"
155
+ run "#{sudo} rm -rf #{shared_path}/var/full_page_cache/*"
136
156
  end
137
157
 
138
158
  desc "Enable display errors"
@@ -140,6 +160,30 @@ configuration.load do
140
160
  run "perl -pi -e 's/#ini_set/ini_set/g' #{latest_release}/index.php"
141
161
  end
142
162
 
163
+ desc "Enable Modules"
164
+ task :enable_mods, :roles => :web, :except => { :no_release => true } do
165
+ modules = fetch(:enable_modules, [])
166
+ # enable specific modules
167
+ modules.each do |name|
168
+ mod_name = name.include?('.xml') ? "#{name}" : "#{name}.xml"
169
+ mod_path = "#{latest_release}/app/etc/modules/#{mod_path}"
170
+ # enable the module
171
+ run "perl -pi -e 's/false/true/g' #{mod_path}" if remote_file_exists?("#{mod_path}")
172
+ end
173
+ end
174
+
175
+ desc "Disable Modules"
176
+ task :disable_mods, :roles => :web, :except => { :no_release => true } do
177
+ modules = fetch(:disable_modules, [])
178
+
179
+ # enable specific modules
180
+ modules.each do |name|
181
+ mod_name = name.include?('.xml') ? "#{name}" : "#{name}.xml"
182
+ mod_path = "#{latest_release}/app/etc/modules/#{mod_path}"
183
+ # disable the module
184
+ run "perl -pi -e 's/true/false/g' #{mod_path}" if remote_file_exists?("#{mod_path}")
185
+ end
186
+ end
143
187
  end
144
188
 
145
189
  # --------------------------------------------
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-ash
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 1.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - August Ash
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-09 00:00:00.000000000 Z
11
+ date: 2013-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano